西湖论剑2021WP_RE复现

先复现RE的吧,之后可能会有别的

RE

ROP

32位无壳,逻辑很简单。粘上主要实现代码

printf("Input:");
scanf("%40s", (char)flag);
if (strlen(flag) != 40)
exit(0);
for (i = 0; i < 0x28; i += 8)
{
for (j = 0; j < 8; ++j)
{
v4 = ((v5[j] & flag[i + 3]) << (8 - (3 - j) % 8u)) | ((v5[j] & (unsigned int)flag[i + 3]) >> ((3 - j) % 8u)) | ((v5[j] & flag[i + 2]) << (8 - (2 - j) % 8u)) | ((v5[j] & (unsigned int)flag[i + 2]) >> ((2 - j) % 8u)) | ((v5[j] & flag[i + 1]) << (8 - (1 - j) % 8u)) | ((v5[j] & (unsigned int)flag[i + 1]) >> ((1 - j) % 8u)) | ((v5[j] & (unsigned __int8)flag[i]) << (8 - -j % 8u)) | ((v5[j] & (unsigned int)flag[i]) >> (-j % 8u));
Buf2[j + i] = byte_405000[(unsigned __int8)(((v5[j] & (unsigned __int8)flag[i + 7]) << (8 - (7 - j) % 8u)) | ((v5[j] & (unsigned int)flag[i + 7]) >> ((7 - j) % 8u)) | ((v5[j] & flag[i + 6]) << (8 - (6 - j) % 8u)) | ((v5[j] & (unsigned int)flag[i + 6]) >> ((6 - j) % 8u)) | ((v5[j] & flag[i + 5]) << (8 - (5 - j) % 8u)) | ((v5[j] & (unsigned int)flag[i + 5]) >> ((5 - j) % 8u)) | ((v5[j] & flag[i + 4]) << (8 - (4 - j) % 8u)) | ((v5[j] & (unsigned int)flag[i + 4]) >> ((4 - j) % 8u)) | v4)];
}
}
if (memcmp(&unk_405100, Buf2, 0x28u))
{
puts("Wrong");
exit(0);
}
puts("Congratulations");
puts("flag is DASCTF{your input}");

但脚本不好写,导致当时没出来,z3不能直接进行位运算,需要加上BitVecs,当时也没怎么看懂,还是脚本写少了,都分析出来了就是出不来。

进行整理v0和buf2

v0 = 
((*(&v2 + j) & *(flag+3 + i)) << (8 - (3 - j) % 8u)) |
((*(&v2 + j) & *(flag+3 + i)) >> (3 - j) % 8u) |
((*(&v2 + j) & *(flag+2 + i)) << (8 - (2 - j) % 8u)) |
((*(&v2 + j) & *(flag+2 + i)) >> (2 - j) % 8u) |
((*(&v2 + j) & *(flag+1 + i)) << (8 - (1 - j) % 8u)) |
((*(&v2 + j) & *(flag+1 + i)) >> (1 - j) % 8u) |
((*(&v2 + j) & *(flag + i)) << (8 - -j % 8u)) |
((*(&v2 + j) & *(flag + i)) >> -j % 8u);

Buf2[j + i] = byte_405000[
((*(&v2 + j) & *(flag+7 + i) << (8 - (7 - j) % 8u) |
((*(&v2 + j) & *(flag+7 + i) >> (7 - j) % 8u) |
((*(&v2 + j) & *(flag+6 + i)) << (8 - (6 - j) % 8u)) |
((*(&v2 + j) & *(flag+6 + i)) >> (6 - j) % 8u) |
((*(&v2 + j) & *(flag+5 + i)) << (8 - (5 - j) % 8u)) |
((*(&v2 + j) & *(flag+5 + i)) >> (5 - j) % 8u) |
((*(&v2 + j) & *(flag+4 + i)) << (8 - (4 - j) % 8u)) |
((*(&v2 + j) & *(flag+4 + i)) >> (4 - j) % 8u) |
v0)];

z3上,写脚本

from z3 import *
Buf2 = [0x65, 0x55, 0x24, 0x36, 0x9D, 0x71, 0xB8, 0xC8, 0x65, 0xFB, 0x87, 0x7F, 0x9A, 0x9C, 0xB1, 0xDF, 0x65, 0x8F, 0x9D, 0x39, 0x8F, 0x11, 0xF6, 0x8E, 0x65, 0x42, 0xDA, 0xB4, 0x8C, 0x39, 0xFB, 0x99, 0x65, 0x48, 0x6A, 0xCA, 0x63, 0xE7, 0xA4, 0x79]
byte_405000 = [0x65, 0x08, 0xF7, 0x12, 0xBC, 0xC3, 0xCF, 0xB8, 0x83, 0x7B, 0x02, 0xD5, 0x34, 0xBD, 0x9F, 0x33, 0x77, 0x76, 0xD4, 0xD7, 0xEB, 0x90, 0x89, 0x5E, 0x54, 0x01, 0x7D, 0xF4, 0x11, 0xFF, 0x99, 0x49, 0xAD, 0x57, 0x46, 0x67, 0x2A, 0x9D, 0x7F, 0x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0xC8, 0x0E, 0x8C, 0xE5, 0x9E, 0xAE, 0xBF, 0xEF, 0x42, 0xC5, 0xAF, 0xA0, 0xC2, 0xFA, 0xC7, 0xB6, 0xDB, 0x18, 0xC4, 0xA6, 0xFE, 0xE9, 0xF5, 0x6E, 0x64, 0x2F, 0xF1, 0x1B, 0xFB, 0xBA, 0xA7, 0x37, 0x8F]
key = [128,64,32,16,8,4,2,1]

flag = [BitVec(f"flag[{i}]", 8) for i in range(40)]

s = Solver()
for i in range(0,0x28,8):
for j in range(8):
v0 = ((key[j] & flag[i + 3]) << (8 - (3 - j) % 8)) | ((key[j] & flag[i + 3]) >> ((3 - j) % 8)) | ((key[j] & flag[i + 2]) << (8 - (2 - j) % 8)) | ((key[j] & flag[i + 2]) >> ((2 - j) % 8)) | ((key[j] & flag[i + 1]) << (8 - (1 - j) % 8)) | ((key[j] & flag[i + 1]) >> ((1 - j) % 8)) | ((key[j] & flag[i]) << (8 - -j % 8)) | ((key[j] & flag[i]) >> (-j % 8))
Buf2_ = ((key[j] & flag[i + 7]) << (8 - (7 - j) % 8)) | ((key[j] & flag[i + 7]) >> ((7 - j) % 8)) | ((key[j] & flag[i + 6]) << (8 - (6 - j) % 8)) | ((key[j] & flag[i + 6]) >> ((6 - j) % 8)) | ((key[j] & flag[i + 5]) << (8 - (5 - j) % 8)) | ((key[j] & flag[i + 5]) >> ((5 - j) % 8)) | ((key[j] & flag[i + 4]) << (8 - (4 - j) % 8)) | ((key[j] & flag[i + 4]) >> ((4 - j) % 8))

s.add(v0 | Buf2_ == byte_405000.index(Buf2[i+j])) # 算出结果和数组比对
assert s.check() == sat
m = s.model()

flag1 = []
for i in flag:
flag1.append(chr(m[i].as_long()))
print(''.join(flag1))

TacticalArmed

程序开始时有反调试,把int 2D patch成int 3之后就可以动调。
抛出异常后会初始化四个常量,调试可以得到4011F0函数处smc执行后的字节码。

smc可以识别,但脱包不熟练

复现不出来脱包过程,之后再试试

只能在静态看看555

查看函数发现TlsCallback_0函数,进入函数,发现startAddress中存在int 2Dh,限制动调,在调试的时候不会去抛出异常,正常执行的时候抛出异常,也就是说需要抛出异常才是正常情况,可能那里藏了什么,跟踪一下

在OD中打开将其设置为int 3h。

继续无脑按F8发现

mov     esp, [ebp+ms_exc.old_esp]
mov eax, 4
imul ecx, eax, 0 ;imul为有符号数乘法
mov dword_405000[ecx], 7CE45630h

mov eax, 4
shl eax, 0 ;shl为逻辑左移一位
mov dword_405000[eax], 58334908h

mov eax, 4
shl eax, 1
mov dword_405000[eax], 66398867h

mov eax, 4
imul ecx, eax, 3
mov dword_405000[ecx], 0C35195B1h
mov [ebp+ms_exc.registration.TryLevel], 0FFFFFFFFh

运行到主函数发现每次循环,里面的指令都不一样,这里应该是一个动态解码的过程,分析这个算法应该为tea算法,确定delta为0x81A5692e

反汇编可见 右移5左移4XOR 推测是TEA加密输入值后比较是否一致,写解密脚本:

#include 
#include

void decrypt(uint32_t* v, uint32_t* k,int z) {

uint32_t v0 = v[0], v1 = v[1], sum = 0x81A5692e*33*(z+1), i;
uint32_t k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3];

for (i = 0; i < 33; i++) {
v1 -= ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
v0 -= ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
sum -= 0x81A5692e;
}
v[0] = v0;
v[1] = v1;
}

int main()
{
uint32_t key[] = {0x7CE45630, 0x58334908, 0x66398867, 0x0C35195B1};
int8_t ida_chars[40] ={0xED, 0x1D, 0x2F, 0x42, 0x72, 0xE4, 0x85, 0x14, 0xD5, 0x78, 0x55, 0x03, 0xA2, 0x80, 0x6B, 0xBF, 0x45, 0x72, 0xD7, 0x97, 0xD1, 0x75, 0xAE, 0x2D, 0x63, 0xA9, 0x5F, 0x66, 0x74, 0x6D, 0x2E, 0x29, 0xC1, 0xFC, 0x95, 0x97, 0xE9, 0xC8, 0xB5, 0x0B};

int i,j;
for (i = 0,j=0; i < 40,j < 5; i += 8,j++)
{
decrypt((uint32_t*)(ida_chars + i), key , j);
}

printf("%s\n",ida_chars);
}

Re4-虚假的粉丝

看程序

FileName[16] = (char)key1 / -24 + 48;
v15 = (char)(key1 / 100) % 10 + 48;
v16 = (char)(key1 / 10) % 10 + 48;
v17 = key1 % 10 + 48; //字符串转化为数字,预测是编号
v18 = 'txt.';
Stream = fopen(FileName, "r");

memset(Buffer, 0, sizeof(Buffer));
fseek(Stream, Offset, 0);
fread(Buffer, ElementSize, 1u, Stream)
sub_401350("%s\n", Buffer);
if ( Buffer[0] != 'U' || Buffer[39] != 'S' ) //需要个40位的 首尾是U和S,拿everything搜一波,得到4157
{
sub_401350("Sorry! Wrong Key.\n");
fclose(Stream);
return 0;
}

key1为4157

继续分析

fseek(Stream, key2, 0); // key2为offest,偏移量为1118
fread(Buffer, key3, 1u, Stream); // key3为size,大小为40

程序输出对其进行base64解密

UzNDcmU3X0szeSUyMCUzRCUyMEFsNE5fd0FsSzNS -> S3Cre7_K3y%20%3D%20Al4N_wAlK3R得到key:Al4N_wAlK3R

然后在5315中即可得到flag

:ii:,::iiriririi::.,.,,::ii;:::::i::::iiiiiii;irir;;i;::,::i:::::i::,::i:::iir;rii::ir:ii::::ii;i;i;i;i;iiii:
::::@B@,iiririi:@B@B@B@B::i::2@B:::B@q::i:::ii;iririi::B@Bi::B@B:,:@@U:,BBM:iirii,PB@B;::.@B5:i:i:i:iii:i::::
::,@B@BY:iiri;i:B@B@B@B@::.L:@B@.:,@B@.:,7jr,:i;iri;i:L@B@B.,G@@,.B@B@..B@F:irii:;B@B7,:.@B@B,:r:,Lv,:::,ju7,
:,F@@:@B.:iirir::..B@ ..@B@BkS@B.:.B@B.7@@@@@i:i;i;i:.@@,B@u..@BE @@@B:r@B,:ri;iiB@B@B.:@B@BG.iB@B@B@7.B@B@B:
,,@@BUB@B::;iriii:i@Bi.i@@Oi.BB@.,.@B@ @B@B@B@:ii;ii,@B@j@B@..X@B0B1v@@@B2:iirii:,B@2.E@@;B@@i:@@v @@@ @@@O7.
.B@@@B@@@r:iri;ii:7B@i:i@B.,:2@B5iuB@2.B@B80@U:irii:LB@B@B@B@..B@B@..B@@@.:i;i;ii.@B5.@B@@@@@B,B@..B@B.:uB@BU
7@B;...@B@:i:iiiiir@Br:;B@ii::B@B@B@B,,UB@B@B::iii::B@B...v@B7,BB@B,,@B@0::iiiii::B@F:,,..B@G.i@@:.@B@.@B@B@i
:i:::::::i::::::ii:ii:i:i::ii::,;7;,::i:,iL7::::::::;:::::::ri::::::i:::::i::,::::i:::i:i::::::ii:::::::LL:,,
::iii;ii::B@B@B@:iiiiiiiiiiri;ii:i:iiiiiii::::B@B@@@:iiiiiii:iii:iiiiiiiiir@B@B@Mi:iiiiri;iiiiiiiiiiiiii:i:i:

A_True_AW_14ns

挺难认的

gghdl

看函数存在VHPI,还有调用GHDI接口,搜索看不懂,但是动调可以发现就是把输入一一置换然后与常值比较

f = open("./ghdl.txt", "r").readlines() # ghdl为获取的数据
cmp = []
test = list(
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$ %&'()*+,-./:;<=>?@[\\]^_`{|}~0000000000000000000000000000000000000")
dic = {}
for i in range(0, len(f), 2):
# print(f[i], f[i+1])
inin = f[i].strip().split(' ')[1]
cmpcmp = f[i+1].strip().split(' ')[1]
cmp.append(cmpcmp)
dic[inin] = test[i // 2]
assert len(cmp) == len(test)
print(dic)
for i in range(len(cmp)):
val = cmp[i]
try:
print(dic[val], end='')
except:
print('?', end='')

WP看不懂这道也不怎么会,之后搞吧