攻防世界 reverse 进阶 8-The_Maya_Society Hack.lu-2017
8.The_Maya_Society Hack.lu-2017
在linux下将时间调整为2012-12-21,运行即可得到flag。
下面进行分析
1 signed __int64 __fastcall main(__int64 a1, char **a2, char **a3) 2 { 3 size_t v3; // rbx 4 size_t v4; // rax 5 unsigned __int64 size; // rax 6 unsigned __int64 size_1; // rax 7 __int64 v8; // rsi 8 char *v9; // rdi 9 time_t timer; // [rsp+18h] [rbp-128h] 10 char str[8]; // [rsp+20h] [rbp-120h] 11 char md5_str; // [rsp+40h] [rbp-100h] 12 char time_s; // [rsp+60h] [rbp-E0h] 13 __int64 d1_dest; // [rsp+C8h] [rbp-78h] 14 char v15; // [rsp+D4h] [rbp-6Ch] 15 char v16; // [rsp+DDh] [rbp-63h] 16 char v17; // [rsp+E6h] [rbp-5Ah] 17 char v18; // [rsp+EFh] [rbp-51h] 18 char *sign_1; // [rsp+F8h] [rbp-48h] 19 char *sign; // [rsp+100h] [rbp-40h] 20 char *s1_src; // [rsp+108h] [rbp-38h] 21 char *dest; // [rsp+110h] [rbp-30h] 22 int *v23; // [rsp+118h] [rbp-28h] 23 size_t len_time_s; // [rsp+120h] [rbp-20h] 24 struct tm *tp; // [rsp+128h] [rbp-18h] 25 26 strcpy(str, ".fluxfingers.net"); 27 timer = time(0LL); 28 tp = localtime(&timer); 29 strftime(&time_s, 0x63uLL, "%Y-%m-%d", tp); 30 len_time_s = strlen(&time_s); 31 md5_B5A(&time_s, len_time_s); 32 v23 = &dword_5566589760B8; // 下面主要进行MD5算法中的A、B、C、D连接 33 snprintf( 34 &v18, 35 9uLL, 36 "%02x%02x%02x%02x", 37 (unsigned __int8)dword_5566589760B8, 38 BYTE1(dword_5566589760B8), 39 BYTE2(dword_5566589760B8), 40 HIBYTE(dword_5566589760B8)); 41 v23 = &dword_5566589760C0; 42 snprintf( 43 &v17, 44 9uLL, 45 "%02x%02x%02x%02x", 46 (unsigned __int8)dword_5566589760C0, 47 BYTE1(dword_5566589760C0), 48 BYTE2(dword_5566589760C0), 49 HIBYTE(dword_5566589760C0)); 50 v23 = &dword_5566589760B4; 51 snprintf( 52 &v16, 53 9uLL, 54 "%02x%02x%02x%02x", 55 (unsigned __int8)dword_5566589760B4, 56 BYTE1(dword_5566589760B4), 57 BYTE2(dword_5566589760B4), 58 HIBYTE(dword_5566589760B4)); 59 v23 = &dword_5566589760BC; 60 snprintf( 61 &v15, 62 9uLL, 63 "%02x%02x%02x%02x", 64 (unsigned __int8)dword_5566589760BC, 65 BYTE1(dword_5566589760BC), 66 BYTE2(dword_5566589760BC), 67 HIBYTE(dword_5566589760BC)); 68 snprintf(&md5_str, 0x21uLL, "%s%s%s%s", &v18, &v17, &v16, &v15); 69 v3 = strlen(&md5_str); 70 v4 = strlen(str); 71 dest = (char *)malloc(v3 + v4 + 1); 72 if ( !dest ) 73 return 1LL; 74 *dest = 0; 75 strcat(dest, &md5_str); 76 strcat(dest, str); // 时间md5 + .fluxfingers.net 77 // a0ab7eafc534bc4a8a48cd6e1cfc4d24.fluxfingers.net 78 s1_src = sub_5566587748A4(dest); // 关键处 79 if ( !s1_src ) 80 return 1LL; 81 size = strlen(s1_src); 82 sign = base64_15E0((__int64)s1_src, size, &d1_dest); 83 size_1 = strlen(s1_src); 84 sign_1 = base64_15E0((__int64)s1_src, size_1, &d1_dest); 85 if ( !sign ) 86 return 1LL; 87 v8 = d1_dest; 88 v9 = sign; 89 sub_556658774858(sign, d1_dest, sign_1); // ^0x25 90 ((void (__fastcall *)(char *, __int64))sign_1)(v9, v8);// flag{e3a03c6f3fe91b40eaa8e71b41f0db12} 91 // 92 return 0LL; 93 }
获取本地时间-->将时间MD5加密-->结果连接字符串.fluxfingers.net-->进入sub_5566587748A4(dest)
1 char *__fastcall sub_5566587748A4(const char *dname) 2 { 3 char *index_head; // rax 4 ns_rr rr; // [rsp+10h] [rbp-24A0h] 5 ns_msg handle; // [rsp+430h] [rbp-2080h] 6 char s; // [rsp+480h] [rbp-2030h] 7 u_char answer; // [rsp+1480h] [rbp-1030h] 8 char *dest; // [rsp+2488h] [rbp-28h] 9 size_t n; // [rsp+2490h] [rbp-20h] 10 char *index_tail; // [rsp+2498h] [rbp-18h] 11 char *src; // [rsp+24A0h] [rbp-10h] 12 int msg; // [rsp+24ACh] [rbp-4h] 13 14 msg = __res_query(dname, 1, 16, &answer, 4096);// int res_query(const char *dname, int class, int type,unsigned char *answer,int anslen) 15 // 查询名称服务器,以获得指定类型和类的完全限定域名。应答保留在调用方提供的anslen长度的缓冲区应答中 16 if ( msg < 0 ) 17 return 0LL; 18 ns_initparse(&answer, msg, &handle); // int ns_initparse(const u_char *msg, int msglen, ns_msg *handle) 19 // 在使用其他名称服务器库例程之前必须调用的第一个例程。nitparse填充句柄指向的数据结构,该句柄是传递给其他例程的参数 20 msg = handle._counts[1]; 21 ns_parserr(&handle, ns_s_an, 0, &rr); // int ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) 22 // 提取关于响应记录的信息并将其存储在rr中,rr是传递给其他名称服务器库例程的参数 23 ns_sprintrr(&handle, &rr, 0LL, 0LL, &s, 0x1000uLL);// int ns_sprintrr(const ns_msg *handle, const ns_rr *rr, const char *name_ctx, const char *origin, char *buf, size_t buflen) 24 // 将rr转换为表示格式 25 index_head = strchr(&s, '"'); 26 src = index_head + 1; 27 if ( index_head == (char *)-1LL ) 28 return 0LL; 29 index_tail = strchr(src, '"'); 30 if ( !index_tail ) 31 return 0LL; 32 n = index_tail - src; 33 dest = (char *)malloc(index_tail - src + 1); 34 strncpy(dest, src, n); 35 dest[n] = 0; 36 return dest; // zgJDSURCXkAWRBUWRhNDFkNAHBRHERVAREQdQBIURxEUQxVBRxQXWC+dJCUlJZokJSUlbagQ7dra2p8CJSUlKiCdGSUlJZolJSUlKiA= 37 }
只有传入正确的参数(MD5(2012-12-21)+".fluxfingers.net"),才会返回正确结果,这题主要还是考查对细节信息的敏感度,题目充斥着“世界末日”,联系时间,自然想到2012-12-21
算法方面没有难度,
关键函数返回处理结果-->进行base64解码-->异或0x25
1 import base64 2 msg='zgJDSURCXkAWRBUWRhNDFkNAHBRHERVAREQdQBIURxEUQxVBRxQXWC+dJCUlJZokJSUlbagQ7dra2p8CJSUlKiCdGSUlJZolJSUlKiA=' 3 b=base64.b64decode(msg) 4 # print(b) 5 s='' 6 for i in range(len(b)): 7 t=b[i]^0x25 8 print(t,end=' ') 9 s+=chr(t) 10 print() 11 print(s)
输出:
235 39 102 108 97 103 123 101 51 97 48 51 99 54 102 51 102 101 57 49 98 52 48 101 97 97 56 101 55 49 98 52 49 102 48 100 98 49 50 125 10 184 1 0 0 0 191 1 0 0 0 72 141 53 200 255 255 255 186 39 0 0 0 15 5 184 60 0 0 0 191 0 0 0 0 15 5
ë'flag{e3a03c6f3fe91b40eaa8e71b41f0db12}
¸ ¿ H5Èÿÿÿº' ¸< ¿