2025_Xuanyuan
1.ezre
exeinfo查看,UPX壳
010editor查看文件格式可发现其符合UPX壳的区段码,但是出题人把大写改成了小写
这样就可以upx-d了,然后IDA打开即可
可见sub_140001130就是加密函数
可以从这里直接看到字母表和密文,直接对着1130函数反写即可
获得flag{Y0u_@R3_Upx_4nd_b45364_m4st3r!}
2.你知道base么
64位无壳直接做
可见这个由两个部分组成,上半部分是tea加密,下半部分需要我们自行寻找base加密表
tea加密的逻辑都在 sub_7FF65715140B里面,点进去就可以看到
标准tea加密,直接写代码即可
#include <stdio.h>
#include <stdint.h>
void decrypt(uint32_t* v, uint32_t* key) {
uint32_t v4 = v[0];
uint32_t v5 = v[1];
uint32_t delta = 0x61C88647;
uint32_t v6 = -32 * delta;
for (int i = 0; i < 32; i++) {
uint32_t g_part = (key[3] + (v4 >> 5)) ^ (v6 + v4) ^ (key[2] + 16 * v4);
v5 -= g_part;
uint32_t f_part = (key[1] + (v5 >> 5)) ^ (v6 + v5) ^ (key[0] + 16 * v5);
v4 -= f_part;
v6 += delta;
}
v[0] = v4;
v[1] = v5;
}
int main() {
uint32_t cipher[2] = { 0xA92F3865, 0x9E60E953 };
uint32_t key[4] = { 0x12345678, 0x3456789A, 0x89ABCDEF, 0x12345678 };
decrypt(cipher, key);
unsigned char* flag = (unsigned char*)cipher;
printf("key1: ");
for (int i = 0; i < 8; i++) {
printf("%c", flag[i]);
}
printf("\n");
return 0;
}
得到一阶段密钥,然后就是寻找base64表的过程
然后就可以看到这段rc4加密的内容,由此我们可以得知上一步的y0uokTea同时也是rc4的密钥
了解了rc4的代码后直接写解密代码即可
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
uint8_t* rc4_keystream(const uint8_t* key_bytes, size_t key_len, size_t length) {
uint8_t* S = (uint8_t*)malloc(256 * sizeof(uint8_t));
for (int i = 0; i < 256; i++) {
S[i] = i;
}
int j = 0;
for (int i = 0; i < 256; i++) {
j = (j + S[i] + key_bytes[i % key_len]) % 256;
uint8_t tmp = S[i];
S[i] = S[j];
S[j] = tmp;
}
uint8_t* out = (uint8_t*)malloc(length * sizeof(uint8_t));
int i = 0;
j = 0;
for (size_t n = 0; n < length; n++) {
i = (i + 1) % 256;
j = (j + S[i]) % 256;
uint8_t tmp = S[i];
S[i] = S[j];
S[j] = tmp;
uint8_t t = (S[i] + S[j]) % 256;
out[n] = S[t];
}
return out;
}
uint8_t* base_decode(const uint8_t* cipher_bytes, size_t cipher_len, const uint8_t* table, size_t table_len, size_t* out_len) {
int* idxs = (int*)malloc(cipher_len * sizeof(int));
for (size_t i = 0; i < cipher_len; i++) {
for (int j = 0; j < table_len; j++) {
if (table[j] == cipher_bytes[i]) {
idxs[i] = j - 1;
break;
}
}
}
uint32_t bits = 0;
int bitlen = 0;
uint8_t* out = (uint8_t*)malloc(cipher_len * 5 / 8 + 1);
size_t out_pos = 0;
for (size_t i = 0; i < cipher_len; i++) {
bits = (bits << 5) | (idxs[i] & 0x1F);
bitlen += 5;
while (bitlen >= 8) {
bitlen -= 8;
out[out_pos++] = (bits >> bitlen) & 0xFF;
}
}
*out_len = out_pos;
return out;
}
int main() {
uint8_t key_bytes[8] = { 'y', '0', 'u', 'o', 'k', 'T', 'e', 'a' };
int8_t v21[] = { -44, 89, 35, 118, -76, -65, -29, 44, 88, -113, 86, 25, -38, -16, -64, -67,
54, 61, 123, 70, 27, -72, 23, 31, -29, -48, 3, 69, -51, 4, -19, -55,
103, -26, -85, 41, -89, -68, 11, -34, 92, 48, 113, -41, -43, 90, -58, -97,
64, 101, -60, 113, -87, -61, -82, -39, -75, -27, 18, -116, 0x80 };
size_t cipher2_len = sizeof(v21) / sizeof(v21[0]);
uint8_t* cipher2 = (uint8_t*)malloc(cipher2_len);
for (size_t i = 0; i < cipher2_len; i++) {
cipher2[i] = (uint8_t)v21[i];
}
uint8_t* ks = rc4_keystream(key_bytes, 8, cipher2_len);
uint8_t* table_bytes = (uint8_t*)malloc(cipher2_len);
for (size_t i = 0; i < cipher2_len; i++) {
table_bytes[i] = (cipher2[i] - ks[i]) & 0xFF;
}
const char* cipher3_str = "0tCPwtnncFZyYUlSK/4Cw0/echcG2lteBWnG2Ulw0htCYTMW";
size_t cipher3_len = strlen(cipher3_str);
uint8_t* cipher3 = (uint8_t*)cipher3_str;
size_t table_len = cipher2_len;
size_t flag_len;
uint8_t* flag = base_decode(cipher3, cipher3_len, table_bytes, table_len, &flag_len);
printf("flag = %.*s\n", (int)flag_len, flag);
return 0;
}




