楚慧杯ez_vm

虚拟机逆向,感觉用z3模式程序执行然后z3来解比较好理解。这题目有个坑就是下标越界的问题。我动调的时候发现的,opcode中0x32做为下标为0,依此类推。这个坑就在这里。

opcode = [0x8,0x1,0x11,0x8,0x2,0x13,0x7,0x0,0x0,0x1,
0x0,0x1,0x2,0x0,0x2,0x6,0x0,0x0,0x7,0x0,
0x1,0x1,0x0,0x1,0x2,0x0,0x2,0x6,0x1,0x0,
0x7,0x0,0x2,0x1,0x0,0x1,0x2,0x0,0x2,0x6,
0x2,0x0,0x7,0x0,0x3,0x1,0x0,0x1,0x2,0x0,
0x2,0x6,0x3,0x0,0x7,0x0,0x4,0x1,0x0,0x1,
0x2,0x0,0x2,0x6,0x4,0x0,0x7,0x0,0x5,0x1,
0x0,0x1,0x2,0x0,0x2,0x6,0x5,0x0,0x7,0x0,
0x6,0x1,0x0,0x1,0x2,0x0,0x2,0x6,0x6,0x0,
0x7,0x0,0x7,0x1,0x0,0x1,0x2,0x0,0x2,0x6,
0x7,0x0,0x7,0x0,0x8,0x1,0x0,0x1,0x2,0x0,
0x2,0x6,0x8,0x0,0x7,0x0,0x9,0x1,0x0,0x1,
0x2,0x0,0x2,0x6,0x9,0x0,0x7,0x0,0xa,0x1,
0x0,0x1,0x2,0x0,0x2,0x6,0xa,0x0,0x7,0x0,
0xb,0x1,0x0,0x1,0x2,0x0,0x2,0x6,0xb,0x0,
0x7,0x0,0xc,0x1,0x0,0x1,0x2,0x0,0x2,0x6,
0xc,0x0,0x7,0x0,0xd,0x1,0x0,0x1,0x2,0x0,
0x2,0x6,0xd,0x0,0x7,0x0,0xe,0x1,0x0,0x1,
0x2,0x0,0x2,0x6,0xe,0x0,0x7,0x0,0xf,0x1,
0x0,0x1,0x2,0x0,0x2,0x6,0xf,0x0,0x7,0x0,
0x10,0x1,0x0,0x1,0x2,0x0,0x2,0x6,0x10,0x0,
0x7,0x0,0x11,0x1,0x0,0x1,0x2,0x0,0x2,0x6,
0x11,0x0,0x7,0x0,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p = [0]*0x38

def xor_1(a,b):
    temp[a] ^= temp[b]

def add(a,b):
    temp[a] += temp[b]

def sub(a,b):
    temp[a] -= temp[b]

def left(a,b):
    temp[a]<<temp[b]

def right(a,b):
    temp[a] >> temp[b]

def temp1(a,b):
    a1 = temp[b]
    flag[a] = a1

def temp2(a,b):
    result = flag[b]
    temp[a] = result

def copy1(a,b):
    temp[a] = b

for v4 in range(0,len(opcode)-1,3):
    if opcode[v4]==1:

        xor_1(opcode[v4+1],opcode[v4+2])
    elif opcode[v4]==2:
        add(opcode[v4 + 1], opcode[v4 + 2])
    elif opcode[v4]==3:
        sub(opcode[v4 + 1], opcode[v4 + 2])
    elif opcode[v4]==4:
        left(opcode[v4 + 1], opcode[v4 + 2])
    elif opcode[v4]==5:
        right(opcode[v4 + 1], opcode[v4 + 2])
    elif opcode[v4]==6:
        print(opcode[v4 + 1], opcode[v4 + 2])
        temp1(opcode[v4 + 1], opcode[v4 + 2])
    elif opcode[v4]==7:
        temp2(opcode[v4 + 1], opcode[v4 + 2])
    elif opcode[v4]==8:
        copy1(opcode[v4 + 1], opcode[v4 + 2])

enc=[138, 144, 131, 137, 125, 136, 131, 52, 135, 134, 135, 51, 134, 57, 56, 55, 134, 135, 58, 58, 54, 60, 54, 56, 51, 138, 136, 53, 59, 134, 60, 52, 52, 55, 53, 54, 54, 127, 0]
from z3 import *
s = Solver()
for i in range(38):
    s.add(flag[i]==enc[i])

print(s.check())
m = s.model()
inp = [BitVec(f'{i}',64) for i in range(38)]
for i in inp:
    print(chr(m[i].as_long()),end='')

  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值