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

Goal: 1000 CNY · Raised: 1000 CNY

100.0%

CVE-2021-44228 PoC — Apache Log4j 代码问题漏洞

Source
Associated Vulnerability
Title:Apache Log4j 代码问题漏洞 (CVE-2021-44228)
Description:Apache Log4j是美国阿帕奇(Apache)基金会的一款基于Java的开源日志记录工具。 Apache Log4J 存在代码问题漏洞,攻击者可设计一个数据请求发送给使用 Apache Log4j工具的服务器,当该请求被打印成日志时就会触发远程代码执行。
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. If the original source is unavailable, please email f.jinxu#gmail.com for a local snapshot (replace # with @).
    3. Shenlong has snapshotted the POC code for you. To support long-term maintenance, please consider donating. Thank you for your support.