mark一下,以后分析
原文:http://sibears.ru/labs/ASIS-CTF-Quals-2016-Leaked_License/
[ASIS CTF Quals 2016] - 泄露许可证[64]
我从朋友的朋友的老兄那里借了这个软件许可证和图书馆!如果我可以伪造今年竞争计算机ID的许可证,那就太好了。
我们获得了Leaked_Lisence.dll和文件[email protected]_license
Groke @ MacBook-Air-groke:〜/ ctf / asis / Leaked_Lisence $ cat admin \ @nsa.gov.us_license
7e43ecf0b4e27dacfb5e613437b17acb46e8deab2c70510dc71844b492a691ec
在dll中,导出一个验证方法,其参数占用48个字节。如果稍微查看一下该文件,可以看到源代码是C ++中的:
“ios_base :: eofbit set”
“ios_base :: failbit set”
“ios_base :: badbit set”
然后假设参数是std :: string。使用代码,我们恢复以下形式的字符串:
struct magic {
union {
char * s1 ; char s2 [ 16 ]; }; int size ; int real_length ; };
将此结构添加到id后,很明显验证函数按值接受2个这样的行。
实际上,算法本身如下(伪Python):
DEF 验证(ID , 许可证): 与 开放(“secret.key” ) 作为与 secret_file: 秘密 = secret_file 。read () checkString = sha256 (secret )。解码('hex' ) 而 len (id ) < 32 : id = id + id secretFromUser = “” license = license 。解码('hex' ) for x in xrange (32 ): secretFromUser + = chr (ord (id [ i ]) ^ ord (license [ i ])) check2 = sha256 (secretFromUser )。解码('hex' ) 如果 check2 。equal (checkString ): 返回 1 返回 0
显然,这足以让我们从此许可证中获取secretFromUser并在其基础上生成我们自己的许可证。有一个问题,因为不清楚许可证的ID是什么。有一种理论认为某处出现了错误,并且编写了以下文件以便用笔感觉:
#include“stdafx.h”
#include <iostream>
#include <string>
#include <Windows.h>
struct magic { union { char * s1 ; char s2 [ 16 ]; }; int size ; int real_length ; }; magic * get_my_magic (char * buf ){ struct magic * ret = (magic * )malloc (24 ); int ln = strlen (buf ); ret - > s1 = (char * )malloc (ln ); ret - > size = ln ; ret - > real_length = ln ; strncpy (ret - > s1 , buf , ln ); return语句 的RET ; } int main () { magic * id = get_my_magic (“[email protected]” ); magic * key = get_my_magic (“7e43ecf0b4e27dacfb5e613437b17acb46e8deab2c70510dc71844b492a691ec” ); auto hMod = LoadLibraryA (“Leaked_Lisence.dll” ); auto myFunc = (int (* )(magic , magic ))GetProcAddress (hMod , “verify” ); 汽车 s = myFunc (* id , * key ); std :: cout << s << std :: endl ; }
需要魔术结构,因为工作室中的sizeof(std :: string)<> 24
然而,实践表明理论计算是正确的,我们回到了id的搜索。尝试过“[email protected]”后,我们获得了以下许可证:
6e52e0f5a99023eeac30672828ec22db53ea9dab30414a1fca4511ebd5bea4fe
,结果就是flag: