首页
社区
课程
招聘
[原创]KCTF 第二题 星际生物
发表于: 2024-8-17 02:46 1535

[原创]KCTF 第二题 星际生物

2024-8-17 02:46
1535

1.ILSpy 反编译

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// brain, Version=1.0.8991.31927, Culture=neutral, PublicKeyToken=null
// <Module>
using System.Runtime.CompilerServices;
using <CppImplementationDetails>;
 
internal unsafe static int main()
{
    //IL_0032: Expected I, but got I8
    //IL_00ed: Expected I, but got I8
    //IL_0101: Expected I, but got I8
    //IL_0215: Expected I, but got I8
    //IL_0174: Expected I, but got I8
    //IL_01fe: Expected I, but got I8
    System.Runtime.CompilerServices.Unsafe.SkipInit(out $ArrayType$$$BY0BAA@D $ArrayType$$$BY0BAA@D);
    // IL initblk instruction
    System.Runtime.CompilerServices.Unsafe.InitBlock(ref $ArrayType$$$BY0BAA@D, 0, 256);
    printf((sbyte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref ??_C@_0BJ@MNCFGMHN@Please?5input?5your?5flag?3?5?$AA@), __arglist());
    scanf((sbyte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref ??_C@_05HPMPOKFN@?$CF?$FL?$FO?6?$FN?$AA@), __arglist((sbyte*)(&$ArrayType$$$BY0BAA@D)));
    sbyte* ptr = (sbyte*)(&$ArrayType$$$BY0BAA@D);
    if (*(bool*)(&$ArrayType$$$BY0BAA@D))
    {
        do
        {
            ptr = (sbyte*)((ulong)(nint)ptr + 1uL);
        }
        while (*ptr != 0);
    }
    if ((uint)((ref *(?*)ptr) - (ref *(?*)(&$ArrayType$$$BY0BAA@D))) != 70)
    {
        printf((sbyte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref ??_C@_0M@IIPHMAMA@Try?5again?$CB?6?$AA@), __arglist());
        return -1;
    }
    if (*(sbyte*)(&$ArrayType$$$BY0BAA@D) == 102 && System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY0BAA@D, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY0BAA@D, 1)) == 108 && System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY0BAA@D, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY0BAA@D, 2)) == 97 && System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY0BAA@D, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY0BAA@D, 3)) == 103 && System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY0BAA@D, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY0BAA@D, 4)) == 123 && System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY0BAA@D, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY0BAA@D, 69)) == 125)
    {
        System.Runtime.CompilerServices.Unsafe.SkipInit(out $ArrayType$$$BY0EA@E $ArrayType$$$BY0EA@E);
        // IL cpblk instruction
        System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(ref $ArrayType$$$BY0EA@E, ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY0BAA@D, 5), 64);
        uint num = 0u;
        uint num2 = 0u;
        $ArrayType$$$BY188E* ptr2 = ($ArrayType$$$BY188E*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref sudoku);
        do
        {
            uint num3 = 0u;
            $ArrayType$$$BY188E* ptr3 = ptr2;
            do
            {
                if (*(byte*)ptr3 == 15)
                {
                    byte b = *(byte*)((ref *(?*)num) + (ref *(?*)(&$ArrayType$$$BY0EA@E)));
                    if ((uint)b < 48u || (uint)b > 57u)
                    {
                        printf((sbyte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref ??_C@_0M@IIPHMAMA@Try?5again?$CB?6?$AA@), __arglist());
                        return -1;
                    }
                    *(sbyte*)ptr3 = (sbyte)(b - 48);
                    num++;
                }
                num3++;
                ptr3 = ($ArrayType$$$BY188E*)((ulong)(nint)ptr3 + 1uL);
            }
            while (num3 < 9);
            num2++;
            ptr2 = ($ArrayType$$$BY188E*)((ulong)(nint)ptr2 + 9uL);
        }
        while (num2 < 9);
        uint num4 = 1u;
        uint num5 = 1u;
        uint num6 = 0u;
        long num7 = 0L;
        while (num4 == 1)
        {
            long num8 = 0L;
            uint num9 = 1u;
            while (num4 == 1)
            {
                uint num10 = num9;
                if (num9 < 9)
                {
                    long num11 = num9;
                    byte b2 = *(byte*)((ref *(?*)(num7 + num8)) + (ref System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY188E, ?>(ref sudoku)));
                    num4 = 1u;
                    $ArrayType$$$BY188E* ptr4 = ($ArrayType$$$BY188E*)((ref *(?*)(num7 + num11)) + (ref System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY188E, ?>(ref sudoku)));
                    do
                    {
                        if (b2 != *(byte*)ptr4)
                        {
                            num10++;
                            ptr4 = ($ArrayType$$$BY188E*)((ulong)(nint)ptr4 + 1uL);
                            continue;
                        }
                        num4 = 0u;
                        break;
                    }
                    while (num10 < 9);
                }
                num9++;
                num8++;
                if (num9 - 1 >= 9)
                {
                    break;
                }
            }
            num6++;
            num7 += 9;
            if (num6 >= 9)
            {
                break;
            }
        }
        uint num12 = 0u;
        long num13 = 0L;
        while (num5 == 1)
        {
            uint num14 = 1u;
            $ArrayType$$$BY188E* ptr5 = ($ArrayType$$$BY188E*)((ref *(?*)num13) + (ref System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY188E, ?>(ref sudoku)));
            while (num5 == 1)
            {
                uint num15 = num14;
                if (num14 < 9)
                {
                    long num16 = num14;
                    byte b3 = *(byte*)ptr5;
                    num5 = 1u;
                    $ArrayType$$$BY188E* ptr6 = ($ArrayType$$$BY188E*)((ref *(?*)(num16 * 9 + num13)) + (ref System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY188E, ?>(ref sudoku)));
                    do
                    {
                        if (b3 != *(byte*)ptr6)
                        {
                            num15++;
                            ptr6 = ($ArrayType$$$BY188E*)((ulong)(nint)ptr6 + 9uL);
                            continue;
                        }
                        num5 = 0u;
                        break;
                    }
                    while (num15 < 9);
                }
                num14++;
                ptr5 = ($ArrayType$$$BY188E*)((ulong)(nint)ptr5 + 9uL);
                if (num14 - 1 >= 9)
                {
                    break;
                }
            }
            num12++;
            num13++;
            if (num12 >= 9)
            {
                break;
            }
        }
        if (num4 == 1 && num5 == 1)
        {
            System.Runtime.CompilerServices.Unsafe.SkipInit(out $ArrayType$$$BY133E $ArrayType$$$BY133E);
            *(sbyte*)(&$ArrayType$$$BY133E) = 33;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 1)) = 45;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 2)) = 63;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 3)) = 43;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 4)) = 43;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 5)) = 43;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 6)) = 45;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 7)) = 43;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 8)) = 45;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 9)) = 43;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 10)) = 43;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 11)) = 43;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 12)) = 43;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 13)) = 45;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 14)) = 45;
            System.Runtime.CompilerServices.Unsafe.As<$ArrayType$$$BY133E, sbyte>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref $ArrayType$$$BY133E, 15)) = 43;
            byte b4 = 0;
            byte b5 = 0;
            uint num17 = 0u;
            do
            {
                int num18 = *(byte*)((ref *(?*)num) + (ref *(?*)(&$ArrayType$$$BY0EA@E)));
                num++;
                switch (num18)
                {
                case 87:
                    if (b4 != 0)
                    {
                        b4--;
                        goto default;
                    }
                    printf((sbyte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref ??_C@_0M@IIPHMAMA@Try?5again?$CB?6?$AA@), __arglist());
                    return -1;
                case 83:
                    if (b4 != 3)
                    {
                        b4++;
                        goto default;
                    }
                    printf((sbyte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref ??_C@_0M@IIPHMAMA@Try?5again?$CB?6?$AA@), __arglist());
                    return -1;
                case 68:
                    if (b5 != 3)
                    {
                        b5++;
                        goto default;
                    }
                    printf((sbyte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref ??_C@_0M@IIPHMAMA@Try?5again?$CB?6?$AA@), __arglist());
                    return -1;
                case 65:
                    if (b5 != 0)
                    {
                        b5--;
                        goto default;
                    }
                    printf((sbyte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref ??_C@_0M@IIPHMAMA@Try?5again?$CB?6?$AA@), __arglist());
                    return -1;
                default:
                    if (System.Runtime.CompilerServices.Unsafe.Add(ref *(byte*)((ref *(?*)b5) + (ref *(?*)(&$ArrayType$$$BY133E))), (long)b4 * 4L) == 45)
                    {
                        printf((sbyte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref ??_C@_0M@IIPHMAMA@Try?5again?$CB?6?$AA@), __arglist());
                        return -1;
                    }
                    break;
                }
                num17++;
            }
            while (num17 < 8);
            if (System.Runtime.CompilerServices.Unsafe.Add(ref *(byte*)((ref *(?*)b5) + (ref *(?*)(&$ArrayType$$$BY133E))), (long)b4 * 4L) == 63)
            {
                printf((sbyte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref ??_C@_0BB@MGPKLNCH@You?5are?5winner?$CB?6?$AA@), __arglist());
                return 0;
            }
        }
    }
    printf((sbyte*)System.Runtime.CompilerServices.Unsafe.AsPointer(ref ??_C@_0M@IIPHMAMA@Try?5again?$CB?6?$AA@), __arglist());
    return -1;
}

2.0
sudoku变量名提示数独
查看sudoku是一个9X9的表格

查看程序逻辑就是将flag在sudoku的0xf处的填入数组
然后检查每一列每一行是否重复
最后是一个迷宫4X4的,肉眼可解

最后将转换的数字按次序排列+迷宫的WASD序列就是最后的flag


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回
//