0%

Nep欢乐个人赛-RE-hardsharp

(这道题也是本菜鸡在参加的所有CTF比赛中独立解决的第一道题,谨做纪念)

题目:
链接:https://pan.baidu.com/s/1ktDs3UPwUONpDKyIe0IlrQ
提取码:86n1
复制这段内容后打开百度网盘手机App,操作更方便哦;

查壳,C#编写的
在这里插入图片描述
dnSpy32打开, 定位到主函数
在这里插入图片描述

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
// hardcsharp.Program
// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
private static void Main(string[] args)
{
AesClass aesClass = new AesClass();
string text = "";
string strB = "1Umgm5LG6lNPyRCd0LktJhJtyBN7ivpq+EKGmTAcXUM+0ikYZL4h4QTHGqH/3Wh0";
byte[] array = new byte[]
{
81,
82,
87,
81,
82,
87,
68,
92,
94,
86,
93,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18,
18
};
Console.WriteLine("Welcome to nepnep csharp test! plz input the magical code:");
string text2 = Console.ReadLine();
if (text2.Length != 37)
{
Console.WriteLine("Nope!");
Console.ReadKey();
return;
}
if (text2.Substring(0, 4) != "Nep{" || text2[36] != '}')
{
Console.WriteLine("Nope!");
Console.ReadKey();
return;
}
for (int i = 0; i < 32; i++)
{
text += Convert.ToChar((int)(array[i] ^ 51)).ToString();
}
if (string.Compare(aesClass.AesEncrypt(text2, text), strB) == 0)
{
Console.WriteLine("wow, you pass it!");
Console.ReadKey();
return;
}
Console.WriteLine("Nope!");
Console.ReadKey();
}

由上面的代码,我们可以知道text是array[]和51异或后得到的结果,我们写个Python脚本求一下text

1
2
3
4
5
array = [81,82,87,81,82,87,68,92,94,86,93,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18]
text = ''
for i in range(len(array)):
text+=chr(array[i]^51)
print(text)

在这里插入图片描述
text=”badbadwomen!!!!!!!!!!!!!!!!!!!!!”
我们发现它将text和text2经过aesClass.AesEncrypt()处理之后和strB相比较,相等的话即正确
text2由代码可知是Nep{……},我们需要解出来的也就是这个
看一下aesClass.AesEncrypt()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// hardcsharp.AesClass
// Token: 0x06000004 RID: 4 RVA: 0x00002148 File Offset: 0x00000348
public string AesEncrypt(string str, string key)
{
if (string.IsNullOrEmpty(str))
{
return null;
}
byte[] bytes = Encoding.UTF8.GetBytes(str);
byte[] array = new RijndaelManaged
{
Key = Encoding.UTF8.GetBytes(key),
Mode = CipherMode.ECB,
Padding = PaddingMode.PKCS7
}.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
return Convert.ToBase64String(array, 0, array.Length);
}

普及一下:
CipherMode.ECB:AES加密解密(ECB模式)
PaddingMode.PKCS7:AES的一种填充模式
另外注意Base64和UTF-8

那这样就好办了
在线工具:AES解密
在这里插入图片描述
flag:Nep{up_up_down_down_B_a_b_A_Nep_nep~}