如何使用WFH搜索Windows可执行程序中的常见漏洞或功能

安全 网站安全
WFH可以输出潜在的安全漏洞,并将目标Windows可执行文件中的潜在漏洞相关信息写入至CSV文件中。

关于WFH

WFH,全名为Windows Feature Hunter,即Windows功能搜索工具,该工具基于Python开发,使用Frida实现其功能,可以帮助广大研究人员搜索和识别Windows可执行程序中的常见安全漏洞以及功能。当前版本的WFH能够自动识别动态链接库DLL中潜在的侧加载问题以及组件对象模型COM中劫持攻击的实现可能。

DLL侧加载利用勒Windows中WinSXS程序集来从SXS列表中加载恶意DLL文件。COM劫持将允许攻击者置入恶意代码,而这些代码将能够通过劫持COM引用和关系代替合法软件的执行。

WFH可以输出潜在的安全漏洞,并将目标Windows可执行文件中的潜在漏洞相关信息写入至CSV文件中。

工具安装

首先, 广大研究人员需要使用下列命令将该项目源码克隆至本地:

  1. git clone https://github.com/ConsciousHacker/WFH 

然后运行下列命令安装和配置相关依赖组件:

  1. pip install -r requirements.txt 

工具帮助信息

  1. PS C:\Tools\WFH > python .\wfh.py -h 
  2.  
  3. usage: wfh.py [-h] -t T [T ...] -m {dll,com} [-v] [-timeout TIMEOUT] 
  4.  
  5.   
  6.  
  7. Windows Feature Hunter 
  8.  
  9.   
  10.  
  11. optional arguments: 
  12.  
  13.   -h, --help            show this help message and exit 
  14.  
  15.   -t T [T ...], -targets T [T ...] 
  16.  
  17.                         list of target windows executables 
  18.  
  19.   -m {dll,com}, -mode {dll,com} 
  20.  
  21.                         vulnerabilities to potentially identify 
  22.  
  23.   -v, -verbose          verbose output from Frida instrumentation 
  24.  
  25.   -timeout TIMEOUT      timeout value for Frida instrumentation 
  26.  
  27.   
  28.  
  29. EXAMPLE USAGE 
  30.  
  31.     NOTE: It is recommended to copy target binaries to the same directory as wfh for identifying DLL Sideloading 
  32.  
  33.   
  34.  
  35.     DLL Sideloading Identification (Single):        python wfh.py -t .\mspaint.exe -m dll 
  36.  
  37.     DLL Sideloading Identification (Verbose):       python wfh.py -t .\mspaint.exe -m dll -v 
  38.  
  39.     DLL Sideloading Identification (Timeout 30s):   python wfh.py -t .\mspaint.exe -m dll -timeout 30 
  40.  
  41.     DLL Sideloading Identification (Wildcard):      python wfh.py -t * -m dll 
  42.  
  43.     DLL Sideloading Identification (List):          python wfh.py -t .\mspaint.exe .\charmap.exe -m dll 
  44.  
  45.   
  46.  
  47.     COM Hijacking Identification (Single):          python wfh.py -t "C:\Program Files\Internet Explorer\iexplore.exe" -m com 
  48.  
  49.     COM Hijacking Identification (Verbose):         python wfh.py -t "C:\Program Files\Internet Explorer\iexplore.exe" -m com -v 
  50.  
  51.     COM Hijacking Identification (Timeout 60s):     python wfh.py -t "C:\Program Files\Internet Explorer\iexplore.exe" -m com -timeout 60 
  52.  
  53.     COM Hijacking Identification (Wildcard):        python wfh.py -t * -m com -v 
  54.  
  55. COM Hijacking Identification (List):            python wfh.py -t "C:\Program Files\Internet Explorer\iexplore.exe" "C:\Windows\System32\notepad.exe" -m com -v 

工具使用

(1) DLL侧加载识别

首先,我们需要将需要分析的代码拷贝至WFH工具所在的目录下,然后按照下列命令执行扫描分析:

  1. PS C:\Tools\WFH > copy C:\Windows\System32\mspaint.exe . 
  2.  
  3. PS C:\Tools\WFH > copy C:\Windows\System32\charmap.exe . 
  4.  
  5. PS C:\Tools\WFH > dir 
  6.  
  7.   
  8.  
  9.   
  10.  
  11.     Directory: C:\Tools\WFH 
  12.  
  13.   
  14.  
  15.   
  16.  
  17. Mode                 LastWriteTime         Length Name 
  18.  
  19. ----                 -------------         ------ ---- 
  20.  
  21. d-----         5/14/2021   2:12 PM                .vscode 
  22.  
  23. -a----          5/6/2021   2:39 PM           1928 .gitignore 
  24.  
  25. -a----         12/7/2019   2:09 AM         198656 charmap.exe 
  26.  
  27. -a----         5/18/2021   7:39 AM           6603 loadlibrary.js 
  28.  
  29. -a----          4/7/2021  12:48 PM         988160 mspaint.exe 
  30.  
  31. -a----         5/18/2021   7:53 AM           8705 README.md 
  32.  
  33. -a----         5/17/2021  11:27 AM           5948 registry.js 
  34.  
  35. -a----          5/6/2021   2:41 PM             11 requirements.txt 
  36.  
  37. -a----         5/18/2021   8:35 AM          10623 wfh.py 

接下来,我们就可以使用WFH来对目标代码进行分析,并尝试识别其中的DLL侧加载机会:

  1. PS C:\Tools\WFH > python .\wfh.py -t * -m dll 
  2.  
  3. ================================================== 
  4.  
  5. Running Frida against charmap.exe 
  6.  
  7. -------------------------------------------------- 
  8.  
  9.         [+] Potential DllMain Sideloading: LoadLibraryW,LPCWSTR: MSFTEDIT.DLL 
  10.  
  11.         [+] Potential DllMain Sideloading: LoadLibraryExW,LPCWSTR : MSFTEDIT.DLL, dwFlags : NONE 
  12.  
  13.   
  14.  
  15. [*] Writing raw Frida instrumentation to charmap.exe-raw.log 
  16.  
  17. [*] Writing Potential DLL Sideloading to charmap.exe-sideload.log 
  18.  
  19. -------------------------------------------------- 
  20.  
  21. ================================================== 
  22.  
  23. Running Frida against mspaint.exe 
  24.  
  25. -------------------------------------------------- 
  26.  
  27.         [+] Potential DllMain Sideloading: LoadLibraryExW,LPCWSTR : gdiplus.dll, dwFlags : NONE 
  28.  
  29.         [-] Potential DllExport Sideloading: GetProcAddress,hModule : C:\WINDOWS\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.19041.789_none_faf0a7e97612e7bb\gdiplus.dll, LPCSTR: GdiplusStartup 
  30.  
  31.         [+] Potential DllMain Sideloading: LoadLibraryW,LPCWSTR: MSFTEDIT.DLL 
  32.  
  33.         [+] Potential DllMain Sideloading: LoadLibraryExW,LPCWSTR : MSFTEDIT.DLL, dwFlags : NONE 
  34.  
  35.   
  36.  
  37. [*] Writing raw Frida instrumentation to mspaint.exe-raw.log 
  38.  
  39. [*] Writing Potential DLL Sideloading to mspaint.exe-sideload.log 
  40.  
  41. -------------------------------------------------- 
  42.  
  43. ================================================== 
  44.  
  45. [*] Writing dll results to dll_results.csv 
  46.  
  47.   
  48.  
  49. PS C:\Tools\WFH > type .\dll_results.csv 
  50.  
  51. Executable,WinAPI,DLL,EntryPoint / WinAPI Args 
  52.  
  53. charmap.exe,LoadLibraryW,LPCWSTR: MSFTEDIT.DLL 
  54.  
  55. charmap.exe,LoadLibraryExW,LPCWSTR : MSFTEDIT.DLL, dwFlags : NONE 
  56.  
  57. mspaint.exe,LoadLibraryExW,LPCWSTR : gdiplus.dll, dwFlags : NONE 
  58.  
  59. mspaint.exe,GetProcAddress,hModule : C:\WINDOWS\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.19041.789_none_faf0a7e97612e7bb\gdiplus.dll, LPCSTR: GdiplusStartup 
  60.  
  61. mspaint.exe,LoadLibraryW,LPCWSTR: MSFTEDIT.DLL 
  62.  
  63. mspaint.exe,LoadLibraryExW,LPCWSTR : MSFTEDIT.DLL, dwFlags : NONE 

如果你想让WFH输出更多详细内容,可以使用“-v”参数开启Verbose模式。此时将能够查看Windows API调用的详细情况:

  1. PS C:\Tools\WFH > python .\wfh.py -t * -m dll -v 
  2.  
  3. ================================================== 
  4.  
  5. Running Frida against charmap.exe 
  6.  
  7. {'type': 'send', 'payload': 'LoadLibraryW,LPCWSTR: MSFTEDIT.DLL'} 
  8.  
  9. {'type': 'send', 'payload': 'LoadLibraryExW,LPCWSTR : MSFTEDIT.DLL, dwFlags : NONE'} 
  10.  
  11. -------------------------------------------------- 
  12.  
  13.         [+] Potential DllMain Sideloading: LoadLibraryW,LPCWSTR: MSFTEDIT.DLL 
  14.  
  15.         [+] Potential DllMain Sideloading: LoadLibraryExW,LPCWSTR : MSFTEDIT.DLL, dwFlags : NONE 
  16.  
  17.   
  18.  
  19. [*] Writing raw Frida instrumentation to charmap.exe-raw.log 
  20.  
  21. [*] Writing Potential DLL Sideloading to charmap.exe-sideload.log 
  22.  
  23. -------------------------------------------------- 
  24.  
  25. ================================================== 
  26.  
  27. Running Frida against mspaint.exe 
  28.  
  29. {'type': 'send', 'payload': 'LoadLibraryExW,LPCWSTR : gdiplus.dll, dwFlags : NONE'} 
  30.  
  31. {'type': 'send', 'payload': 'GetProcAddress,hModule : C:\\WINDOWS\\WinSxS\\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.19041.789_none_faf0a7e97612e7bb\\gdiplus.dll, LPCSTR: GdiplusStartup'} 
  32.  
  33. {'type': 'send', 'payload': 'LoadLibraryW,LPCWSTR: MSFTEDIT.DLL'} 
  34.  
  35. {'type': 'send', 'payload': 'LoadLibraryExW,LPCWSTR : MSFTEDIT.DLL, dwFlags : NONE'} 
  36.  
  37. -------------------------------------------------- 
  38.  
  39.         [+] Potential DllMain Sideloading: LoadLibraryExW,LPCWSTR : gdiplus.dll, dwFlags : NONE 
  40.  
  41.         [-] Potential DllExport Sideloading: GetProcAddress,hModule : C:\WINDOWS\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.19041.789_none_faf0a7e97612e7bb\gdiplus.dll, LPCSTR: GdiplusStartup 
  42.  
  43.         [+] Potential DllMain Sideloading: LoadLibraryW,LPCWSTR: MSFTEDIT.DLL 
  44.  
  45.         [+] Potential DllMain Sideloading: LoadLibraryExW,LPCWSTR : MSFTEDIT.DLL, dwFlags : NONE 
  46.  
  47.   
  48.  
  49. [*] Writing raw Frida instrumentation to mspaint.exe-raw.log 
  50.  
  51. [*] Writing Potential DLL Sideloading to mspaint.exe-sideload.log 
  52.  
  53. -------------------------------------------------- 
  54.  
  55. ================================================== 
  56.  
  57. [*] Writing dll results to dll_results.csv 

(2) COM劫持识别

  1. PS C:\Tools\WFH > python .\wfh.py -t "C:\Program Files\Internet Explorer\iexplore.exe" -m com 
  2.  
  3. ================================================== 
  4.  
  5. Running Frida against C:\Program Files\Internet Explorer\iexplore.exe 
  6.  
  7. -------------------------------------------------- 
  8.  
  9.         [+] Potential COM Hijack: Path : HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{0E5AAE11-A475-4C5B-AB00-C66DE400274E}\InProcServer*32,lpValueName : null,Type : REG_EXPAND_SZ, Value : %SystemRoot%\system32\Windows.Storage.dll 
  10.  
  11.         [+] Potential COM Hijack: Path : HKEY_CLASSES_ROOT\CLSID\{1FD49718-1D00-4B19-AF5F-070AF6D5D54C}\InProcServer*32,lpValueName : null,Type : REG_SZ, Value : C:\Program Files (x86)\Microsoft\Edge\Application\90.0.818.62\BHO\ie_to_edge_bho_64.dll 
  12.  
  13.   
  14.  
  15. [*] Writing raw Frida instrumentation to .\iexplore.exe-raw.log 
  16.  
  17. [*] Writing Potential COM Hijack to .\iexplore.exe-comhijack.log 
  18.  
  19. -------------------------------------------------- 
  20.  
  21. ================================================== 
  22.  
  23. [*] Writing dll results to comhijack_results.csv 

工具使用样例

(1) 原生Windows签名代码

将所有的原生Windows签名代码拷贝至WFH脚本所在目录:

  1. Get-ChildItem c:\ -File | ForEach-Object { if($_ -match '.+?exe$') {Get-AuthenticodeSignature $_.fullname} } | where {$_.IsOSBinary} | ForEach-Object {Copy-Item $_.path . } 

(2) 搜索DLL侧加载机会

  1. python wfh.py -t * -m dll 

(3) 搜索COM劫持机会

  1. python wfh.py -t * -m com 

项目地址

WFH:【GitHub传送门

 

责任编辑:赵宁宁 来源: FreeBuf
相关推荐

2010-03-23 10:29:28

Python程序编译转

2010-03-26 14:49:04

Python脚本

2022-06-17 07:57:53

拦截包装软链接

2009-09-04 09:36:17

Java调用

2024-03-08 09:34:35

JpackageJarJava

2013-03-18 09:48:05

微软Windows Blu

2019-08-23 17:33:02

WindowsWindows 10电脑

2018-10-29 10:13:29

Windows 10应用程序卸载

2022-01-11 09:59:23

Python关机程序文件

2021-12-26 07:43:50

aDLLDLL漏洞

2019-05-29 18:35:04

Windows 10Office 365应用程序

2018-12-21 19:30:28

Windows 10Windows管理员身份

2021-10-08 10:05:31

DorkifyGoogle Dork漏洞

2022-02-04 22:05:19

JVM程序内存模型

2010-10-13 13:46:10

2021-09-29 13:24:50

恶意文件Windows加载器

2023-11-06 14:21:43

2011-08-17 15:39:16

Windows7管理员身份运行程序

2010-02-24 15:41:53

Python解释器

2021-02-07 10:22:06

Windows 10Windows微软
点赞
收藏

51CTO技术栈公众号