2023-08-03 19:12:22 +00:00
# 8009 - 渗透测试Apache JServ协议( AJP)
2022-04-28 16:01:33 +00:00
< details >
2023-08-03 19:12:22 +00:00
< summary > < a href = "https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology" > < strong > ☁️ HackTricks云 ☁️< / strong > < / a > -< a href = "https://twitter.com/hacktricks_live" > < strong > 🐦 Twitter 🐦< / strong > < / a > - < a href = "https://www.twitch.tv/hacktricks_live/schedule" > < strong > 🎙️ Twitch 🎙️< / strong > < / a > - < a href = "https://www.youtube.com/@hacktricks_LIVE" > < strong > 🎥 Youtube 🎥< / strong > < / a > < / summary >
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
* 你在一家**网络安全公司**工作吗? 你想在HackTricks中看到你的**公司广告**吗?或者你想获得**PEASS的最新版本或下载PDF格式的HackTricks**吗?请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
2023-09-11 00:08:00 +00:00
* 发现我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品——[**The PEASS Family**](https://opensea.io/collection/the-peass-family)
2023-08-03 19:12:22 +00:00
* 获得[**官方PEASS和HackTricks周边产品**](https://peass.creator-spring.com)
2023-09-11 00:08:00 +00:00
* **加入**[**💬**](https://emojipedia.org/speech-balloon/) [**Discord群组** ](https://discord.gg/hRep4RUj7f )或[**电报群组**](https://t.me/peass),或者**关注**我在**Twitter**上的[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**。**
2023-08-03 19:12:22 +00:00
* **通过向**[**hacktricks repo**](https://github.com/carlospolop/hacktricks) **和** [**hacktricks-cloud repo** ](https://github.com/carlospolop/hacktricks-cloud ) **提交PR来分享你的黑客技巧。**
2022-04-28 16:01:33 +00:00
< / details >
2023-07-31 15:59:11 +00:00
< figure > < img src = "../.gitbook/assets/image (1) (3) (1).png" alt = "" > < figcaption > < / figcaption > < / figure >
2022-11-05 09:07:43 +00:00
2023-08-03 19:12:22 +00:00
**HackenProof是所有加密漏洞赏金的家园。**
2023-02-27 09:28:45 +00:00
2023-09-11 00:08:00 +00:00
**无需等待即可获得奖励**\
2023-08-03 19:12:22 +00:00
HackenProof的赏金只有在客户存入奖励预算后才会启动。在漏洞验证后, 您将获得奖励。
2023-02-27 09:28:45 +00:00
2023-09-11 00:08:00 +00:00
**在web3渗透测试中积累经验**\
2023-08-03 19:12:22 +00:00
区块链协议和智能合约是新的互联网! 在其兴起的日子里掌握web3安全。
2023-02-27 09:28:45 +00:00
2023-08-03 19:12:22 +00:00
**成为web3黑客传奇**\
每次验证的漏洞都会获得声誉积分,并占据每周排行榜的榜首。
2023-07-14 15:03:41 +00:00
2023-08-03 19:12:22 +00:00
[**在HackenProof上注册** ](https://hackenproof.com/register )开始从您的黑客攻击中获利!
2023-07-14 15:03:41 +00:00
{% embed url="https://hackenproof.com/register" %}
2022-11-05 09:07:43 +00:00
2023-08-03 19:12:22 +00:00
## 基本信息
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
来源:[https://diablohorn.com/2011/10/19/8009-the-forgotten-tomcat-port/](https://diablohorn.com/2011/10/19/8009-the-forgotten-tomcat-port/)
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
> AJP是一种传输协议。它是HTTP协议的优化版本, 允许独立的Web服务器( 如[Apache](http://httpd.apache.org/)) 与Tomcat进行通信。从历史上看, Apache在提供静态内容方面比Tomcat快得多。这个想法是让Apache在可能的情况下提供静态内容, 但将与Tomcat相关的内容代理到Tomcat。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
还有趣的是:
2020-07-15 15:43:14 +00:00
2023-09-11 00:08:00 +00:00
> ajp13协议是面向数据包的。出于性能原因, 二进制格式可能是为了选择比更易读的纯文本。Web服务器通过TCP连接与Servlet容器通信。为了减少昂贵的套接字创建过程, Web服务器将尝试维护与Servlet容器的持久TCP连接, 并重用连接进行多个请求/响应周期。
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
**默认端口:**8009
2022-05-01 13:25:53 +00:00
```
2020-07-15 15:43:14 +00:00
PORT STATE SERVICE
8009/tcp open ajp13
```
2022-05-01 13:25:53 +00:00
## CVE-2020-1938 ['Ghostcat'](https://www.chaitin.cn/en/ghostcat)
2021-04-27 04:58:23 +00:00
2023-09-11 00:08:00 +00:00
如果AJP端口暴露, Tomcat可能会受到Ghostcat漏洞的影响。这是一个与此问题配套的[利用工具](https://www.exploit-db.com/exploits/48143)。
2021-04-27 04:58:23 +00:00
2023-09-11 00:08:00 +00:00
Ghostcat是一种LFI漏洞, 但受到一定限制: 只能获取特定路径下的文件。尽管如此, 这可能包括像`WEB-INF/web.xml`这样的文件, 根据服务器设置, 这些文件可能会泄露重要信息, 如Tomcat接口的凭据。
2021-04-27 04:58:23 +00:00
2023-09-11 00:08:00 +00:00
修复此问题的版本为9.0.31及以上、8.5.51及以上和7.0.100及以上。
2021-04-27 04:58:23 +00:00
2023-08-03 19:12:22 +00:00
## 枚举
2020-07-15 15:43:14 +00:00
2023-09-11 00:08:00 +00:00
### 自动化枚举
2022-10-03 13:43:01 +00:00
```bash
nmap -sV --script ajp-auth,ajp-headers,ajp-methods,ajp-request -n -p 8009 < IP >
2022-05-01 13:25:53 +00:00
```
2023-08-03 19:12:22 +00:00
### [**暴力破解**](../generic-methodologies-and-resources/brute-force.md#ajp)
2022-10-03 13:43:01 +00:00
2023-08-03 19:12:22 +00:00
## AJP代理
2022-10-03 13:43:01 +00:00
2023-08-03 19:12:22 +00:00
### Apache AJP代理
2022-10-03 13:43:01 +00:00
2023-08-03 19:12:22 +00:00
很少遇到只有8009端口开放而没有其他Web端口开放的情况。在这种情况下, 使用现有的工具如metasploit仍然可以控制它, 是不是很好? 正如引用中所述, 您可以( 滥用) Apache将请求代理到Tomcat的8009端口。在参考资料中, 您将找到一个很好的指南, 介绍了如何做到这一点( 先阅读它) , 下面是我在自己的机器上使用的命令的概述。我省略了一些原始指令, 因为它们似乎不是必要的。
2022-10-03 13:43:01 +00:00
```bash
2021-01-20 22:58:40 +00:00
sudo apt-get install libapache2-mod-jk
sudo vim /etc/apache2/apache2.conf # append the following line to the config
2023-08-03 19:12:22 +00:00
Include ajp.conf
sudo vim /etc/apache2/ajp.conf # create the following file, change HOST to the target address
ProxyRequests Off
< Proxy * >
Order deny,allow
Deny from all
Allow from localhost
< / Proxy >
ProxyPass / ajp://HOST:8009/
ProxyPassReverse / ajp://HOST:8009/
2020-07-15 15:43:14 +00:00
sudo a2enmod proxy_http
2021-01-20 22:58:40 +00:00
sudo a2enmod proxy_ajp
sudo systemctl restart apache2
2020-07-15 15:43:14 +00:00
```
2023-08-03 19:12:22 +00:00
使用这种设置的一个好处是, 你可能会阻止已经存在的IDS/IPS系统, 因为AJP协议是二进制的, 但我还没有验证过这一点。现在你可以将你的常规metasploit tomcat exploit指向127.0.0.1:80并接管该系统。以下是metasploit的输出:
2022-10-03 13:43:01 +00:00
```bash
2020-07-15 15:43:14 +00:00
msf exploit(tomcat_mgr_deploy) > show options
Module options (exploit/multi/http/tomcat_mgr_deploy):
2023-08-03 19:12:22 +00:00
Name Current Setting Required Description
---- --------------- -------- -----------
PASSWORD tomcat no The password for the specified username
PATH /manager yes The URI path of the manager app (/deploy and /undeploy will be used)
Proxies no Use a proxy chain
RHOST localhost yes The target address
RPORT 80 yes The target port
USERNAME tomcat no The username to authenticate as
VHOST no HTTP server virtual host
2020-07-15 15:43:14 +00:00
```
2023-08-03 19:12:22 +00:00
### Nginx反向代理和AJP
2020-07-15 15:43:14 +00:00
2023-09-11 00:08:00 +00:00
[查看Docker化版本 ](#Docker化版本 )
当我们遇到一个开放的AJP代理端口( 8009 TCP) 时, 我们可以使用带有`ajp_module`的Nginx来访问“隐藏”的Tomcat管理器。这可以通过编译Nginx源代码并添加所需的模块来实现, 具体步骤如下:
2020-07-15 15:43:14 +00:00
2023-08-03 19:12:22 +00:00
* 下载Nginx源代码
* 下载所需的模块
* 使用`ajp_module`编译Nginx源代码。
* 创建一个指向AJP端口的配置文件
2020-07-15 15:43:14 +00:00
```bash
2022-10-03 13:43:01 +00:00
# Download Nginx code
wget https://nginx.org/download/nginx-1.21.3.tar.gz
tar -xzvf nginx-1.21.3.tar.gz
# Compile Nginx source code with the ajp module
git clone https://github.com/dvershinin/nginx_ajp_module.git
cd nginx-1.21.3
sudo apt install libpcre3-dev
./configure --add-module=`pwd`/../nginx_ajp_module --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules
make
sudo make install
nginx -V
2020-07-15 15:43:14 +00:00
```
2023-08-03 19:12:22 +00:00
在`/etc/nginx/conf/nginx.conf`文件中,将整个`server`块注释掉,并在`http`块内添加以下行。
2022-10-03 13:43:01 +00:00
```shell-session
upstream tomcats {
2023-08-03 19:12:22 +00:00
server < TARGET_SERVER > :8009;
keepalive 10;
}
2022-10-03 13:43:01 +00:00
server {
2023-08-03 19:12:22 +00:00
listen 80;
location / {
ajp_keep_conn on;
ajp_pass tomcats;
}
2022-10-03 13:43:01 +00:00
}
```
2023-09-11 00:08:00 +00:00
启动Nginx并通过向本地主机发送cURL请求来检查一切是否正常运行。
2022-10-03 13:43:01 +00:00
```html
sudo nginx
curl http://127.0.0.1:80
<!DOCTYPE html>
< html lang = "en" >
2023-08-03 19:12:22 +00:00
< head >
< meta charset = "UTF-8" / >
< title > Apache Tomcat/X.X.XX< / title >
< link href = "favicon.ico" rel = "icon" type = "image/x-icon" / >
< link href = "favicon.ico" rel = "shortcut icon" type = "image/x-icon" / >
< link href = "tomcat.css" rel = "stylesheet" type = "text/css" / >
< /headas
< body >
< div id = "wrapper" >
< div id = "navigation" class = "curved container" >
< span id = "nav-home" > < a href = "https://tomcat.apache.org/" > Home< / a > < / span >
< span id = "nav-hosts" > < a href = "/docs/" > Documentation< / a > < / span >
< span id = "nav-config" > < a href = "/docs/config/" > Configuration< / a > < / span >
< span id = "nav-examples" > < a href = "/examples/" > Examples< / a > < / span >
< span id = "nav-wiki" > < a href = "https://wiki.apache.org/tomcat/FrontPage" > Wiki< / a > < / span >
< span id = "nav-lists" > < a href = "https://tomcat.apache.org/lists.html" > Mailing Lists< / a > < / span >
< span id = "nav-help" > < a href = "https://tomcat.apache.org/findhelp.html" > Find Help< / a > < / span >
< br class = "separator" / >
< / div >
< div id = "asf-box" >
< h1 > Apache Tomcat/X.X.XX< / h1 >
< / div >
< div id = "upper" class = "curved container" >
< div id = "congrats" class = "curved container" >
< h2 > If you're seeing this, you've successfully installed Tomcat. Congratulations!< / h2 >
2022-10-03 13:43:01 +00:00
< SNIP >
```
2023-09-11 00:08:00 +00:00
### Docker化版本
The Dockerized version of Apache JServ Protocol (AJP) is a convenient way to deploy and test AJP-based applications. By containerizing the AJP server, you can easily set up and tear down testing environments without the need for manual installation and configuration.
To create a Dockerized version of AJP, you can use the official Apache Tomcat Docker image as a base. Apache Tomcat is a popular Java Servlet container that supports the AJP protocol.
Here are the steps to create a Dockerized version of AJP:
1. Create a Dockerfile with the following content:
```dockerfile
FROM tomcat:latest
EXPOSE 8009
```
2. Build the Docker image using the following command:
```bash
docker build -t ajp-server .
```
3. Run the Docker container using the following command:
```bash
docker run -d -p 8009:8009 --name ajp-container ajp-server
```
4. Verify that the AJP server is running by accessing the following URL in your browser:
```
http://localhost:8009
```
If the AJP server is running correctly, you should see the default Apache Tomcat homepage.
You can now deploy your AJP-based applications to the Dockerized AJP server and test them in a controlled environment. Remember to properly secure your AJP server by configuring authentication and access controls to prevent unauthorized access.
By using Docker, you can easily replicate and distribute your AJP testing environment, making it easier to collaborate with other team members and share your findings.
```bash
git clone https://github.com/ScribblerCoder/nginx-ajp-docker
cd nginx-ajp-docker
```
将`nginx.conf`中的`TARGET-IP`替换为AJP IP, 然后构建并运行。
``` bash
docker build . -t nginx-ajp-proxy
docker run -it --rm -p 80:80 nginx-ajp-proxy
```
2023-08-03 19:12:22 +00:00
## 参考资料
2022-04-28 16:01:33 +00:00
2022-10-03 13:43:01 +00:00
* [https://academy.hackthebox.com/module/145/section/1295 ](https://academy.hackthebox.com/module/145/section/1295 )
2022-04-28 16:01:33 +00:00
2023-07-31 15:59:11 +00:00
< figure > < img src = "../.gitbook/assets/image (1) (3) (1).png" alt = "" > < figcaption > < / figcaption > < / figure >
2023-07-14 15:03:41 +00:00
2023-08-03 19:12:22 +00:00
**HackenProof 是所有加密漏洞赏金的家园。**
2023-07-14 15:03:41 +00:00
2023-09-11 00:08:00 +00:00
**即刻获得奖励**\
2023-08-03 19:12:22 +00:00
HackenProof 的赏金只有在客户存入奖励预算后才会启动。在漏洞验证后,您将获得奖励。
2022-11-05 09:07:43 +00:00
2023-08-03 19:12:22 +00:00
**在 web3 渗透测试中积累经验**\
2023-09-11 00:08:00 +00:00
区块链协议和智能合约是新的互联网!在其兴起之时掌握 web3 安全。
2023-02-27 09:28:45 +00:00
2023-08-03 19:12:22 +00:00
**成为 web3 黑客传奇**\
2023-09-11 00:08:00 +00:00
每次验证的漏洞都会增加声誉积分,征服每周排行榜的顶端。
2023-02-27 09:28:45 +00:00
2023-09-11 00:08:00 +00:00
[**在 HackenProof 上注册** ](https://hackenproof.com/register ) 并从您的黑客攻击中获利!
2023-02-27 09:28:45 +00:00
2023-07-14 15:03:41 +00:00
{% embed url="https://hackenproof.com/register" %}
2022-11-05 09:07:43 +00:00
2022-10-03 13:43:01 +00:00
< details >
2022-04-28 16:01:33 +00:00
2023-09-11 00:08:00 +00:00
< summary > < a href = "https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology" > < strong > ☁️ HackTricks Cloud ☁️< / strong > < / a > -< a href = "https://twitter.com/hacktricks_live" > < strong > 🐦 Twitter 🐦< / strong > < / a > - < a href = "https://www.twitch.tv/hacktricks_live/schedule" > < strong > 🎙️ Twitch 🎙️< / strong > < / a > - < a href = "https://www.youtube.com/@hacktricks_LIVE" > < strong > 🎥 Youtube 🎥< / strong > < / a > < / summary >
2022-04-28 16:01:33 +00:00
2023-09-11 00:08:00 +00:00
* 您在**网络安全公司**工作吗?您想在 HackTricks 中看到您的**公司广告**吗?或者您想获得**PEASS 的最新版本或下载 PDF 格式的 HackTricks**?请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 发现我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品——[**The PEASS Family**](https://opensea.io/collection/the-peass-family)
2023-08-03 19:12:22 +00:00
* 获得[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* **加入**[**💬**](https://emojipedia.org/speech-balloon/) [**Discord 群组** ](https://discord.gg/hRep4RUj7f ) 或 [**Telegram 群组** ](https://t.me/peass ),或在**Twitter**上**关注**我[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**。**
* **通过向**[**hacktricks 仓库**](https://github.com/carlospolop/hacktricks) **和** [**hacktricks-cloud 仓库** ](https://github.com/carlospolop/hacktricks-cloud ) **提交 PR 来分享您的黑客技巧。**
2022-04-28 16:01:33 +00:00
< / details >