bufferover flow ?
Posted: Mon May 17, 2010 5:34 pm
I am trying to learn how these buffer over flows work
I have this exploit.c example
my code to exploit the exploit.c file
The exploit is given by this function
But if I overflow the buffer[20] this buffer is not on the stack so overflowing it.... I don't know how far to go to get to the return address of the stack. If that is the stratgy ... what happens if buffer[20] was placed before the stack then no amount of overflow would work since buffer[21] ,buffer[22] ,....etc would be farther away from the stack.
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
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