摸了一小会鱼。

glass

附件

重点是 libnative-lib.so。反汇编看一下操作也比较简单。没有完全做逆向,直接爆破了一下。需要三个三个爆破。

crack
  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
233
234
235
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <signal.h>

int32_t clz(uint32_t i)
{
    int32_t ret = 0;
    uint32_t temp = ~i;

    while (temp & 0x80000000)
    {
        temp <<= 1;
        ret++;
    }
    return ret;
}

int32_t sub_11DC(int32_t i, int32_t len)
{
    char v2;     // r2
    uint32_t v3; // r1
    uint32_t v4; // r3
    uint32_t v5; // r2
    int32_t v6;  // zf
    if (len != 1)
    {
        if (len)
        {
            if (i <= len)
            {
                i = i == len;
            }
            else if ((len & (len - 1)) != 0)
            {
                v2 = clz((uint32_t)len) - clz((uint32_t)i);
                v3 = len << v2;
                v4 = 1 << v2;
                v5 = 0;
                while (1)
                {
                    if (i >= v3)
                    {
                        i -= v3;
                        v5 |= v4;
                    }
                    if (i >= v3 >> 1)
                    {
                        i -= v3 >> 1;
                        v5 |= v4 >> 1;
                    }
                    if (i >= v3 >> 2)
                    {
                        i -= v3 >> 2;
                        v5 |= v4 >> 2;
                    }
                    if (i >= v3 >> 3)
                    {
                        i -= v3 >> 3;
                        v5 |= v4 >> 3;
                    }
                    v6 = i == 0;
                    if (i)
                    {
                        v4 >>= 4;
                        v6 = v4 == 0;
                    }
                    if (v6)
                        break;
                    v3 >>= 4;
                }
                i = v5;
            }
            else
            {
                i >>= 31 - clz((uint32_t)len);
            }
        }
        else
        {
            i = raise(8);
        }
    }
    return i;
}

int32_t sub_126C(int32_t i, int32_t len)
{
    int32_t r1 = i, r2 = len;
    int32_t r0 = sub_11DC(i, len);

    int32_t r3 = r2 * r0;
    r1 = r1 - r3;

    return r1;
}

void subFFC(char *str1, char *str2, int32_t len)
{
    char v12[256];
    memset(v12, 0, 0x100);
    int32_t i;
    int32_t v7, v8;
    for (i = 0; i != 256; ++i)
    {
        str1[i] = i;
        v7 = sub_126C(i, len);
        v12[i] = str2[v7];
    }
    v8 = 0;
    int32_t v9 = 0;
    int32_t v10;
    while (v8 != 256)
    {
        v10 = (unsigned char)str1[v8];
        v9 = (v9 + v10 + (unsigned char)v12[v8]) % 256;
        str1[v8++] = str1[v9];
        str1[v9] = v10;
    }
}

void sub1088(char *str1, char *str2, int32_t len)
{
    int32_t v3, v4, v5;
    v3 = 0, v4 = 0;
    while (len)
    {
        --len;
        v4 = (v4 + 1) % 256;
        v5 = (unsigned char)str1[v4];
        v3 = (v3 + v5) % 256;
        str1[v4] = str1[v3];
        str1[v3] = v5;
        *str2++ ^= str1[(unsigned char)(v5 + str1[v4])];
    }
}

void sub_10D4(char *str1, int32_t len1, char *str2, int32_t len2)
{
    int32_t i; // r4
    char *v5;  // r6
    char v6;   // r5
    char v7;   // lr
    char v8;   // r12
    int32_t j; // lr
    int32_t k; // r6

    for (i = 0; i < len1; i += 3)
    {
        v5 = &str1[i];
        v6 = str1[i + 2];
        v7 = str1[i + 1];
        v8 = str1[i] ^ v6;
        str1[i] = v8;
        v5[2] = v6 ^ v7;
        v5[1] = v7 ^ v8;
    }
    for (j = 0; j < len1; j += len2)
    {
        for (k = 0; (len2 & ~(len2 >> 31)) != k && j + k < len1; ++k)
            str1[k] ^= str2[k];
        str1 += len2;
    }
}

void checkFlag(char *flag)
{
    char str_12345678[256];
    char empty_str[256];

    memset(empty_str, 0, 0x100);
    // qmemcpy(str_12345678, "12345678", sizeof(str_12345678));
    memcpy(str_12345678, "12345678", sizeof(str_12345678));
    int32_t len256 = strlen(str_12345678);
    subFFC(empty_str, str_12345678, len256);
    sub1088(empty_str, flag, 39);
    sub_10D4(flag, 39, str_12345678, len256);
}

char tocmp[] = {0xA3, 0x1A, 0xE3, 0x69, 0x2F, 0xBB, 0x1A, 0x84, 0x65, 0xC2, 0xAD, 0xAD, 0x9E, 0x96, 0x5, 0x2, 0x1F, 0x8E, 0x36, 0x4F, 0xE1, 0xEB, 0xAF, 0xF0, 0xEA, 0xC4, 0xA8, 0x2D, 0x42, 0xC7, 0x6E, 0x3F, 0xB0, 0xD3, 0xCC, 0x78, 0xF9, 0x98, 0x3F, 0x00};

int main()
{
    // char flag[40] = "CISCN{AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}";
    char flag[40] = "CISCN{B6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\0";

    char flag_cpy[40];
    int32_t i = 0;
    char j;
    int32_t k;
    int a, b, c;
    while (1)
    {
        printf("[+] %d\n", i);
        for (a = 0x2d; a < 0x7E; ++a)
        {
            for (b = 0x2d; b < 0x7E; ++b)
            {
                for (c = 0x2d; c < 0x7E; ++c)
                {
                    for (k = 0; k < 40; ++k)
                    {
                        printf("%x ", (unsigned char)flag_cpy[k]);
                    }
                    strcpy(flag_cpy, flag);
                    flag_cpy[i] = a;
                    flag_cpy[i + 1] = b;
                    flag_cpy[i + 2] = c;
                    checkFlag(flag_cpy);
                    if (flag_cpy[i] == tocmp[i] && flag_cpy[i + 1] == tocmp[i + 1] && flag_cpy[i + 2] == tocmp[i + 2])
                    {
                        for (k = 0; k < 40; ++k)
                        {
                            printf("%x ", (unsigned char)flag_cpy[k]);
                        }
                        putchar('\n');
                        printf("flag[%d]=%c\n", i, a);
                        printf("flag[%d]=%c\n", i + 1, b);
                        printf("flag[%d]=%c\n", i + 2, c);
                        flag[i] = a;
                        flag[i + 1] = b;
                        flag[i + 2] = c;
                        printf("%s\n", flag);
                        // exit(0);
                        goto label;
                    }
                }
            }
        }
    label:
        i += 3;
    }
    return 0;
}

但是分析一下的话很多函数都可以优化掉,例如 sub_126C 函数,就是将 12345678 均匀映射到 256 位的数组中。

TODO: 实现 angr 解题的脚本。

baby bc

附件

给了一个 baby.bc,file 一下发现是 LLVM 的 IR。

1
2
$ file baby.bc
baby.bc: LLVM IR bitcode

用 clang 编译一下当成正常的逆向来做就行。

逆向时发现可以用符号执行直接找到输入。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import angr
from angr.sim_options import MEMORY_FIND_STRICT_SIZE_LIMIT
from angr.storage.file import Flags
import claripy

def main():
    path_to_bin = './a.out'
    project = angr.Project(path_to_bin)

    st = project.factory.entry_state(add_options={angr.options.SYMBOLIC_WRITE_ADDRESSES})

    input_chars = [claripy.BVS('flag_{}'.format(i), 8) for i in range(25)]
    myinput = claripy.Concat(*input_chars)
    st.memory.store(0x6020C0, myinput)

    sm = project.factory.simulation_manager(st)
    print(sm.explore(find=0x401410))
    found_state = sm.found[0]
    print(found_state.solver.eval(found_state.memory.load(0x6020C0, 25), cast_to=bytes))

main()

即可出输入。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$ python ppp.py
INFO    | 2021-05-15 20:01:30,308 | pyvex.lifting.libvex | unhandled opc_aux = 0x 6
first_opcode == 0xDF

INFO    | 2021-05-15 20:01:30,308 | pyvex.lifting.libvex | unhandled opc_aux = 0x 6
first_opcode == 0xDF

INFO    | 2021-05-15 20:01:30,309 | pyvex.lifting.libvex | unhandled opc_aux = 0x 6
first_opcode == 0xDF

<SimulationManager with 97 deadended, 1 found>
b'1425353142350212150442315'