Basic Tomcat Info

htARTE (HackTricks AWS Red Team Expert)를 통해 제로부터 영웅이 될 때까지 AWS 해킹을 배우세요!

Try Hard Security Group


root 권한으로 실행하지 않도록 주의

root로 Tomcat을 실행하지 않기 위한 매우 일반적인 구성은 포트 80/443에서 Apache 서버를 설정하고, 요청된 경로가 정규식과 일치하는 경우 요청이 다른 포트에서 실행 중인 Tomcat으로 전송되도록 하는 것입니다.

기본 구조

├── 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
  • bin 폴더에는 Tomcat 서버를 시작하고 실행하는 데 필요한 스크립트 및 이진 파일이 저장됩니다.

  • conf 폴더에는 Tomcat에서 사용하는 다양한 구성 파일이 저장됩니다.

  • tomcat-users.xml 파일에는 사용자 자격 증명과 할당된 역할이 저장됩니다.

  • lib 폴더에는 Tomcat의 올바른 작동에 필요한 다양한 JAR 파일이 저장됩니다.

  • logstemp 폴더에는 임시 로그 파일이 저장됩니다.

  • webapps 폴더는 Tomcat의 기본 웹 루트이며 모든 애플리케이션을 호스팅합니다. work 폴더는 캐시 역할을 하며 런타임 중에 데이터를 저장하는 데 사용됩니다.

webapps 내의 각 폴더는 다음 구조를 가지고 있어야 합니다.

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

가운데 가장 중요한 파일은 WEB-INF/web.xml이며, 배포 서술자로 알려져 있습니다. 이 파일은 애플리케이션에서 사용되는 경로 및 이러한 경로를 처리하는 클래스에 대한 정보를 저장합니다. 애플리케이션에서 사용되는 모든 컴파일된 클래스는 WEB-INF/classes 폴더에 저장되어야 합니다. 이러한 클래스에는 중요한 비즈니스 로직과 민감한 정보가 포함될 수 있습니다. 이 파일들의 취약점은 웹사이트의 완전한 침해로 이어질 수 있습니다. lib 폴더에는 해당 애플리케이션에 필요한 라이브러리가 저장됩니다. jsp 폴더에는 Jakarta Server Pages (JSP)가 저장되어 있으며, 이전에는 JavaServer Pages로 알려져 있었으며, Apache 서버의 PHP 파일과 비교될 수 있습니다.

다음은 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>

위의 web.xml 구성은 AdminServlet라는 새로운 서블릿을 정의하며, 이 서블릿은 com.inlanefreight.api.AdminServlet 클래스에 매핑됩니다. Java는 패키지 이름을 만들 때 점 표기법을 사용하며, 위에서 정의한 클래스의 디스크 경로는 다음과 같을 것입니다:

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

다음으로, /admin에 대한 요청을 AdminServlet로 매핑하는 새로운 서블릿 매핑이 생성됩니다. 이 구성은 /admin에 대한 모든 요청을 AdminServlet.class 클래스로 보내어 처리합니다. web.xml 설명자에는 많은 민감한 정보가 포함되어 있으며, 로컬 파일 포함 (LFI) 취약점을 활용할 때 확인해야 하는 중요한 파일입니다.

tomcat-users

tomcat-users.xml 파일은 /managerhost-manager 관리 페이지에 대한 액세스를 허용하거나 거부하는 데 사용됩니다.

<?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>

파일은 manager-gui, manager-script, manager-jmx, 그리고 manager-status 역할 각각이 무엇에 액세스 권한을 제공하는지 보여줍니다. 이 예시에서는 tomcat 사용자가 암호 tomcat으로 manager-gui 역할을 가지고 있으며, 두 번째로 약한 암호 adminadmin 사용자 계정에 설정되어 있습니다.

참고 자료

Try Hard Security Group

htARTE (HackTricks AWS Red Team Expert)를 통해 제로부터 영웅이 되기까지 AWS 해킹을 배워보세요!

Last updated