Basic Tomcat Info

从零开始学习AWS黑客技术,成为专家 htARTE(HackTricks AWS Red Team Expert)

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的默认Web根目录,托管所有应用程序。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`的新servlet,映射到类`com.inlanefreight.api.AdminServlet`。Java使用点表示法来创建包名,这意味着上面定义的类在磁盘上的路径为:

- `classes/com/inlanefreight/api/AdminServlet.class`

接下来,创建了一个新的servlet映射,将请求映射到`/admin`与`AdminServlet`。这个配置将会将任何接收到的`/admin`请求发送到`AdminServlet.class`类进行处理。`web.xml`描述符包含了许多敏感信息,是在利用本地文件包含(LFI)漏洞时需要检查的重要文件。

### tomcat-users

`tomcat-users.xml`文件用于允许或禁止访问`/manager``host-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-guimanager-scriptmanager-jmxmanager-status提供的访问权限。在这个示例中,我们可以看到一个名为tomcat,密码为tomcat的用户具有manager-gui角色,另外一个弱密码admin被设置给了用户账户admin

参考

Try Hard Security Group

从零开始学习AWS黑客技术,成为专家 htARTE(HackTricks AWS Red Team Expert)

最后更新于