TODO

Unified is introducing the exploitation of one of the biggest vulnerabilities of 2021, Log4Shell, also known as Log4j. This box demonstrates how to exploit Log4j in the widely used UniFi network monitoring system to gain reverse shell by manipulating a POST header.

Enumeration

The nmap scan shows that port 8080 is running a http-open-proxy that is redirecting incoming requests to port 8443.

nmap

Visiting webpage at https://10.129.43.28:8443 displays the login page of the UniFi Network Application, along with its version number 6.4.54, developed by Ubiquiti.

Googling its version number reveals that this specific version if vulnerable to Log4Shell (CVE-2021-44228), also known as Log4j.

website

Exploitation

According to the article, the login POST request needs to be intercepted, so that it can be modified and the malicious payload can be added.

website

The value of the remember parameter should be enclosed in quotation marks (") to ensure it is parsed as a string, rather than as a JSON object.

payload

The response contains api.errInvalidPayload however, despite the error message, the payload is successfully executed.

response

tcpdump confirms that the connection was indeed received on port 389 (LDAP).

tcpdump

Prior to crafting the payload, I have installed Open-JDK by issuing sudo apt install openjdk-11-jdk -y and maven with sudo apt-get install maven.

Then, I have cloned and built the package. The build process will create a file called RogueJndi-1.1.jar in the rogue-jndi/target directory.

git clone https://github.com/veracode-research/rogue-jndi
cd rogue-jndi
mvn package

The payload will be responsible for creating a shell on the target system and will be Base64 encoded.

payload-encode

The payload should be then passed to Rogue-JNDI, along with a chosen port (1234), and the IP address of the attacker machine (--hostname).

The server is now listening on port 1389 to the incoming connection.

rogue-jndi

To capture the reverse shell, a netcat listener should be opened listening on port 1234, as defined in the payload.

netcat

Now, the payload should be modified include port 1389 in Burp Suite's Repeater.

execute

Upon receiving the incoming connection, the netcat listener spawns a reverse shell, which can be upgraded to an interactive shell with script /dev/null -c bash.

interactive-shell

The currently authenticated user is unifi with uid=999.

user-enumeration

The user flag can be found in /home/michael/user.txt.

user-flag

Privilege escalation

After a bit of searching on the internet, MongoDB is being used by UniFi to store and share the SSH secrets between appliances. MongoDB is indeed running on the system on port 27117.

mongo

With the mongo command line utility the hash of the administrator's password can be revealed in the x_shadow variable.

admin

This discovered hash can be replaced, but prior to that, a new password (pass1234) must be created and hashed.

pass-hash

The current hash can be replaced using the following mongo command.

update-pass-hash

With the new password hash in place, it is now possible to authenticate to the UniFi Network Application.

login

The authentication is successful, and the dashboard is displayed.

dashboard

Under settings, the password for the SSH connection can be read in plain text.

passwd

With the found password it is now possible to authenticate to the target via SSH.

ssh

The root flag can be found in the home directory of the root user.

root-flag

With the root flag, the machine is now pwned.

Mitigation

  1. Update the Log4j library

    • Upgrade to the latest possible version of Log4j, where the vulnerability has been fixed
  2. Network segmentation

    • Limit the exposure of critical services to trusted networks (e.g., VPN) only
  3. Web Application Firewall

    • Implement a WAF to block malicious payloads attempting JNDI injection
  4. Secure MongoDB access

    • Require authentication for MongoDB and restrict remote access
  5. Limit privileges

    • Run services with the least privilege necessary