Abusing Intermediary Applications
AJP Proxy
When we come across open AJP proxy ports (8009 TCP) during penetration tests, we may be able to use them to access the "hidden" Apache Tomcat Manager behind it. Although AJP-Proxy is a binary protocol, we can configure our own Nginx or Apache webserver with AJP modules to interact with it and access the underlying application. This way, we can discover administrative panels, applications, and websites that would be otherwise inaccessible.
Docker Installation
sudo apt install docker
sudo docker run -it --rm -p 8009:8009 -v `pwd`/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml --name tomcat "tomcat:8.0"Nginx Reverse Proxy & AJP
When we come across an open AJP proxy port (8009 TCP), we can use Nginx with the ajp_module to access the "hidden" Tomcat Manager.
Download Nginx Source Code
wget https://nginx.org/download/nginx-1.21.3.tar.gz
tar -xzvf nginx-1.21.3.tar.gzCompile Nginx source code with the ajp module
Staphy$ git clone https://github.com/dvershinin/nginx_ajp_module.git
Staphy$ cd nginx-1.21.3
Staphy$ sudo apt install libpcre3-dev
Staphy$ ./configure --add-module=`pwd`/../nginx_ajp_module --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules
Staphy$ make
Staphy$ sudo make install
Staphy$ nginx -V
nginx version: nginx/1.21.3
built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
configure arguments: --add-module=../nginx_ajp_module --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/moduleComment out the entire server block and append the following lines inside the http block in /etc/nginx/conf/nginx.conf.
Pointing to the AJP Port:
Start Nginx and check if everything is working correctly by issuing a curl request to your local host.
Apache Reverse Proxy & AJP
Apache has the AJP module precompiled for us. We will need to install it, though, as it doesn't come in default installations. Configuring the AJP-Proxy in our Apache server can be done as follows:
Install the libapache2-mod-jk package
Enable the module
Create the configuration file pointing to the target AJP-Proxy port
The required commands and configuration files are the following:
Accessing the "hidden" Tomcat page
If we configure everything correctly, we will be able to access the Apache Tomcat manager using both cURL and our web browser.
Last updated