Jake KingSamir Bousseaden

使用 Elastic Security 检测 CVE- 2021- 44228 (Log4j2) 漏洞的利用

本博客文章提供了 CVE-2021-44228 的摘要,并为 Elastic Security 用户提供了检测方法,以在其环境中查找该漏洞的活跃利用。当我们了解更多信息时,将在此帖子中提供进一步的更新。

14 分钟阅读安全研究, 漏洞更新
Detecting Exploitation of CVE-2021-44228 (Log4j2) with Elastic Security
  • 要了解 Elastic 当前如何评估我们产品中此漏洞的内部风险,请参阅此处的公告。
  • 自最初发布以来,本博客已更新(2021 年 12 月 17 日),包含进一步的检测和搜索改进。

概述

本博客文章提供了 CVE-2021-44228 的摘要,并为 Elastic Security 用户提供了检测方法,以在其环境中查找该漏洞的活跃利用。

当我们了解更多信息时,将在此帖子中提供进一步的更新。此版本截至 2021 年 12 月 14 日星期二为止准确。可以经由 Log4j2 的 安全页面直接调查 Apache 的更新。

CVE-2021-44228 (Log4Shell) 摘要

Log4j2 是一个开源日志记录框架,它被整合到最终用户系统和服务器上的许多基于 Java 的应用程序中。在 2021 年 11 月下旬,阿里巴巴的 Chen Zhaojun 发现了一个远程代码执行漏洞,该漏洞最终在 CVE ID 下报告:CVE-2021-44228,于 2021 年 12 月 10 日向公众发布。该漏洞通过不正确地反序列化传递到框架中的用户输入来利用。它允许远程代码执行,并且可以允许攻击者泄漏敏感数据(例如环境变量),或在目标系统上执行恶意软件。

已发现的漏洞会影响从 2.0-beta9 到 2.14.1 的所有 Log4j2 版本。早期修补此问题的方法导致了许多候选版本,最终建议在发布此帖子时将框架升级到 Log4j2 2.15.0-rc2。

考虑到微不足道的复杂性和观察到的广泛利用的性质,在任何已确定利用 Log4j2 易受攻击版本的软件的环境中,都应考虑进行缓解至关重要。

在 Elastic Security 中检测 Log4Shell 漏洞的利用

Elastic Security 用户可以使用以下事件关联检测规则来识别 Log4j2 漏洞的活跃利用。根据基于主机的事件数据的格式,您可能需要修改此检测以匹配您的数据字段。

使用端点数据时的检测规则

sequence by host.id with maxspan=1m
 [network where event.action == "connection_attempted" and
  process.name : "java" and
  /*
     outbound connection attempt to
     LDAP, RMI or DNS standard ports
     by JAVA process
   */
  destination.port in (1389, 389, 1099, 53, 5353)] by process.pid
 [process where event.type == "start" and

  /* Suspicious JAVA child process */
  process.parent.name : "java" and
   process.name : ("sh",
                   "bash",
                   "dash",
                   "ksh",
                   "tcsh",
                   "zsh",
                   "curl",
                   "perl*",
                   "python*",
                   "ruby*",
                   "php*",
                   "wget")] by process.parent.pid

使用 Auditbeat 数据时的检测规则

sequence by agent.id with maxspan=1m
 [network where event.action == "connected-to" and
  process.name : "java" and
  /*
     outbound connection attempt to
     LDAP, RMI or DNS standard ports
     by JAVA process
   */
  destination.port in (1389, 389, 1099, 53, 5353)] by process.pid
 [process where event.type == "start" and

  /* Suspicious JAVA child process */
  process.parent.name : "java" and
   process.name : ("sh",
                   "bash",
                   "dash",
                   "ksh",
                   "tcsh",
                   "zsh",
                   "curl",
                   "perl*",
                   "python*",
                   "ruby*",
                   "php*",
                   "wget")] by process.parent.pid

使用 Endgame 流式事件时的检测规则

sequence by agent.id with maxspan=1m
 [network where event.category == "network" and
  process.name : "java" and
  /*
     outbound connection attempt to
     LDAP, RMI or DNS standard ports
     by JAVA process
   */
  destination.port in (1389, 389, 1099, 53, 5353)] by process.pid
 [process where event.type == "start" and

  /* Suspicious JAVA child process */
  process.parent.name : "java" and
   process.name : ("sh",
                   "bash",
                   "dash",
                   "ksh",
                   "tcsh",
                   "zsh",
                   "curl",
                   "perl*",
                   "python*",
                   "ruby*",
                   "php*",
                   "wget")] by process.parent.pid

此检测规则查找 LDAP、RMI 和 DNS 标准端口的出站连接尝试序列(通常通过最近观察到的 JAVA/JNDI 注入攻击滥用),然后是同一 Java 进程实例的子进程。

现在,让我们演示一下此规则如何检测 log42j 漏洞的利用

上面的屏幕截图显示了攻击者利用漏洞,使用 base-64 编码的有效负载,目标是由 Christophe Tafani-Dereeper 创建的示例易受攻击的应用程序

此屏幕截图显示了在 Elastic Security 中检测到 CVE-2021-44228 的活跃利用,其中详细说明了漏洞利用的警报和时间线视图。

上面的屏幕截图显示,在对检测警报的调查中,Java 执行了一个 shell 脚本来下载并运行 bash 脚本。

更新:检测和搜索改进

通过 Java 执行可疑的 Shell 命令

基于通过 log4j 漏洞利用提供的公开已知的恶意 Java 类,您可以搜索可疑的 shell 脚本和入口工具传输命令

process where event.type == "start" and
  process.parent.name : "java*" and

  /* Ingress tools transfer via common shell command interpreters */

  /* linux or macos */
  (
   (process.name : ("sh", "bash", "python*") and
    process.command_line : ("*curl*|*sh*", "*wget*|*bash", "*curl*|*bash*", "*curl*|*bash*", "*http*|*sh*", "*python*http*")) or

  /* windows */
  (process.name : ("powershell.exe", "pwsh.exe", "cmd.exe") and
   process.command_line : ("*.downloadstring*", "*.downloadfile*", "*.downloaddata*", "*BitsTransfer*", "* -enc*", "* IEX*", "*wp-content*", "*wp-admin*", "*wp-includes*", "*$*$*$*$*$*", "*^*^*^*^*^*^*^*^*^*", "*.replace*", "*start-process*", "*http*", "*cmd*powershell*")))

通过 JAVA 执行不受信任的文件

标识何时 JAVA 解释器创建可执行文件 (PE/ELF) 并且随后执行该文件。

使用端点数据时的检测规则

sequence by host.id with maxspan=5m
 [ file where event.type != "deletion" and
  process.name : ("java", "java.exe", "javaw.exe") and

  (file.extension : ("exe", "com", "pif", "scr") or
      /* Match Windows PE files by header data (MZ) */
  file.Ext.header_bytes : ("4d5a*", "7f454c46*")) and

  not file.path :  ("?:\\Program Files\\*",
                    "?:\\Program Files (x86)\\*") ] by file.path
 [ process where event.type == "start" and
  not process.code_signature.trusted == true ] by process.executable

使用 Endgame 流式事件时的检测规则

sequence by agent.id with maxspan=5m
  [ file where event.type != "deletion"
    process.name : ("java", "java.exe", "javaw.exe")] by file_path
  [ process where event.type == "start" and
  not process.code_signature.trusted == true] by process_path

潜在的 CoinMiner 活动

具有加密货币矿工常用命令行的进程(大多数观察到的利用 log4j 漏洞的活动是 coinminer)

process where event.type == "start" and
 process.command_line :
       ("* pool.*", "*-u*--coin*", "*.xmr.*", "*.xmr1.*",
        "*stratum*", "*elitter.net*", "*cryptonight*",
        "*-a scrypt*", "*stratum1*", "*-userpass*", "*-max-cpu-usage*",
	  "*qhor.net*", "*-wallet*pool*", "*--donate-level*", "*supportxmr.com*")

其他相关的利用后检测

尝试禁用 IPTables 或防火墙

篡改 Bash 命令行历史记录

系统日志文件删除

通过终端的潜在反向 Shell 活动

可疑的 JAVA 子进程

尝试禁用 Syslog 服务

Elastic Endgame EQL 查询

可疑的 Java Netcon,然后是异常子进程

sequence with maxspan=5s
 [network where process_name == "java*" and destination_port in (1389, 389, 1099, 53, 5353) and
  destination_address != "127.0.0.1" and not destination_address == "::1"] by pid
 [process where opcode in (1,5) and
  /* Suspicious JAVA child process */
  parent_process_name == "java*" and
   process_name in ("sh", "bash", "dash", "ksh", "tcsh", "zsh", "curl", "perl*", "python*", "ruby*", "php*", "wget", "powershell.exe", "cmd.exe")] by ppid

通过 Java 执行可疑的 Shell 命令

process where opcode in (1,5) and
  parent_process_name == "java*" and
  /* Ingress tools transfer via common shell command interpreters */

  /* linux or macos */
 (
  (process_name in ("sh", "bash", "python") and
   wildcard(command_line, "*curl*|*sh*", "*wget*|*bash", "*curl*|*bash*", "*curl*|*bash*", "*http*|*sh*", "*python*http*")) or
  /* windows */
  (process_name in ("powershell.exe", "pwsh.exe", "cmd.exe") and
   wildcard(command_line,"*.downloadstring*", "*.downloadfile*", "*.downloaddata*", "*BitsTransfer*", "* -enc*", "* IEX*", "*wp-content*", "*wp-admin*", "*wp-includes*", "*$*$*$*$*$*", "*^*^*^*^*^*^*^*^*^*","*.replace*", "*start-process*", "*http*", "*cmd*powershell*")))

常见的 Coin Miner 作为 JAVA 的后代

process where opcode in (1, 3, 4, 5) and
 descendant of [process where opcode in (1, 3, 4, 5) and process_name == "java*"] and
 wildcard(command_line, "* pool.*", "*-u*--coin*", "*.xmr.*", "*.xmr1.*", "*stratum*", "*elitter.net*", "*cryptonight*", "*-a scrypt*", "*stratum1*",
"*-userpass*", "*-max-cpu-usage*", "*qhor.net*", "*-wallet*pool*",  "*--donate-level*", "*supportxmr.com*",
/* evasion commands */
"*base64*", "*history -c*", "*ld.so.preload*", "*nmi_watchdog*", "*ufw*disable*", "*.bash_history*", "*chmod*+x*",
"*tor2web*", "*kill*-9*", "*python*-c*http*")

通过 JAVA 执行不受信任的文件

sequence with maxspan=2m
  [ file where opcode != 2 and file_name == "*.exe" and process_name == "java*"] by file_path
  [ process where opcode in (1,5)] by process_path

社区检测

许多社区成员讨论了该漏洞的广泛利用,并提供了许多早期检测方法的见解,分析师可以利用这些方法来确定他们正在使用的系统是否已被利用或处于活跃利用之下

其他缓解策略

除了 Apache 团队关于部署最新的修补版 Log4j2 框架以进行更新的建议指导之外,还广泛提出了许多缓解措施以防止漏洞利用

  • Fastly 建议检查您的 Log4j 版本是否支持使用 JAVA_OPTS=-Dlog4j2.formatMsgNoLookups=true 执行 JVM,以禁用到远程服务器的查找功能。这应适用于 2.10.0 到 2.15.0 版本。

  • 为了防止从易受攻击的主机横向移动或通过网络进行利用,建议限制可能易受攻击的系统与外部资源的连接,使其仅限于受信任的应用程序和/或服务。

感谢您,来自 Elastic Security。

我们要感谢全球所有安全团队今天和整个周末的辛勤工作,尤其是本帖中列出的那些团队。面对如此严重和普遍的漏洞,安全社区的开放与协作对于保护所有用户至关重要。我们希望您知道,我们将与您同在每一步。

现有的 Elastic Security 可以在产品内访问这些功能。如果您是 Elastic Security 的新手,请查看我们的快速入门指南(快速入门的简短培训视频)或我们的免费基础培训课程。您可以随时开始免费试用 Elastic Cloud 14 天。或者下载免费的 Elastic Stack 自管理版本。

参考资料

https://www.lunasec.io/docs/blog/log4j-zero-day/

https://www.tenable.com/blog/cve-2021-44228-proof-of-concept-for-critical-apache-log4j-remote-code-execution-vulnerability

https://www.crowdstrike.com/blog/log4j2-vulnerability-analysis-and-mitigation-recommendations/

https://mbechler.github.io/2021/12/10/PSA_Log4Shell_JNDI_Injection/

https://www.greynoise.io/viz/query/?gnql=CVE-2021-44228

https://logging.apache.ac.cn/log4j/2.x/security.html#

https://github.com/christophetd/log4shell-vulnerable-app