8009 - Pentesting Apache JServ Protocol (AJP)

Support HackTricks

Join HackenProof Discord server to communicate with experienced hackers and bug bounty hunters!

Hacking Insights Engage with content that delves into the thrill and challenges of hacking

Real-Time Hack News Keep up-to-date with fast-paced hacking world through real-time news and insights

Latest Announcements Stay informed with the newest bug bounties launching and crucial platform updates

Join us on Discord and start collaborating with top hackers today!

Basic Information

From: https://diablohorn.com/2011/10/19/8009-the-forgotten-tomcat-port/

AJP는 전송 프로토콜입니다. 독립형 웹 서버인 Apache가 Tomcat과 통신할 수 있도록 HTTP 프로토콜의 최적화된 버전입니다. 역사적으로 Apache는 정적 콘텐츠를 제공하는 데 Tomcat보다 훨씬 빠릅니다. 아이디어는 가능한 경우 Apache가 정적 콘텐츠를 제공하고, Tomcat 관련 콘텐츠에 대해서는 Tomcat에 요청을 프록시하는 것입니다.

Also interesting:

ajp13 프로토콜은 패킷 지향입니다. 성능상의 이유로 더 읽기 쉬운 일반 텍스트보다 이진 형식이 선택된 것으로 보입니다. 웹 서버는 TCP 연결을 통해 서블릿 컨테이너와 통신합니다. 소켓 생성의 비용이 많이 드는 과정을 줄이기 위해 웹 서버는 서블릿 컨테이너에 대한 지속적인 TCP 연결을 유지하고, 여러 요청/응답 주기를 위해 연결을 재사용하려고 시도합니다.

Default port: 8009

PORT     STATE SERVICE
8009/tcp open  ajp13

CVE-2020-1938 'Ghostcat'

AJP 포트가 노출되면 Tomcat은 Ghostcat 취약점에 노출될 수 있습니다. 이 문제와 관련된 익스플로잇이 있습니다.

Ghostcat은 LFI 취약점이지만 다소 제한적입니다: 특정 경로의 파일만 가져올 수 있습니다. 그럼에도 불구하고, 이는 서버 설정에 따라 Tomcat 인터페이스의 자격 증명과 같은 중요한 정보를 유출할 수 있는 WEB-INF/web.xml과 같은 파일을 포함할 수 있습니다.

9.0.31, 8.5.51 및 7.0.100 이상의 패치된 버전에서 이 문제가 수정되었습니다.

Enumeration

Automatic

nmap -sV --script ajp-auth,ajp-headers,ajp-methods,ajp-request -n -p 8009 <IP>

AJP 프록시

Nginx 리버스 프록시 & AJP

도커화된 버전 확인하기

열린 AJP 프록시 포트(8009 TCP)를 발견하면, ajp_module을 사용하여 Nginx로 "숨겨진" Tomcat Manager에 접근할 수 있습니다. 이는 Nginx 소스 코드를 컴파일하고 필요한 모듈을 추가하여 수행할 수 있습니다:

  • Nginx 소스 코드 다운로드

  • 필요한 모듈 다운로드

  • ajp_module과 함께 Nginx 소스 코드 컴파일.

  • AJP 포트를 가리키는 구성 파일 생성

# 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

server 블록 전체를 주석 처리하고 /etc/nginx/conf/nginx.confhttp 블록 안에 다음 줄을 추가합니다.

upstream tomcats {
server <TARGET_SERVER>:8009;
keepalive 10;
}
server {
listen 80;
location / {
ajp_keep_conn on;
ajp_pass tomcats;
}
}

Nginx를 시작하고 로컬 호스트에 cURL 요청을 발행하여 모든 것이 올바르게 작동하는지 확인하십시오.

sudo nginx
curl http://127.0.0.1:80

<!DOCTYPE html>
<html lang="en">
<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>
<SNIP>

Nginx 도커화 버전

git clone https://github.com/ScribblerCoder/nginx-ajp-docker
cd nginx-ajp-docker

nginx.conf에서 TARGET-IP를 AJP IP로 교체한 후 빌드하고 실행합니다.

docker build . -t nginx-ajp-proxy
docker run -it --rm -p 80:80 nginx-ajp-proxy

Apache AJP Proxy

열려 있는 포트 8009를 다른 접근 가능한 웹 포트 없이 만나는 것은 드뭅니다. 그러나 Metasploit을 사용하여 이를 악용하는 것은 여전히 가능합니다. Apache를 프록시로 활용하여 요청을 포트 8009의 Tomcat으로 리디렉션할 수 있습니다.

sudo apt-get install libapache2-mod-jk
sudo vim /etc/apache2/apache2.conf # append the following line to the config
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/
sudo a2enmod proxy_http
sudo a2enmod proxy_ajp
sudo systemctl restart apache2

이 설정은 AJP 프로토콜의 이진 특성으로 인해 침입 탐지 및 방지 시스템(IDS/IPS)을 우회할 수 있는 잠재력을 제공합니다. 이 기능은 검증되지 않았습니다. 일반 Metasploit Tomcat 익스플로잇을 127.0.0.1:80으로 전송하면 대상 시스템을 효과적으로 장악할 수 있습니다.

msf  exploit(tomcat_mgr_deploy) > show options

References

경험이 풍부한 해커 및 버그 바운티 헌터와 소통하기 위해 HackenProof Discord 서버에 참여하세요!

Hacking Insights 해킹의 스릴과 도전에 대해 깊이 있는 콘텐츠에 참여하세요.

Real-Time Hack News 실시간 뉴스와 통찰력을 통해 빠르게 변화하는 해킹 세계를 최신 상태로 유지하세요.

Latest Announcements 새로운 버그 바운티 출시 및 중요한 플랫폼 업데이트에 대한 정보를 유지하세요.

오늘 Discord에 참여하여 최고의 해커들과 협업을 시작하세요!

Support HackTricks

Last updated