Conversor
Full name: Kravtsov Nikolay Dmitrievich
Educational institution: **** **** *****
Grade: 11
Conversor
1. Initial analysis
nmap -sCV -Pn -p- -n -T3 10.129.5.133
Two ports are open. As in the previous challenge, we focus on the web server, add conversor.htb to /etc/hosts, and inspect the site.
2. Obtaining the user flag
Because Now I’m sitting on a VPS, I don’t have access to the graphical interface, so the first thing I did was not go to the site, but immediately started scanning directories using the dirsearch utility. There were three - /register and /login, ordinary directories, and /about - quite suspicious. On the about directory after the request
curl http://conversor.htb/about
I discovered an interesting thing - there was the source code of the server. I downloaded it immediately.
After analysis, I found that the / endpoint has XML and XLST files loaded. XXE is not here - no_network is enabled on the /convert endpoint when parsing XML, but there is XLST injection. I discovered this almost immediately and started preparing a reverse shell. First, you should register and log in. This can be done with two commands, which is what I did.
curl -X POST http://conversor.htb/register -d "username=attacker" -d "password=attacker123"
Then
curl -X POST http://conversor.htb/login -d "username=attacker" -d "password=attacker123" -c cookies.txt
Next we had to prepare the payloads. We make the XML file as simple as possible - simply, in fact, empty.
Next, I created a payload that forwards the shell to my attacking ip:
Here it is necessary to make an important clarification - the payload works because in the source code we read, there is a readme file in which it is written in plain text that the system runs .py files in the directory every 60 seconds /var/www/conversor.htb/scripts:
If you want to run Python scripts (for example, our server deletes all files older than 60 minutes to avoid system overload), you can add the following line to your /etc/crontab:
* * * * * www-data for f in /var/www/conversor.htb/scripts/*.py; do python3 "$f"; done
All that remains is to upload the payload and wait for the cron job to run.
curl -X POST http://conversor.htb/convert -b cookies.txt -F "xml_file=@dummy.xml" -F "xslt_file=@sploit.xslt"
nc -lvnp 1234
Having received the shell, we immediately jump to conversor.htb/instance/, because, judging by app.py, the database file is located there. We connect using sqlite3 and look at it. There you can find two tables: users and uploads. Uploads is useless to us - there is only my vulnerable XLST file, but users is where we can try to get the password of another user or even root.
We obtained the password hash for fismathack. We submitted it to https://crackstation.net/ you can get the password.
Now you can log in via ssh and immediately receive the user flag.
22efa43c40beaa289eff96756af09070
3. Obtaining the root flag
I didn’t even need to load the scripts - after my first command 'sudo -l' the result was NOPASSWD:
After looking at the version and googling it, I found out that it is vulnerable to CVE-2024-48990. Digging a little deeper, I understood how it works:
needrestart reads environment variables such as PYTHONPATH and RUBYLIB from user processes through /proc/[pid]/environ. It then uses those variables when running interpreters as root to check installed modules. This creates a privilege escalation path:
- The user starts a Python process given PYTHONPATH=/tmp/.m
- needrestart retrieves this environment variable from /proc/{PID}/environ
- needrestart runs Python as root with attacker rights
- The attacker posts malicious code importlib/init.so in a specific directory
- Python initialization loads and executes attacker code as root
- The malicious code creates a bash executable with the SETUID bit belonging to the root user
- The user runs SETUID bash to gain root privileges.
Mladicstefan has a good POC of this vulnerability at Github.
After exploitation, I received a shell from the root user on the machine and read root.txt.
cd320d46c027a1e79aad949340f4b1e1
4. Vulnerability Summary
| Stage/Vulnerability | Type of impact | CVSS score | Possible consequences | Result |
|---|---|---|---|---|
| Source code disclosure | Information Disclosure | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N 5.3 (MEDIUM) |
1. speed up development of exploits 2. detection of hidden endpoints 3. revealing paths to files and cron tasks |
Discovering the XSLT Injection vulnerability and understanding how to exploit it |
| XSLT Injection | RCE (www-data) | CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H 8.8 (HIGH) |
1. full control over the web application 2. access to the file system 3. the possibility of further escalation of privileges |
Getting Reverse Shell |
| Weak hashes | Brute Force or finding a password using leaks | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N 7.8 (HIGH) |
1. access via SSH further 2. escalation of privileges 3. lateral movement |
Account compromise |
| Insecure cron | Persistence/RCE | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H 8.0 (HIGH) |
1. establishing persistence 2. execution of malicious code 3. installation of backdoors |
Obtaining a reverse shell and establishing persistence |
| CVE-2024-48990 | Privilege Escalation | CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H 8.4 (HIGH) |
1. full control over 2. system access to sensitive data 3. establishing stealthy persistence |
Complete compromise of the machine |
5. Complete chain of compromise
- Source code disclosure via /about
- XSLT processing analysis
- XSLT Injection => uploading a Python payload
- Cronjob => execution of payload
- Reverse shell (www-data)
- SQLite access => user hash
- Password guessing => SSH access
- sudo needrestart => exploitation CVE-2024-48990
- Getting root
6. Remediation recommendations
- Protect source code: Necessary: 1. Remove access to code from the web application 2. Deny test endpoints (allow only for certain users/IP) 3. Use the Production configuration, not Debug or Dev.
Protect from XSLT-Injection:
Необходимо: 1. Запретить загрузку XSLT от пользователей 2. Если все-таки необходимо – проверять на наличие ссылок типа file:/// или reverse shell скриптов/других подобных вещей 3. Обрабатывать XML.Protect from XSLT-Injection:
Необходимо сделать все аналогично прошлой машине: использовать более сложные алгоритмы хэширования и т.д.Protect cron tasks:
Необходимо: 1. Проверять скрипты 2. Запретить выполнение вредоносных скриптов 3. Использовать отдельную директорию с определенными правами.Fix CVE-2024-48990:
Необходимо: 1. Обновить пакет needrestart 2. Убрать NOPASSWD из /etc/sudoers 3. Использовать secure_path для sudoers