Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1000 CNY

100.0%

CVE-2021-44228 PoC — Apache Log4j2 JNDI features do not protect against attacker controlled LDAP and other JNDI related endpoints

Source
Associated Vulnerability
Title:Apache Log4j2 JNDI features do not protect against attacker controlled LDAP and other JNDI related endpoints (CVE-2021-44228)
Description:Apache Log4j2 2.0-beta9 through 2.15.0 (excluding security releases 2.12.2, 2.12.3, and 2.3.1) JNDI features used in configuration, log messages, and parameters do not protect against attacker controlled LDAP and other JNDI related endpoints. An attacker who can control log messages or log message parameters can execute arbitrary code loaded from LDAP servers when message lookup substitution is enabled. From log4j 2.15.0, this behavior has been disabled by default. From version 2.16.0 (along with 2.12.2, 2.12.3, and 2.3.1), this functionality has been completely removed. Note that this vulnerability is specific to log4j-core and does not affect log4net, log4cxx, or other Apache Logging Services projects.
Readme
# 青藤 log4j2-patch

https://github.com/qingtengyun/cve-2021-44228-qingteng-patch
  
修复 log4j2的 CVE-2021-44228 , 利用 JVM 提供的 Instrumentation API来更改加载到 JVM 中的现有字节码。  
在不重启Java进程的情况下,修改org.apache.logging.log4j.core.lookup.JndiLookup类的lookup方法,固定返回
Patched JndiLookup::lookup()。

简单参考了 https://github.com/corretto/hotpatch-for-apache-log4j2 进行了修改增强,**支持JDK版本6、7、8、9、10、11, 支持Windows**  
jattach和 jattach.exe 来自 https://github.com/apangin/jattach, 可以和github的对比。  

如不放心下载的构建好的工具,可下载代码自行执行 build.sh 打包替换。  
build.sh 打包结果位于 build/cve-2021-44228-qingteng-patch 目录下


## 使用方法

Linux:  
```bash
./attach.sh $pid
./attach.sh
```

./attach.sh 不带pid将使用jps列出此机器上所有java进程,然后输入行号选择进程来进行注入修复,输入all将会注入所有列出的java进程
可输入多个,空格分割。


Windows:  
双击 attach.bat, 然后输入java进程pid  
或者cmd命令行里传入pid,例如 ```attach.bat pid```

## 例子
```
$ ./attach.sh 438625
/data/qingteng/cve-2021-44228-qingteng-patch
will patch pid: 438625
/data/qingteng/cve-2021-44228-qingteng-patch/jattach 438625 load instrument false /data/qingteng/cve-2021-44228-qingteng-patch/qt-log4j-agent.jar=/data/qingteng/cve-2021-44228-qingteng-patch/qt-log4j-patch.jar
Connected to remote JVM
JVM response code = 0
0
```

末尾返回
```
JVM response code = 0
0
```
表示注入成功。 否则为失败。


## 注意事项
一、如果报如下错误  
```
Could not start attach mechanism: No such file or directory
```
可能的原因有
1、VM带有下面参数运行 `-XX:+DisableAttachMechanism`,表示已禁用 Attach 。  
2、/tmp/.java_pid$pid socket文件产生过然后已被删除,无法 Attach,无法使用此方法。

二、需要和Java进程运行的用户是相同用户,如果运行用户禁止登录,可以用root执行su来执行,注意替换pid_username和pid  
```
su -l -s /bin/bash -c "$(pwd)/attach.sh pid" pid_username
```
File Snapshot

[4.0K] /data/pocs/e61bbca5764242a88b4e8fcda1c587e81ad6a5d0 ├── [4.0K] agent │   ├── [ 327] build.gradle │   └── [4.0K] src │   └── [4.0K] main │   └── [4.0K] java │   └── [4.0K] com │   └── [4.0K] qt │   └── [4.0K] rasp │   ├── [4.0K] agent │   │   └── [2.7K] RaspClassLoader.java │   └── [4.0K] agent1 │   └── [2.4K] AgentBootstrap.java ├── [ 302] attach.bat ├── [1.2K] attach.sh ├── [ 465] build.gradle ├── [ 710] build.sh ├── [4.0K] gradle │   └── [4.0K] wrapper │   ├── [ 58K] gradle-wrapper.jar │   └── [ 202] gradle-wrapper.properties ├── [5.6K] gradlew ├── [2.7K] gradlew.bat ├── [4.0K] patch │   ├── [ 240] build.gradle │   └── [4.0K] src │   └── [4.0K] main │   └── [4.0K] java │   └── [4.0K] com │   └── [4.0K] qt │   └── [4.0K] log4j │   └── [2.9K] Log4JPatch.java ├── [2.1K] README.md └── [ 35] settings.gradle 18 directories, 15 files
Shenlong Bot has cached this for you
Remarks
    1. It is advised to access via the original source first.
    2. Local POC snapshots are reserved for subscribers — if the original source is unavailable, the local mirror is part of the paid plan.
    3. Mirroring, verifying, and maintaining this POC archive takes ongoing effort, so local snapshots are a paid feature. Your subscription keeps the archive online — thank you for the support. View subscription plans →