Basic Tomcat Info

Wsparcie dla HackTricks

Try Hard Security Group


Unikaj uruchamiania jako root

Aby nie uruchamiać Tomcat jako root, bardzo powszechną konfiguracją jest ustawienie serwera Apache na porcie 80/443 i, jeśli żądana ścieżka pasuje do wyrażenia regularnego, żądanie jest wysyłane do Tomcat działającego na innym porcie.

Domyślna struktura

├── bin
├── conf
│   ├── catalina.policy
│   ├── catalina.properties
│   ├── context.xml
│   ├── tomcat-users.xml
│   ├── tomcat-users.xsd
│   └── web.xml
├── lib
├── logs
├── temp
├── webapps
│   ├── manager
│   │   ├── images
│   │   ├── META-INF
│   │   └── WEB-INF
|   |       └── web.xml
│   └── ROOT
│       └── WEB-INF
└── work
└── Catalina
└── localhost
  • Folder bin przechowuje skrypty i pliki binarne potrzebne do uruchomienia serwera Tomcat.

  • Folder conf przechowuje różne pliki konfiguracyjne używane przez Tomcat.

  • Plik tomcat-users.xml przechowuje dane uwierzytelniające użytkowników i przypisane im role.

  • Folder lib zawiera różne pliki JAR potrzebne do prawidłowego działania Tomcat.

  • Foldery logs i temp przechowują tymczasowe pliki dziennika.

  • Folder webapps jest domyślnym katalogiem głównym Tomcat i hostuje wszystkie aplikacje. Folder work działa jako pamięć podręczna i jest używany do przechowywania danych w czasie działania.

Każdy folder wewnątrz webapps powinien mieć następującą strukturę.

webapps/customapp
├── images
├── index.jsp
├── META-INF
│   └── context.xml
├── status.xsd
└── WEB-INF
├── jsp
|   └── admin.jsp
└── web.xml
└── lib
|    └── jdbc_drivers.jar
└── classes
└── AdminServlet.class

Najważniejszym plikiem wśród nich jest WEB-INF/web.xml, znany jako opis wdrożenia. Plik ten przechowuje informacje o trasach używanych przez aplikację oraz klasach obsługujących te trasy. Wszystkie skompilowane klasy używane przez aplikację powinny być przechowywane w folderze WEB-INF/classes. Klasy te mogą zawierać ważną logikę biznesową oraz wrażliwe informacje. Każda luka w tych plikach może prowadzić do całkowitego kompromitacji strony internetowej. Folder lib przechowuje biblioteki potrzebne przez tę konkretną aplikację. Folder jsp przechowuje Jakarta Server Pages (JSP), wcześniej znane jako JavaServer Pages, które można porównać do plików PHP na serwerze Apache.

Oto przykład pliku web.xml.

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>AdminServlet</servlet-name>
<servlet-class>com.inlanefreight.api.AdminServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>AdminServlet</servlet-name>
<url-pattern>/admin</url-pattern>
</servlet-mapping>
</web-app>

The web.xml configuration above defines a nowy serwlet o nazwie AdminServlet that is mapped to the klasę com.inlanefreight.api.AdminServlet. Java uses the dot notation to create package names, meaning the path on disk for the class defined above would be:

  • classes/com/inlanefreight/api/AdminServlet.class

Next, a new servlet mapping is created to map requests to /admin with AdminServlet. This configuration will send any request received for /admin to the AdminServlet.class class for processing. The web.xml descriptor holds a lot of wrażliwych informacji and is an important file to check when leveraging a Local File Inclusion (LFI) vulnerability.

tomcat-users

The tomcat-users.xml file is used to pozwolić or disallow access to the /manager and host-manager admin pages.

<?xml version="1.0" encoding="UTF-8"?>

<SNIP>

<tomcat-users xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
version="1.0">
<!--
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

The users below are wrapped in a comment and are therefore ignored. If you
wish to configure one or more of these users for use with the manager web
application, do not forget to remove the <!.. ..> that surrounds them. You
will also need to set the passwords to something appropriate.
-->


<SNIP>

!-- user manager can access only manager section -->
<role rolename="manager-gui" />
<user username="tomcat" password="tomcat" roles="manager-gui" />

<!-- user admin can access manager and admin section both -->
<role rolename="admin-gui" />
<user username="admin" password="admin" roles="manager-gui,admin-gui" />


</tomcat-users>

Plik pokazuje, do czego dostęp mają poszczególne role manager-gui, manager-script, manager-jmx i manager-status. W tym przykładzie widzimy, że użytkownik tomcat z hasłem tomcat ma rolę manager-gui, a dla konta użytkownika admin ustawione jest drugie słabe hasło admin.

References

Try Hard Security Group

Support HackTricks

Last updated