第一次在52发帖,写的有问题的地方还请师傅们见谅
逆向部分题目很不错,VM题的伪随机控制流和迷宫题异常处理设置很巧妙,还剩两道没力气逆了,以后再补
ezjunk
花指令,直接NOP掉,反编译main函数
2024-04-27-22-51-30-image.png (72.48 KB, 下载次数: 0)
下载附件
2024-4-28 22:35 上传
2024-04-27-22-52-29-image.png (61.13 KB, 下载次数: 0)
下载附件
2024-4-28 22:37 上传
加密部分是xxtea,观察调用时传入的参数,a2是sum,来自loc_4015C3+2,a3是delta,来自loc_401A1C,a4是key,来自off_404350 + 400
delta在main里面,刚好是patch掉的部分,需要记录patch前的数据,sum在另一个函数里面,先去掉花指令
2024-04-27-22-58-14-image.png (57.45 KB, 下载次数: 0)
下载附件
2024-4-28 22:37 上传
找到sum所在的地方,这部分在main运行前执行,LoadLibraryA没用,可以忽略,IsDebuggerPresent检测调试器,根据是否被调试设置key,patch掉反调试,记录patch前的sum值
写xxtea解密
#!/usr/bin/env python
flag = [0x5406CBB1, 0xA4A41EA2, 0x34489AC5, 0x53D68797, 0xB8E0C06F, 0x259F2DB, 0x52E38D82, 0x595D5E1D]
k2 = 0xE8017300
k3 = 0xFF58F981
key = [0x5454, 0x4602, 0x4477, 0x5E5E, 0x33, 0x43, 0x54, 0x46]
for i in range(0, 7, 2):
v6 = flag[i+1]
v7 = flag
a2 = k2
for _ in range(32)
a2 = a2 + 0x100000000 - k3
a2 &= 0xFFFFFFFF
for _ in range(32):
a2 += k3
a2 &= 0xFFFFFFFF
v6 = v6 + 0x100000000 - (((v7 + ((v7 > 6))) ^ (key[(a2>>11)&3]+a2) ^ 0x33) & 0xFFFFFFFF)
v6 &= 0xFFFFFFFF
v7 = v7 + 0x100000000 - (((v6 + ((v6 > 5))) ^ (key[a2&3]+a2) ^ 0x44) & 0xFFFFFFFF)
v7 &= 0xFFFFFFFF
flag[i+1] = v6
flag = v7
print(hex(v7), hex(v6))
for f in flag:
print(f.to_bytes(4, "little").decode(), end='')
# fakeflag{Is_there_anywhere_else}
跑出来发现是假flagfakeflag{Is_there_anywhere_else},main里面是假校验,
分析发现注册了一个退出时调用的函数sub_4016BC,NOP去混淆反编译
2024-04-27-23-07-11-image.png (83.18 KB, 下载次数: 0)
下载附件
2024-4-28 22:37 上传
这里才是真check,对xxtea加密后的flag移位异或,再跟真ans校验
移位的时候根据最高为决定移位后是否异或0x84A6972F,逆向看的时候注意最低位,异或0x84A6972F后最低位为1,否则为0,所以解密根据最低位判断是否异或0x84A6972F
flag = [0xB6DDB3A9, 0x36162C23, 0x1889FABF, 0x6CE4E73B, 0xA5AF8FC, 0x21FF8415, 0x44859557, 0x2DC227B7]
for i in range(8):
for _ in range(32):
v0 = flag
if ((v0 & 1) == 1):
v0 ^= 0x84A6972F
v0 = v0 >> 1
v0 |= 0x80000000
else:
v0 = v0 >> 1
flag = v0
继续xxtea解密得到真flagd3ctf{ea3yjunk_c0d3_4nd_ea5y_re}
RandomVm
srand设置随机数种子0xD33B470,假随机,可以直接把rand跑出来
2024-04-27-23-19-11-image.png (57.03 KB, 下载次数: 1)
下载附件
2024-4-28 22:37 上传
大量函数都是上面的结构,先进行一段操作,再设置跳转表,rand一个随机数选择下一个执行的函数
每个函数对应一条虚拟机指令,控制流由跳转表和rand控制,需要分析每个函数的功能与跳转关系,100+函数手动分析是不可能的,用IDA Python解析一下
从入口开始解析,通过解析汇编指令获取跳转表,同时记录每个函数反编译的虚拟机指令
import idc
import idaapi
start = 0x717F
funcs = {}
# 递归找函数关系
def recur(addr):
print(hex(addr))
if (addr == 0x241A):
return
ea = addr
value_dic = {}
while (True):
ins = idc.generate_disasm_line(ea, 0)
if (ins.startswith("mov")):
op0 = idc.print_operand(ea, 0)
op1 = idc.print_operand(ea, 1)
# 过滤eax rax
if (op0[0] in "er"):
op0 = op0[1:]
if (op1[0] in "er"):
op1 = op1[1:]
value_dic[op0] = op1
value_dic[op0] = op1
if (op0.startswith("[rbp+var_")):
if (op1[-1] != 'h'):
value_dic[op0] = value_dic[op1]
# print(hex(ea), ins)
if (ins == "call _rand" and len(value_dic) >= 10):
break
ins_len = idc.create_insn(ea)
ea += ins_len
# xor
print(value_dic)
xor_ins = idc.print_operand(ea+0x36, 1)[:-1]
xor = int(xor_ins, 16)
nexts = []
for i in ["60", "58", "50", "48", "40", "38", "30", "28", "20", "18"]:
next = int(value_dic[f"[rbp+var_{i}]"][:-1], 16)
next = ((next ^ xor) + addr) & 0xFFFFFFFFFFFFFFFF
nexts.append(next)
funcs[addr] = nexts
for next in nexts:
if (next not in funcs):
recur(next)
ea = start
idc.set_name(ea, "main_main")
recur(ea)
print(funcs)
for ea in funcs:
src = str(idaapi.decompile(ea)).split('\n')
print(f"{hex(ea)}: \"{src[5]}\",")
分析后得到所有函数的关系,以及每个函数对应的虚拟机指令,手动优化一下
ops = {
0x717f: ([0x6bc8, 0x340a, 0x2917, 0x2db3, 0x6233, 0x4f23, 0x16f8, 0x1e22, 0x2f84, 0x2db3], " array[r0] = 0;"),
0x6bc8: ([0x55a9, 0x604e, 0x3725, 0x2917, 0x1fb5, 0x2425, 0x6d19, 0x7095, 0x16f8, 0x26a4], " *((_BYTE *)&flag + (unsigned __int8)r1) = ((int)*((unsigned __int8 *)&flag + (unsigned __int8)r1) >> array[r0]) | (*((_BYTE *)&flag + (unsigned __int8)r1) > array[r0]) | (*((_BYTE *)&flag + (unsigned __int8)r1) > array[r0]) | (*((_BYTE *)&flag + (unsigned __int8)r1) > array[r0]) | (*((_BYTE *)&flag + (unsigned __int8)r1) > array[r0]) | (*((_BYTE *)&flag + (unsigned __int8)r1)
虚拟机指令有下面几种
"""
array[r0] = 0
array[r0] += 1
array[r0] -= 1
r0 += 1
r0 -= 1
r1 += 1
r1 -= 1
flag[r1] = (flag[r1] >> array[r0]) | (flag[r1]
除了基本的数据处理外,使用syscall实现系统调用,还有if分支根据array[r0]决定是否跳过一个随机数,即控制执行流
pc = 0x717F
i = 0
skips = [18, 22, 48, 168, 172, 312, 340, 370, 397, 449, 478, 595, 599, 623, 627, 675]
while (pc != 0x241A):
print(i, hex(pc), ops[pc][1])
if (i in skips):
i += 1
r = rands
i += 1
pc = ops[pc][0][r]
根据跑出来的随机数解析一下控制流,类似于下面这种需要手动设置一下skip跳过一个随机数
"""
16 0x284a array[r0] = 0;
17 0x7717 --array[r0];
18 0x3565 if ( (char)array[r0]
虚拟指令里面用syscall(0)输入1个字符,进行一些移位异或操作
"""
array[0] = 0
array[1] = 0
array[3] = 1
10 array[2] = getchar()
flag[0] ^= array[2]
flag[1] = array[2]
array[2] = 3
flag[1] = (flag[1] >> 3 | (flag[1]
还有syscall(101, 0, 0, 0),即ptrace反调试检测,需要注意在无调试的情况下,第一次调用ptrace返回值为0,if不跳过rand,但是后续继续调用ptrace会返回-1,if需要跳过rand
"""
array[4] = 101
array[5] = 0
array[6] = 0
array[7] = 0
array[8] = 0
array[4] = syscall(101, 0, 0, 0) # ptrace反调试, 0
"""
输入完12个字符后,最后还有一段异或操作,人肉解析一下,纯体力活
"""
array[0] = 0
array[1] = 0
array[3] = 1
10 array[2] = getchar()
flag[0] ^= array[2]
flag[1] = array[2]
array[2] = 3
flag[1] = (flag[1] >> 3 | (flag[1] > 5 | (flag[2] > 6 | (flag[3] > 7 | (flag[4] > 4 | (flag[5] > 4 | (flag[6] > 7 | (flag[7] > 7 | (flag[8] > 2 | (flag[9] > 4) | (flag[10] > 4) | (flag[11] > 7) | (flag[12]
逆一下加密算法
flag = [0, 0x9D, 0x6B, 0xA1, 0x02, 0xD7, 0xED, 0x40, 0xF6, 0x0E, 0xAE, 0x84, 0x19]
for i in range(12, 1, -1):
flag ^= flag[i-1]
flag[12] ^= 7
flag[12] = (flag[12] > 1)
flag[12] &= 0xFF
flag[11] ^= flag[12]
flag[11] = (flag[11] > 4)
flag[11] &= 0xFF
flag[10] ^= flag[11]
flag[10] = (flag[10] > 4)
flag[10] &= 0xFF
flag[9] ^= flag[10]
flag[9] = (flag[9] > 6)
flag[9] &= 0xFF
flag[8] ^= flag[9]
flag[8] = (flag[8] > 1)
flag[8] &= 0xFF
flag[7] ^= flag[8]
flag[7] ^= 7
flag[7] = (flag[7] > 1)
flag[7] &= 0xFF
flag[6] ^= flag[7]
flag[6] = (flag[6] > 4)
flag[6] &= 0xFF
flag[5] ^= flag[6]
flag[5] ^= 4
flag[5] = (flag[5] > 4)
flag[5] &= 0xFF
flag[4] ^= flag[5]
flag[4] ^= 7
flag[4] = (flag[4] > 1)
flag[4] &= 0xFF
flag[3] ^= flag[4]
flag[3] = (flag[3] > 2)
flag[3] &= 0xFF
flag[2] ^= flag[3]
flag[2] = (flag[2] > 3)
flag[2] &= 0xFF
flag[1] ^= flag[2]
flag[1] ^= 3
flag[1] = (flag[1] > 5)
flag[1] &= 0xFF
# flag[0] ^= flag[1]
print(bytes(flag))
解密拿到flagd3ctf{m3owJumpVmvM}
forest
main里面检查flag格式,把输入的17个字符转换称01字符串,末尾加0
重点在sub_CE1F50里面,把一段内存设置为可执行,然后触发int 3异常,使用sub_CE1A00函数(execption_handle)处理异常
2024-04-27-23-56-17-image.png (52.6 KB, 下载次数: 0)
下载附件
2024-4-28 22:37 上传
unsigned int __thiscall execption_handle(unsigned int **this)
{
unsigned int result; // eax
unsigned int *v3; // ecx
unsigned int *v4; // eax
_DWORD *v5; // eax
int v6; // ecx
unsigned int v7; // edx
void **v8; // ecx
int v9; // esi
int i; // ecx
int v11; // edx
int v12; // eax
int v13; // esi
int v14; // edx
void **v15; // eax
int v16; // [esp+10h] [ebp-2Ch]
int v17; // [esp+14h] [ebp-28h]
_DWORD *v18; // [esp+18h] [ebp-24h]
GetCurrentThreadId();
result = **this;
if ( result v7 )
{
v8 = &flag;
if ( HIDWORD(len) >= 0x10 )
v8 = (void **)flag;
v16 = R2;
v9 = 0;
*(_DWORD *)R2 = *((_BYTE *)v8 + v7) != 0x30;
kk = v7 + 1;
for ( i = 0; i = (unsigned int)len )
{
return(1);
goto LABEL_39;
}
v15 = &flag;
if ( HIDWORD(len) >= 0x10 )
v15 = (void **)flag;
*(_DWORD *)R2 = *((_BYTE *)v15 + kk) != 0x30;
kk = v13 + 1;
this[1][46] = (unsigned int)&code + 0x40 * v14;
v4 = this[1];
LABEL_33:
v4[48] |= 0x100u;
return -1;
}
在execption_handle中根据异常码进行处理
// ksarm.h
#define STATUS_ACCESS_VIOLATION 0xc0000005
#define STAUSBREAKPOINT 0x80000003
#define STATUS_SINGLE_STEP 0x80000004
#define STATUS_PRIVILEGED_INSTRUCTION 0xc0000096
第一次int 3触发断点异常0x80000003,对应下面的异常处理代码
if (byte_CE6028)
{
byte_CE6028 = 0;
R2 = (int)malloc(4u);
R1 = (int)malloc(4u);
v5 = malloc(4u);
v6 = R1;
v7 = kk;
v18 = v5;
R0 = (int)v5;
*(_DWORD *)R1 = 0;
*v5 = 0;
v17 = v6;
if ((unsigned int)len > v7)
{
v8 = &flag;
if (HIDWORD(len) >= 0x10)
v8 = (void **)flag;
v16 = R2;
v9 = 0;
*(_DWORD *)R2 = *((_BYTE *)v8 + v7) != 0x30;
kk = v7 + 1;
for (i = 0; i
这段代码只能执行一次,后续再触发0x80000003异常程序会结束运行,代码里面malloc了3个变量,并使用这3个变量替换code(前面修改了可执行权限的内存)中的0xFFFFFFFF
R2的初值由*(_DWORD *)R2 = *((_BYTE *)v8 + v7) != 0x30;决定,这里是flag的第一个字符
将code初始化之后,this[1][46] = (unsigned int)&code;修改线程结构体的EIP,使异常处理结束后程序进入到code中执行
分析一下code部分代码,code代码中包含很多的代码块,每一块的长度为0x40,根据前面修改的规律可以知道在code块中R0、R1、R2的位置固定
2024-04-28-10-42-40-image.png (45.18 KB, 下载次数: 0)
下载附件
2024-4-28 22:37 上传
代码块中还有cli指令,由于cli指令是特权指令,ring3无法执行,因此运行到cli指令会触发0xc0000096异常,分析对应的处理代码
v13 = kk;
v14 = *(_DWORD *)R1 + 17 * *(_DWORD *)R0;
if (kk >= (unsigned int)len)
{
return (1);
goto LABEL_39;
}
v15 = &flag;
if (HIDWORD(len) >= 0x10)
v15 = (void **)flag;
*(_DWORD *)R2 = *((_BYTE *)v15 + kk) != 0x30;
kk = v13 + 1;
this[1][46] = (unsigned int)&code + 0x40 * v14;
v4 = this[1];
v4[48] |= 0x100u;
cli指令触发异常后,根据R1+17*R0的值确定下一个执行的代码块,修改EIP进入新的代码块,并且根据flag的01字符设置R2
结合code中的内容,在code代码中会设置R0、R1的值,接着使用cli触发异常,根据R0、R1的值选择下一个代码块,R2中储存了flag的一个bit
调试发现在code中还会触发0x80000004异常
2024-04-28-10-59-38-image.png (62.27 KB, 下载次数: 0)
下载附件
2024-4-28 22:37 上传
2024-04-28-11-07-03-image.png (26.23 KB, 下载次数: 0)
下载附件
2024-4-28 22:37 上传
跟踪一下发现这个异常是TF标志位造成的,TF标志位为1时,执行一条指令后就会触发0x80000004异常,在execption_handle中,返回时会设置v4[48] |= 0x100u;,这里设置的就是TF标志位
TF标志位触发异常后,会确定异常发生的位置,当异常发生位置为7,即mov eax, [eax]执行后,根据eax寄存器的确定是否进行跳转
if (result != 0x80000004)
return result;
v3 = this[1];
if (((v3[46] - (_DWORD)&code) & 0x3F) == 7 && v3[44] == 1)
v3[46] += 0x17;
v4 = this[1];
v4[48] |= 0x100u;
结合跳转的位置和code中的代码,这里实际是根据R2进行调整,如果R2,即flag为1,跳转到下一个cli块中设置R1、R0,综合分析知道这里是根据flag的01值决定下一个代码块,在每一个代码块中有两个可跳转的位置
使用IDA Python解析代码块,获取每个代码块中的两个跳转位置
import idc
import idaapi
image_base = idaapi.get_imagebase()
code_off = 0x6030
code_size = 0x4840
start = image_base + code_off
end = image_base + code_off + code_size
op_ls = [(-1, -1) for _ in range(0x121)]
for idx in range(0x121):
ea = start + idx * 0x40
print(f"[{hex(ea)}]: ")
ins = idc.generate_disasm_line(ea, 0)
if (ins.startswith("mov eax, 0FFFFFFFFh")):
op1 = idc.print_operand(ea+0x0C, 1)
if (op1[-1] == 'h'):
op1 = int(op1[:-1], 16)
else:
op1 = int(op1)
op2 = idc.print_operand(ea+0x17, 1)
if (op2[-1] == 'h'):
op2 = int(op2[:-1], 16)
else:
op2 = int(op2)
op3 = idc.print_operand(ea+0x23, 1)
if (op3[-1] == 'h'):
op3 = int(op3[:-1], 16)
else:
op3 = int(op3)
op4 = idc.print_operand(ea+0x2E, 1)
if (op4[-1] == 'h'):
op4 = int(op4[:-1], 16)
else:
op4 = int(op4)
ins = (op1+17*op2, op3+17*op4)
elif (ins.startswith("int 3")):
ins = (-1, -1)
print(ins)
op_ls[idx] = ins
print(op_ls)
在解析时发现除了上面正常的代码块,还有下面几种代码块
"""
int 3
add [ecx-51h], ebx
mov eax, 1; mov dword ptr [eax], 39393939h
add [ebp+28D5560Ah], ecx
"""
其中int 3触发0x80000003异常,由于该异常只能处理一次,所有遇到int 3的代码块会直接die掉
剩余3条指令会触发0xC0000005异常,该异常会进入right,输出正确信息
分析后可以知道本题其实是一道迷宫题,根据输入的flag决定走的路径,走到出口胜利
先找一下实际可到达的出口
op_ls = [(11, 41), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (193, 52), (7, 7), (216, 43), (116, 13), (120, 189), (82, 244), (12, 12), (8, 15), (-1, -1), (-1, -1), (72, 95), (233, 272), (211, 194), (-1, -1), (59, 230), (237, 89), (60, 190), (23, 23), (243, 232), 'add [ecx-51h], ebx', (207, 224), 'mov eax, 1', (31, 61), (151, 179), (12, 180), (-1, -1), (76, 147), (-1, -1), (153, 196), (279, 271), (-1, -1), (276, 7), (38, 38), (39, 39), (48, 171), (-1, -1), (236, 251), (16, 192), (-1, -1), (125, 165), (46, 46), (260, 27), (45, 3), (174, 190), (219, 92), (51, 51), (-1, -1), 'add [ebp+28D5560Ah], ecx', (54, 54), (280, 204), (20, 135), (57, 57), (58, 58), (59, 59), (60, 60), (223, 235), (113, 265), (55, 278), (87, 6), (19, 214), (100, 36), (-1, -1), (68, 68), (69, 69), (70, 70), (130, 24), (258, 44), (73, 73), (74, 74), (75, 75), (76, 76), (77, 77), (122, 240), (79, 79), (80, 80), (-1, -1), (67, 26), (83, 83), (117, 118), (85, 85), (-1, -1), (-1, -1), (106, 73), (89, 89), (-1, -1), (-1, -1), (119, 129), (93, 93), (85, 167), (-1, -1), (96, 96), (97, 97), (123, 225), (259, 173), (229, 226), (101, 101), (269, 68), (169, 182), (104, 104), (105, 105), (154, 50), (-1, -1), (108, 108), (23, 112), (140, 99), (111, 111), (210, 202), (113, 113), (274, 56), (-1, -1), (-1, -1), (261, 42), (118, 118), (32, 115), (267, 209), (121, 121), (122, 122), (123, 123), (231, 256), (125, 125), (126, 126), (57, 206), (145, 245), (129, 129), (130, 130), (131, 131), (-1, -1), (133, 133), (155, 162), (135, 135), (136, 136), (-1, -1), (-1, -1), (-1, -1), (140, 140), (78, 197), (134, 163), (200, 103), (71, 218), (185, 283), (-1, -1), (139, 34), (188, 104), (-1, -1), (150, 150), (151, 151), (102, 253), (246, 157), (154, 154), (155, 155), 'add [ebp+57h], ebp', (93, 255), (158, 158), (38, 144), (281, 286), (28, 146), (186, 285), (163, 163), (138, 174), (69, 37), (166, 166), (241, 111), (168, 168), (169, 169), (-1, -1), (171, 171), (58, 148), (173, 173), (205, 64), (175, 175), (176, 176), (177, 177), 'add ds:0F215EE7Ch[edi*8], ecx', (181, 75), (128, 264), (257, 270), (160, 176), (221, 175), (101, 141), (220, 47), (88, 91), (195, 114), (158, 247), (189, 189), (80, 142), (287, 133), (-1, -1), (14, 161), (242, 166), (195, 195), (196, 196), (197, 197), 'add [edx], edi', (131, 65), (200, 200), (190, 130), (199, 96), (183, 105), (204, 204), (-1, -1), (35, 74), (-1, -1), (168, 109), (209, 209), (210, 210), (-1, -1), (-1, -1), (213, 213), (239, 108), (215, 215), (-1, -1), (217, 217), (218, 218), (219, 219), (220, 220), (136, 10), (222, 222), (107, 266), (66, 273), (1, 21), (-1, -1), (227, 227), (228, 228), (263, 170), (5, 191), (62, 46), (232, 232), (-1, -1), (103, 36), (-1, -1), (236, 236), (184, 2), (-1, -1), (98, 137), (126, 277), (217, 250), (172, 228), (102, 70), (-1, -1), (245, 245), (246, 246), (17, 86), (248, 248), (104, 38), (83, 268), (39, 187), (270, 128), (253, 253), (22, 149), (4, 94), (256, 256), (257, 257), (222, 84), (215, 288), (260, 260), (-1, -1), (254, 248), (164, 132), (264, 264), (54, 262), (33, 9), (253, 18), (213, 203), (30, 97), (40, 227), (271, 271), (79, 127), (-1, -1), (274, 274), (131, 241), (212, 63), (77, 143), (-1, -1), (121, 110), (124, 150), (281, 281), (282, 282), (-1, -1), 'add edi, esp', (285, 285), (51, 29), (282, 208), (159, 177)]
for i in range(0x121):
if (type(op_ls) != str):
continue
for j in range(0x121):
if (type(op_ls[j]) == str):
continue
if (i in op_ls[j]):
print(f"[{i}]: {op_ls}")
break
真出口在[27] mov eax, 1; mov dword ptr [eax], 39393939h
dfs走迷宫找出口记录路径
def dfs(cur, path=[]):
# print(cur, path)
if (cur == 27):
print(path)
return
elif (type(op_ls[cur]) == str):
return
l = op_ls[cur][0]
if (l != -1 and l not in path):
new_path = path.copy()
new_path.append(cur)
dfs(l, new_path)
r = op_ls[cur][1]
if (r != -1 and r not in path):
new_path = path.copy()
new_path.append(cur)
dfs(r, new_path)
dfs(0, [])
只有一条路,长度正好是17 * 8,把路径转换为flag
path = [11, 82, 26, 224, 66, 100, 229, 263, 164, 174, 64, 6, 193, 161, 28, 61, 223, 266, 9, 13, 8, 43, 16, 72, 258, 84, 117, 42, 251, 187, 114, 56, 20, 230, 191, 287, 208, 109, 112, 202, 199, 65, 214, 239, 98, 225, 21, 237, 184, 141, 78, 240, 277, 143, 103, 182, 160, 286, 29, 179, 181, 270, 40, 48, 45, 165, 37, 276, 63, 55, 280, 124, 231, 62, 265, 262, 254, 22, 190, 142, 134, 162, 186, 88, 106, 50, 92, 119, 32, 147, 34, 153, 157, 255, 94, 167, 241, 250, 268, 203, 183, 221, 10, 120, 267, 18, 194, 242, 172, 148, 188, 247, 17, 272, 127, 206, 35, 279, 110, 99, 259, 288, 159, 144, 71, 24, 243, 102, 269, 30, 180, 128, 145, 185, 47, 27]
last = 0
flag = ""
for cur in path:
if (cur == op_ls[last][0]):
flag += "0"
else:
flag += "1"
last = cur
print(int(flag, 2).to_bytes(17))
# d3ctf{0ut_of_th3ForesT#}
最后得到题目flagd3ctf{0ut_of_th3ForesT#}