January 24, 2022

2022 HWS-EasyVM

0x00 日常查壳

无壳32位

image-20220124225745631

0x01 分析主函数

通过shitf+F12找到字符串,交叉引用到这,这边有几个常见的花指令jz jnz这种的

可以参考之前我录的一期:绿城杯-Reverse(逆向)-babyvxworks 浅谈花指令_bilibili

image-20220124225916432

反汇编出来的ida看不出来什么东西,ida动调不起来,老是闪退,于是就去dbg去做这题

image-20220124230350044

去翻函数列表可以发现4012F0是关键区域,在main函数里一步步跟会找到跳到那的位置

image-20220124230656009

0x02 分析4012F0

VM的题就是操作数和操作码,确定了符号执行的函数,慢慢跟就好了

image-20220124231011036

关键就注意这三块数据即可,现在只要搞清楚每个符号执行是干嘛就可以了

image-20220124231715479

一条语句跟着看数据得到分析

于是可以得到一个等式:

当i = 0: flag[i] = eflag[i] ^ 0xEE

当i > 0: flag[i] = eflag[i] ^ eflag[i - 1] ^ 0xEE

image-20220124233015199

0x03 GetFlag!

于是我们恢复一下enflag这串数据,顺便把base64后的几个异或解决

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
#include <stdio.h>

int main(void)
{
unsigned char ef[] =
{
0xBE, 0x36, 0xAC, 0x27, 0x99, 0x4F, 0xDE, 0x44, 0xEE, 0x5F,
0xDA, 0x0B, 0xB5, 0x17, 0xB8, 0x68, 0xC2, 0x4E, 0x9C, 0x4A,
0xE1, 0x43, 0xF0, 0x22, 0x8A, 0x3B, 0x88, 0x5B, 0xE5, 0x54,
0xFF, 0x68, 0xD5, 0x67, 0xD4, 0x06, 0xAD, 0x0B, 0xD8, 0x50,
0xF9, 0x58, 0xE0, 0x6F, 0xC5, 0x4A, 0xFD, 0x2F, 0x84, 0x36,
0x85, 0x52, 0xFB, 0x73, 0xD7, 0x0D
};
int i, j;

for ( i = 55; i >= 1; i-- )
{
ef[i] ^= ef[i - 1] ^ 0xEE ^ (0xA + i % 4);
// printf("0x%X, ", ef[i]);
}
ef[0] ^= 0xEE ^ 0xA;

for ( i = 0; i < 56; i++ )
printf("0x%X, ", ef[i]);

return 0;
}

拿到数据后,base64标准解密即可

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
#include <stdio.h>
#include <string.h>

#define LEN 56

static int i, j;
static char Base64Code[] =
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '+', '/', '='
};

int main(void)
{
unsigned char input[] =
{
0x5A, 0x6D, 0x78, 0x68, 0x5A, 0x33, 0x73, 0x79, 0x4E, 0x54, 0x67, 0x32, 0x5A, 0x47, 0x4D, 0x33, 0x4E, 0x69, 0x30, 0x35, 0x4F, 0x47, 0x51, 0x31, 0x4C, 0x54, 0x51, 0x30, 0x5A, 0x54, 0x49, 0x74, 0x59, 0x57, 0x51, 0x31, 0x4F, 0x43, 0x31, 0x6B, 0x4D, 0x44, 0x5A, 0x6C, 0x4E, 0x6A, 0x55, 0x31, 0x4F, 0x57, 0x51, 0x34, 0x4D, 0x6D, 0x46, 0x39
};
char flag[LEN];

for ( i = 0; i < LEN; i++ )
{
for ( j = 0; j < 64; j++ )
{
if ( input[i] == Base64Code[j] )
{
input[i] = j;
// printf("0x%-2x, ", input[i]);
break;
}
}
}
for (i = 0, j = 0; j < LEN; i += 3, j +=4 )
{
flag[i] = (input[j] << 2) | ((input[j + 1] & 0x30) >> 4);
flag[i + 1] = ((input[j + 1] & 0xF) << 4) | ((input[j + 2] & 0x3C) >> 2);
flag[i + 2] = ((input[j + 2] & 0x3) << 6) | input[j + 3] ;
// printf("%x %x %x ", flag[i], flag[i + 1], flag[i + 2]);
}

for ( i = 0; i < LEN / 4 * 3; i++ )
printf("%c", flag[i]);


/* 标准base64解密 4位变3位*/
// for (i = 0, j = 0; j < strlen(input); i += 3, j +=4 )
// {
// flag[i] = (input[j] << 2) | ((input[j + 1] & 0x30) >> 4);
// flag[i + 1] = ((input[j + 1] & 0xF) << 4) | ((input[j + 2] & 0x3C) >> 2);
// flag[i + 2] = ((input[j + 2] & 0x3) << 6) | input[j + 3] ;
// printf("%x %x %x ", flag[i], flag[i + 1], flag[i + 2]);
// }



/* 标准base64加密 3位变4位*/
// for ( i = 0, j = 0; i <= strlen(flag); i += 3, j += 4 )
// {
// input[j] = (flag[i] >> 2) & 0x3F;
// input[j + 1] = ((flag[i] & 0x3) << 4) | (flag[i + 1] & 0xF0 ) >> 4;
// input[j + 2] = ((flag[i + 1] & 0xF ) << 2) | (flag[i + 2] & 0xC0) >> 6;
// input[j + 3] = flag[i + 2] & 0x3F;
// }
}

GetFlag!

image-20220124233257947

DASCTF X SU
🍬
HFCTF2022
🍪

About this Post

This post is written by P.Z, licensed under CC BY-NC 4.0.