hacktricks/src/network-services-pentesting/8009-pentesting-apache-jserv-protocol-ajp.md

88 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 8009 - Pentesting Apache JServ Protocol (AJP)
{{#include ../banners/hacktricks-training.md}}
## 基本信息
来自 [https://diablohorn.com/2011/10/19/8009-the-forgotten-tomcat-port/](https://diablohorn.com/2011/10/19/8009-the-forgotten-tomcat-port/)
> AJP 是一种线协议。它是 HTTP 协议的优化版本,允许独立的 web 服务器如 [Apache](http://httpd.apache.org/) 与 Tomcat 通信。历史上Apache 在提供静态内容方面比 Tomcat 快得多。这个想法是让 Apache 在可能的情况下提供静态内容,但将请求代理到 Tomcat 以获取与 Tomcat 相关的内容。
还有趣的是:
> ajp13 协议是面向数据包的。出于性能原因显然选择了二进制格式而不是更易读的纯文本。web 服务器通过 TCP 连接与 servlet 容器通信。为了减少创建套接字的昂贵过程web 服务器将尝试保持与 servlet 容器的持久 TCP 连接,并重用一个连接进行多个请求/响应周期。
**默认端口:** 8009
```
PORT STATE SERVICE
8009/tcp open ajp13
```
## CVE-2020-1938 ['Ghostcat'](https://www.chaitin.cn/en/ghostcat)
这是一个LFI漏洞允许获取一些文件`WEB-INF/web.xml`,其中包含凭据。这是一个[exploit](https://www.exploit-db.com/exploits/48143)用于利用该漏洞AJP暴露的端口可能会受到影响。
修补版本为9.0.31及以上、8.5.51和7.0.100。
## Enumeration
### Automatic
```bash
nmap -sV --script ajp-auth,ajp-headers,ajp-methods,ajp-request -n -p 8009 <IP>
```
### [**暴力破解**](../generic-hacking/brute-force.md#ajp)
## AJP 代理
### Nginx 反向代理 + AJP
([查看 Docker 化版本](8009-pentesting-apache-jserv-protocol-ajp.md#Dockerized-version))
可以通过使用 Nginx `ajp_module` apache 模块与开放的 AJP 代理端口 (8009 TCP) 进行通信,并从该端口访问 Tomat Manager这可能最终导致在易受攻击的服务器上实现 RCE。
- 从 [https://nginx.org/en/download.html](https://nginx.org/en/download.html) 开始下载 Nginx然后使用 ajp 模块进行编译:
```bash
# Compile Nginx with the ajp module
git clone https://github.com/dvershinin/nginx_ajp_module.git
cd nginx-version
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
```
- 然后,注释掉 `server` 块,并在 `/etc/nginx/conf/nginx.conf``http` 块中添加以下内容。
```json
upstream tomcats {
server <TARGET_SERVER>:8009;
keepalive 10;
}
server {
listen 80;
location / {
ajp_keep_conn on;
ajp_pass tomcats;
}
}
```
- 最后,启动 nginx (`sudo nginx`),并通过访问 `http://127.0.0.1` 检查它是否正常工作。
### Nginx Docker化版本
```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
```
### Apache AJP 代理
也可以使用 **Apache AJP 代理** 来访问该端口,而不是 **Nginx**
## 参考
- [https://github.com/yaoweibin/nginx_ajp_module](https://github.com/yaoweibin/nginx_ajp_module)
{{#include ../banners/hacktricks-training.md}}