I have this exploit.c example
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
*
*/
void bufferoverflow( char * ) ;
void printbufferoverflow() ;
int main(int argc, char** argv) {
bufferoverflow( argv[0]) ;
return (EXIT_SUCCESS);
}
void bufferoverflow( char *str)
{
char buffer[20] ;
strcpy(buffer,str) ;
return ;
}
my code to exploit the exploit.c file
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void printbufferoverflow()
{
printf( "Hello buffer overflow success!" ) ;
return;
}
int main(int argc, char** argv) {
int addressofprintbufferoverflow = &printbufferoverflow;
//now I have to call the exploit.c file passing an arg[0] as a string that will return me to printbufferoverflow
//This is where I am having trouble understanding.
return (EXIT_SUCCESS);
}
The exploit is given by this function
Code: Select all
void bufferoverflow( char *str)
{
char buffer[20] ;
strcpy(buffer,str) ;
return ;
}
Assuming the buffer[20] is above the stack or configured in away such that the greater the [21] ,[22] , ...etc argument to buffer the close to the return address you will get.
Then it is just a matter of &buffer -&esp <-(stack of exploit.c)
The string I am crafting is a ton of NOP's (nop sled) followed by the code to return me to my print function
call printbufferoverflow followed by a ton of back to back return address to print functions just in case
Thanks for any help