HackTricks
Search…
Pentesting
Powered By GitBook
8009 - Pentesting Apache JServ Protocol (AJP)

Basic Information

AJP is a wire protocol. It an optimized version of the HTTP protocol to allow a standalone web server such as Apache to talk to Tomcat. Historically, Apache has been much faster than Tomcat at serving static content. The idea is to let Apache serve the static content when possible, but proxy the request to Tomcat for Tomcat related content.
Also interesting:
The ajp13 protocol is packet-oriented. A binary format was presumably chosen over the more readable plain text for reasons of performance. The web server communicates with the servlet container over TCP connections. To cut down on the expensive process of socket creation, the web server will attempt to maintain persistent TCP connections to the servlet container, and to reuse a connection for multiple request/response cycles
Default port: 8009
1
PORT STATE SERVICE
2
8009/tcp open ajp13
Copied!

CVE-2020-1938 'Ghostcat'

If the AJP port is exposed, Tomcat might be susceptible to the Ghostcat vulnerability. Here is an exploit that works with this issue.
Ghostcat is a LFI vulnerability, but somewhat restricted: only files from a certain path can be pulled. Still, this can include files like WEB-INF/web.xml which can leak important information like credentials for the Tomcat interface, depending on the server setup.
Patched versions at or above 9.0.31, 8.5.51, and 7.0.100 have fixed this issue.

Apache AJP Proxy

It’s not often that you encounter port 8009 open and port 8080,8180,8443 or 80 closed but it happens. In which case it would be nice to use existing tools like metasploit to still pwn it right? As stated in one of the quotes you can (ab)use Apache to proxy the requests to Tomcat port 8009. In the references you will find a nice guide on how to do that (read it first), what follows is just an overview of the commands I used on my own machine. I omitted some of the original instruction since they didn’t seem to be necessary.
1
sudo apt-get install libapache2-mod-jk
2
sudo vim /etc/apache2/apache2.conf # append the following line to the config
3
Include ajp.conf
4
sudo vim /etc/apache2/ajp.conf # create the following file, change HOST to the target address
5
ProxyRequests Off
6
<Proxy *>
7
Order deny,allow
8
Deny from all
9
Allow from localhost
10
</Proxy>
11
ProxyPass / ajp://HOST:8009/
12
ProxyPassReverse / ajp://HOST:8009/
13
sudo a2enmod proxy_http
14
sudo a2enmod proxy_ajp
15
sudo systemctl restart apache2
Copied!
A nice side effect of using this setup is that you might thwart IDS/IPS systems in place since the AJP protocol is somewhat binary, but I haven’t verified this. Now you can just point your regular metasploit tomcat exploit to 127.0.0.1:80 and take over that system. Here is the metasploit output also:
1
msf exploit(tomcat_mgr_deploy) > show options
2
3
Module options (exploit/multi/http/tomcat_mgr_deploy):
4
5
Name Current Setting Required Description
6
---- --------------- -------- -----------
7
PASSWORD tomcat no The password for the specified username
8
PATH /manager yes The URI path of the manager app (/deploy and /undeploy will be used)
9
Proxies no Use a proxy chain
10
RHOST localhost yes The target address
11
RPORT 80 yes The target port
12
USERNAME tomcat no The username to authenticate as
13
VHOST no HTTP server virtual host
Copied!

Enumeration

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

****Brute force****

Last modified 5mo ago