buuctf reverse3

拖进IDA(32)查看伪代码

buuctf reverse3

 

 输入flag后有一点不一样,要经过函数sub_4110BE处理,后经过for与str2比较

进入该函数查看

 1 void *__cdecl sub_411AB0(char *a1, unsigned int a2, int *a3)
 2 {
 3   int v4; // STE0_4
 4   int v5; // STE0_4
 5   int v6; // STE0_4
 6   int v7; // [esp+D4h] [ebp-38h]
 7   signed int i; // [esp+E0h] [ebp-2Ch]
 8   unsigned int v9; // [esp+ECh] [ebp-20h]
 9   int v10; // [esp+ECh] [ebp-20h]
10   signed int v11; // [esp+ECh] [ebp-20h]
11   void *Dst; // [esp+F8h] [ebp-14h]
12   char *v13; // [esp+104h] [ebp-8h]
13 
14   if ( !a1 || !a2 )
15     return 0;
16   v9 = a2 / 3;
17   if ( (signed int)(a2 / 3) % 3 )
18     ++v9;
19   v10 = 4 * v9;
20   *a3 = v10;
21   Dst = malloc(v10 + 1);
22   if ( !Dst )
23     return 0;
24   j_memset(Dst, 0, v10 + 1);
25   v13 = a1;
26   v11 = a2;
27   v7 = 0;
28   while ( v11 > 0 )
29   {
30     byte_41A144[2] = 0;
31     byte_41A144[1] = 0;
32     byte_41A144[0] = 0;
33     for ( i = 0; i < 3 && v11 >= 1; ++i )
34     {
35       byte_41A144[i] = *v13;
36       --v11;
37       ++v13;
38     }
39     if ( !i )
40       break;
41     switch ( i )
42     {
43       case 1:
44         *((_BYTE *)Dst + v7) = aAbcdefghijklmn[(signed int)(unsigned __int8)byte_41A144[0] >> 2];
45         v4 = v7 + 1;
46         *((_BYTE *)Dst + v4++) = aAbcdefghijklmn[((byte_41A144[1] & 0xF0) >> 4) | 16 * (byte_41A144[0] & 3)];
47         *((_BYTE *)Dst + v4++) = aAbcdefghijklmn[64];
48         *((_BYTE *)Dst + v4) = aAbcdefghijklmn[64];
49         v7 = v4 + 1;
50         break;
51       case 2:
52         *((_BYTE *)Dst + v7) = aAbcdefghijklmn[(signed int)(unsigned __int8)byte_41A144[0] >> 2];
53         v5 = v7 + 1;
54         *((_BYTE *)Dst + v5++) = aAbcdefghijklmn[((byte_41A144[1] & 0xF0) >> 4) | 16 * (byte_41A144[0] & 3)];
55         *((_BYTE *)Dst + v5++) = aAbcdefghijklmn[((byte_41A144[2] & 0xC0) >> 6) | 4 * (byte_41A144[1] & 0xF)];
56         *((_BYTE *)Dst + v5) = aAbcdefghijklmn[64];
57         v7 = v5 + 1;
58         break;
59       case 3:
60         *((_BYTE *)Dst + v7) = aAbcdefghijklmn[(signed int)(unsigned __int8)byte_41A144[0] >> 2];
61         v6 = v7 + 1;
62         *((_BYTE *)Dst + v6++) = aAbcdefghijklmn[((byte_41A144[1] & 0xF0) >> 4) | 16 * (byte_41A144[0] & 3)];
63         *((_BYTE *)Dst + v6++) = aAbcdefghijklmn[((byte_41A144[2] & 0xC0) >> 6) | 4 * (byte_41A144[1] & 0xF)];
64         *((_BYTE *)Dst + v6) = aAbcdefghijklmn[byte_41A144[2] & 0x3F];
65         v7 = v6 + 1;
66         break;
67     }
68   }
69   *((_BYTE *)Dst + v7) = 0;
70   return Dst;
71 }

发现奇怪的编码,进入查看

buuctf reverse3

 

 是base64编码

写脚本记得for-i后base64逆运算

1 import base64
2 s="e3nifIH9b_C@n@dH"
3 flag=""
4 for i in range(0,len(s)):
5     flag+=chr(ord(s[i])-i)
6 print(base64.b64decode(flag))

 

上一篇:C语言实现静态数据表,遇到结构体赋值完成后遍历输出结构体乱码


下一篇:21_颜色反转