September 22, 2022

DASCTF X CB-Landing && cbNET

又感觉好久没写WP了,以前总想着把每题的WP写了,但发现实在是太慢了,因为有点强迫症,要写就写详细,一句话带过不如不写,但为了节省时间就没有每个都写了。–9.22

Landing

0x00 Daily Shell Check

无壳64位

image-20220922163741052

0x01 Throw Catch

典型的抛异常Catch异常题目,首先是点进主函数,我们的输入经过异或0x22和+1的处理

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
int __cdecl main(int argc, const char **argv, const char **envp)
{
std::ostream *v3; // rax
std::ostream *v4; // rax
char input[32]; // [rsp+450h] [rbp+3D0h] BYREF
int i; // [rsp+48Ch] [rbp+40Ch]

_main(argc, argv, envp);
v3 = (std::ostream *)std::operator<<<std::char_traits<char>>(refptr__ZSt4cout, "Input something.");
refptr__ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(v3);
std::operator>><char,std::char_traits<char>>(refptr__ZSt3cin, input);
if ( strlen(input) == 28 )
{
for ( i = 0; i <= 27; ++i )
{
input[i] ^= 0x22u;
++input[i];
}
func1(input);
}
v4 = (std::ostream *)std::operator<<<std::char_traits<char>>(refptr__ZSt4cout, "nono");
refptr__ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(v4);
system("pause");
return 1;
}

随后点进func1再进func2,大大的一个throw的操作,那么我们找到catch块即可

于是在主函数的汇编页面找找就可以发现比较异常类型于处理

image-20220922164036982

0x02 GetFlag

那么这题知识点主要就是这个throw catch了,稍微跟了catch块或审一下可以知道是生成密文和base64 Input,然后比较

注意base64是有个+1的操作所以解密base前先-1

(解密的时候忘记最开始的时候还有个+1,于是又学了种base64的写法

GetFlag! Cyber yyds!

image-20220922164354374

cbNET

0x00 Daily Shell Check

Confuser壳加Dotfuscator混淆

image-20220922164528571

0x01 DeShell && Deobfuscation

梭了这个壳,还是第一次见这壳

image-20220922165208632

1
2
3
.\de4dot.exe -d C:\Users\Pz\Desktop\DAS9\cbNET-unpacked.exe // 检查壳类型

.\de4dot.exe "C:\Users\Pz\Desktop\DAS9\cbNET-unpacked.exe" // 直接脱壳

再拖进dnspy即可

0x02 Translate Program

由于去混淆的不是很完全,到处都是goto所以不是很好理解,最好的办法就是自己翻译一遍

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
def method_0(input):
text = "0rays"
flag = []
num = 0
for i in range(len(input)):
flag += input[i] ^ ord(text[num])
num = (num + 1) ^ 5


def method_1(n):
if n < 2:
return 0
else:
for i in range(2, n):
if (n % i == 0): # 说是不是质数
return 0
return 1


def method_2(input):
for i in range(0, len(input) - 7):
try:
input[i] = (input[i] ^ (input[i - 1] // (i % 8))) + (input[i - 1] % (i % 8)) # i = 0 或者是 i % 0 会导致异常
except:
input[i] = (input[i] ^ (input[i + 7] // 8)) + input[i + 7] % 8
print(i, end = ", ")

input[i] = input[i] - 2 - (input[i] % 2) # 减 2 或 3

for j in range(2, input[i] - 1): # num2 <= num3 所以是input[i] - 1取不到
if method_1(j) and method_1(input[i] - j) != 0:
input[i] = j * (input[i] - j)

input = [0] * 24
method_2(input)

0x03 GetFlag

用官解的递归爆破脚本

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
import hashlib


def isPrime(n):
if n < 2:
return 0
for i in range(2, n - 1):
if n % i == 0:
return 0
return 1


def xordecrypt(key):
str = "0rays"
circle = 0
flag = ""
for i in range(len(key)):
flag = flag + chr(key[i] ^ ord(str[circle]))
circle = (circle + 1) ^ 5
flag = "CBCTF{" + flag + "}"
t = hashlib.sha256()
t.update(flag.encode())
finalflag = t.hexdigest()
if finalflag == "15c4ac7645546a1ef8141441b48e1824954fdbb159bf96400061b17db1af9edf":
print(flag)
exit(0)


def recursion(key2, i):
key = key2.copy()
if (i % 8) != 0:
key[i] = (key[i] - key[i - 1] % (i % 8)) ^ (key[i - 1] // (i % 8))
else:
key[i] = (key[i] - key[i + 7] % 8) ^ (key[i + 7] // 8)
if i != 0:
decrypt(key, i - 1)
else:
xordecrypt(key)


def decrypt(key1, i):
key = key1.copy()
for j in range(2, key[i] - 1):
if key[i] % j == 0 and isPrime(j) and isPrime(key[i] // j): # key[i] % j == 0 因为指数相乘所以是肯定余数为0
key[i] = j + key[i] // j
break
key[i] = key[i] + 2 # 先 +2 测试偶数
recursion(key, i)
key[i] = key[i] + 1 # 如果上面没出flag那么就是奇数于是再 +1 相当于 +3
recursion(key, i)


key = [309, 1981, 2823, 6979, 28339, 39487, 33035, 283711, 623, 4109, 23551, 54761, 67985, 231149, 499603, 1354567, 213, 2651, 22559, 52549, 484663, 290793, 532213, 1746643]
decrypt(key, 23)

GetFlag!

image-20220922180541866

DASCTF X SU
🍬
HFCTF2022
🍪

About this Post

This post is written by P.Z, licensed under CC BY-NC 4.0.