Lab 7.1: Enumeration des Services Windows
Objectifs d'Apprentissage
A la fin de ce laboratoire, vous serez capable de:
- Enumerer tous les services d'un systeme Windows
- Identifier les services vulnerables
- Comprendre les risques de securite lies aux services
- Creer des rapports d'audit des services
Duree Estimee
40 minutes
Prerequis
- VM Windows 10/11
- Droits administrateur
- Connaissances PowerShell de base
Contexte Professionnel
L'enumeration des services est essentielle pour:
- Les audits de securite
- La detection de malwares persistants
- L'optimisation des performances
- La conformite reglementaire
Partie 1: Enumeration Basique
Etape 1.1: Utiliser services.msc
- Ouvrez
services.msc - Observez la liste des services
- Triez par "Etat" pour voir les services actifs
Question 1: Combien de services sont en cours d'execution?
Etape 1.2: Enumeration PowerShell
# Tous les services
Get-Service | Measure-Object
# Services en cours d'execution
Get-Service | Where-Object {$_.Status -eq "Running"} | Measure-Object
# Services arretes
Get-Service | Where-Object {$_.Status -eq "Stopped"} | Measure-Object
Question 2: Combien de services sont arretes?
Etape 1.3: Details des services
# Voir les details
Get-Service | Select-Object Name, DisplayName, Status, StartType |
Sort-Object Status -Descending |
Format-Table -AutoSize
Partie 2: Enumeration Avancee avec WMI
Etape 2.1: Informations detaillees
WMI fournit plus d'informations que Get-Service:
Get-WmiObject Win32_Service | Select-Object `
Name,
DisplayName,
State,
StartMode,
@{N='Account';E={$_.StartName}},
PathName |
Format-Table -AutoSize
Etape 2.2: Services par compte d'execution
# Grouper par compte
Get-WmiObject Win32_Service |
Group-Object StartName |
Select-Object Count, Name |
Sort-Object Count -Descending
Question 3: Quel compte execute le plus de services?
Etape 2.3: Services LocalSystem (haut privilege)
# Services s'executant en tant que LocalSystem
Get-WmiObject Win32_Service |
Where-Object {$_.StartName -eq "LocalSystem"} |
Select-Object Name, DisplayName, State, PathName |
Format-Table -AutoSize
Question 4: Combien de services s'executent en tant que LocalSystem?
Partie 3: Detection de Vulnerabilites
Etape 3.1: Chemins non quotes (Unquoted Service Paths)
Les chemins avec espaces sans guillemets sont vulnerables:
# Detecter les chemins non quotes
Get-WmiObject Win32_Service | Where-Object {
$_.PathName -notmatch '^"' -and
$_.PathName -match ' ' -and
$_.PathName -notmatch '^[A-Za-z]:\\Windows'
} | Select-Object Name, PathName
Explication:
Si un service a le chemin C:\Program Files\App\service.exe, Windows cherchera dans l'ordre:
C:\Program.exeC:\Program Files\App\service.exe
Un attaquant peut placer C:\Program.exe pour detourner l'execution.
Etape 3.2: Permissions sur les executables
# Verifier les permissions des binaires de service
Get-WmiObject Win32_Service | ForEach-Object {
$serviceName = $_.Name
$path = $_.PathName
# Extraire le chemin de l'executable
if ($path -match '^"([^"]+)"') {
$exePath = $matches[1]
} elseif ($path -match '^(\S+)') {
$exePath = $matches[1]
} else {
$exePath = $path
}
if (Test-Path $exePath -ErrorAction SilentlyContinue) {
$acl = Get-Acl $exePath -ErrorAction SilentlyContinue
# Verifier si des utilisateurs non-admin ont le droit d'ecriture
$vulnerable = $acl.Access | Where-Object {
($_.IdentityReference -match "Users|Everyone|Authenticated") -and
($_.FileSystemRights -match "Write|Modify|FullControl")
}
if ($vulnerable) {
[PSCustomObject]@{
Service = $serviceName
Path = $exePath
VulnerableACL = $true
}
}
}
} | Format-Table -AutoSize
Etape 3.3: Services avec chemins suspects
# Services dans des chemins inhabituels
Get-WmiObject Win32_Service | Where-Object {
$_.PathName -match "\\Temp\\" -or
$_.PathName -match "\\AppData\\" -or
$_.PathName -match "\\Downloads\\" -or
$_.PathName -match "\\Desktop\\"
} | Select-Object Name, DisplayName, PathName
Question 5: Y a-t-il des services dans des chemins suspects?
Partie 4: Analyse des Dependances
Etape 4.1: Services critiques
# Services dont d'autres dependent
Get-Service | ForEach-Object {
$service = $_
$dependents = Get-Service -DependentServices $service.Name -ErrorAction SilentlyContinue
if ($dependents.Count -gt 0) {
[PSCustomObject]@{
Service = $service.DisplayName
DependentCount = $dependents.Count
Dependents = ($dependents.DisplayName -join ", ")
}
}
} | Where-Object {$_.DependentCount -gt 0} |
Sort-Object DependentCount -Descending |
Select-Object -First 10
Etape 4.2: Chaine de dependances
# Voir les dependances d'un service specifique
$serviceName = "Dnscache"
Write-Host "=== $serviceName ===" -ForegroundColor Cyan
Write-Host "`nServices requis:" -ForegroundColor Yellow
Get-Service $serviceName -RequiredServices | Select-Object DisplayName, Status
Write-Host "`nServices dependants:" -ForegroundColor Yellow
Get-Service $serviceName -DependentServices | Select-Object DisplayName, Status
Partie 5: Rapport d'Audit
Etape 5.1: Script d'audit complet
# Script d'audit des services
$reportPath = "$env:USERPROFILE\Desktop\audit_services.txt"
$report = @"
================================================================================
RAPPORT D'AUDIT DES SERVICES WINDOWS
$(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
================================================================================
RESUME
------
"@
# Statistiques
$allServices = Get-WmiObject Win32_Service
$running = ($allServices | Where-Object {$_.State -eq "Running"}).Count
$stopped = ($allServices | Where-Object {$_.State -eq "Stopped"}).Count
$auto = ($allServices | Where-Object {$_.StartMode -eq "Auto"}).Count
$report += @"
Total des services: $($allServices.Count)
En cours d'execution: $running
Arretes: $stopped
Demarrage automatique: $auto
SERVICES PAR COMPTE D'EXECUTION
-------------------------------
"@
$byAccount = $allServices | Group-Object StartName | Sort-Object Count -Descending
foreach ($group in $byAccount) {
$report += "`n$($group.Name): $($group.Count)"
}
# Chemins non quotes
$unquoted = $allServices | Where-Object {
$_.PathName -notmatch '^"' -and
$_.PathName -match ' ' -and
$_.PathName -notmatch '^[A-Za-z]:\\Windows'
}
$report += @"
VULNERABILITES POTENTIELLES
---------------------------
Chemins non quotes: $($unquoted.Count)
"@
if ($unquoted) {
foreach ($svc in $unquoted) {
$report += "`n - $($svc.Name): $($svc.PathName)"
}
}
# Chemins suspects
$suspect = $allServices | Where-Object {
$_.PathName -match "\\(Temp|AppData|Downloads|Desktop)\\"
}
$report += "`n`nServices dans chemins suspects: $($suspect.Count)"
if ($suspect) {
foreach ($svc in $suspect) {
$report += "`n - $($svc.Name): $($svc.PathName)"
}
}
$report += @"
================================================================================
FIN DU RAPPORT
================================================================================
"@
# Sauvegarder
$report | Out-File $reportPath -Encoding UTF8
Write-Host "Rapport sauvegarde: $reportPath" -ForegroundColor Green
# Afficher
$report
Etape 5.2: Executer l'audit
# Executer le script
.\audit_services.ps1
Livrables
-
Reponses aux 5 questions
-
Rapport d'audit genere par le script
-
Captures d'ecran:
- services.msc
- Resultat de l'enumeration PowerShell
- Services potentiellement vulnerables
-
Analyse (1 page):
- Observations principales
- Risques identifies
- Recommandations
Criteres d'Evaluation
| Critere | Points |
|---|---|
| Enumeration basique | 20% |
| Enumeration WMI | 20% |
| Detection vulnerabilites | 30% |
| Rapport d'audit | 30% |
Commandes de Reference
# Services
Get-Service
Get-WmiObject Win32_Service
# Filtrage
Where-Object {$_.Status -eq "Running"}
# Selection
Select-Object Name, DisplayName, Status
# Groupement
Group-Object StartName
# ACL
Get-Acl chemin
Lab developpe dans le cadre du cours Systemes d'Exploitation - MODULE 7