re每日一题(20200530)(补)

本文详细解析了GKCTF2020逆向挑战赛中的0x03EzMachine题目,介绍了如何使用IDA处理不可F5的main函数,分析虚拟机字节码,以及通过逆向加密算法来实现解密过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

re每日一题(20200530)(补)

GKCTF2020

0x03 EzMachine

载入IDA,main函数不能F5,需要将0x1591的后三个字节nop

在这里插入图片描述

int __cdecl main(int argc, const char **argv, const char **envp)
{
  unsigned int i; // [esp+10h] [ebp-8h]

  sub_6014F0();
  while ( 1 )
  {
LABEL_2:
    for ( i = 0; ; i += 2 )
    {
      if ( i >= 0x58 )
        goto LABEL_2;
      if ( code[4 * i] == byte_6449A0[E_ip] )
        break;
    }
    call[i]();
  }
}

查看code这个数组,可以发现是VM。

分析过后,整理字节码为指令,指令为三个字节长度

0x1 mov reg,const
0x2 push
0x3 mov [mem],reg
0x4 pop
0x5 print
0x6 add
0x7 sub
0x8 mul
0x9 idiv
0xa xor
0xb jmp
0xc cmp
0xd  jz  
0xf  ja
0x10 jb
0x11 gets
0x12 memset 
0x13 mov_reg_esp
0x14 movzx
0xff exit

大致整理后,加密算法为

cipher = []
for i in range(len(input)):
	tmp = ord(input[i])
	sum = 0
	if input[i] <= 'z' and input[i] >= 'a':
		sum = (tmp^0x47)+1
	elif input[i] <= 'Z' and input[i] >= 'A':
		sum = (tmp^0x4b)-1
	cipher.append(sum%0x10)
	cipher.append(sum/0x10)

通过加密算法可以写出解密算法。(由于在VM的栈中,需要反序)

cipher = [0x7,0xd,0x0,0x5,0x1,0xc,0x1,0x0,0x0,0xd,0x5,0xf,0x0,0x9,0x5,0xf,0x3,0x0,0x2,0x5,0x3,0x3,0x1,0x7,0x7,0xb,0x2,0x1,0x2,0x7,0x2,0xc,0x2,0x2]
cipher = cipher[::-1]
flag = ''
for i in range(0,len(cipher),2):
	tmp = cipher[i+1]*0x10+cipher[i]
	ch = chr((tmp-1)^0x47)
	if ch <= 'z' and ch >= 'a':
		flag += ch
		continue
	ch = chr((tmp+1)^0x4b)
	if ch <= 'Z' and ch >= 'A':
		flag += ch
		continue
	flag += chr(tmp)

print flag
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值