I have to exploit a buffer vulnerability in the code below using a string of shell op codes. I have seen almost everything Google has suggested but this particular problem is confusing me because of the function separations.
void printThis(){
if(printf("You did it 1!") >=0) exit(0);
if(printf("You did it 2!") >=0) exit(0);
if(printf("You did it 3!") >=0) exit(0);
}
void readIn(FILE *f){
char exploit[12];
int i;
fscanf(f, "%s", exploit);
for( i = 0; i < 12; i++){
printf("%c", exploit[i]);
}
printf("\"\n");
}
int main(int argc, char** argv){
FILE *fp;
fp = fopen(argv[1], "r");
readIn(fp);
fclose(fp);
printf("You suck at exploiting. I should not be printed.");
}
I am curious as to how to overflow the buffer in readIn()
with the return address of the statement in printThis()
since they are using different stacks. Intuition says a jump to the call on print will work but I haven't been able to get it working.
Any suggestions to get the information I need for the payload in GDB? Thanks for your help!