Writeup
First use this command to scan the executable:
objdump -M intel -d break_this
- The
main()function only callsread_buffer(). - This function reads the length of a buffer from standard input into a variable
n. - Then it reads the buffer itself (
char buffer[64]). - Because
fgets()reads at mostn - 1characters, we can setnto a value bigger than the length of the buffer, so an overflow may be possible. - We will set
nto a large enough value:100 magic_function()starts at address0x080491d6- We see that the buffer passed where
fgets()reads starts atebp - 0x58. - At the address pointed by
ebpwe find the savedebpwhich we must skip, followed by the return address that we need to overwrite. - So we must use
0x58 + 4 = 92dummy charactersAand then the address ofmagic_function()in little-endian encoding.
We can find the address of the magic_function() using this command:
student@hsi:/.../overwrite-ret-addr/support$ nm break_this | grep magic_function
080491d6 T magic_function
python2.7 -c 'print "100\n" + "A" * 92 + "\xd6\x91\x04\x08"' > payload