I'm trying to over the following function:
void function(int param){
char overflow[32];
gets(overflow);
}
I'd like to gain control of the integer parameter. This is an x86 platform.
This is what I'm giving as the string to overflow:
python -c "print '\x41'*33 + '\x41'*4 + '\x41'*4 + '\xFF\xFF\xFF\xFF'"
These are my assumptions, please correct them:
- 33 bytes are allocated for the string (32 chars plus the null byte)
- 4 bytes for the address of the last EBP
- 4 bytes for the return address
- 4 bytes for the integer parameter (where I want the \xFF to appear)
However, this isn't working. What am I missing?
Full code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void func(int key){
char overflowme[32];
printf("overflow me : ");
gets(overflowme); // smash me!
if(key == 0xcafebabe){
system("/bin/sh");
}
else{
printf("Nah..\n");
}
}
int main(int argc, char* argv[]){
func(0xdeadbeef);
return 0;
}