Enumeration

Be aware sometimes these commands require elevated privileges to be run, or may be blocked by GPO or other means (JEA for example).

Most commands that run in cmd.exe will also run in PowerShell! This gives many more options and provides flexibility at times. Some commands may not work directly though, and will need to be run through cmd.exe by prefixing the commands with cmd /c

https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/winPEAS = My favorite Windows enumeration script, automates most common enumeration methods.

User Enumeration

Get user information

$env:username Displays the current user's display name

Get-LocalUser | Select * Display usernames, password and account expiration, SID, Description, enabled status

Groups

[Security.Principal.WindowsIdentity]::GetCurrent() Not very good output by default, need to manipulate the object a bit to get the desired information

The below example is better. Will display group name and SIDs. Still not the same as whoami /all though.

$tableLayout = @{Expression={((New-Object System.Security.Principal.SecurityIdentifier($_.Value)).Translate([System.Security.Principal.NTAccount])).Value};Label=”Group Name”},
@{Expression={$_.Value};Label=”Group SID”},
@{Expression={$_.Type};Label=”Group Type”}

([Security.Principal.WindowsIdentity]::GetCurrent()).Claims | Format-Table $tableLayout -AutoSize

List users' home folders

Get-ChildItem 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\ProfileList' | ForEach-Object { $_.GetValue('ProfileImagePath') }

Using WMI

Use either Get-WmiObject or Get-CimInstance to pull information about all local accounts. This can also be used remotely, and to query information about AD accounts.

Get-CimInstance -ComputerName $env:computername -Class Win32_UserAccount -Filter "LocalAccount=True" | Select PSComputername, Name, Status, Disabled, AccountType, Lockout, PasswordRequired, PasswordChangeable | Out-GridView

#Get Current or last logged in username
$CurrentUser = Get-CimInstance -ComputerName $Computer -Class Win32_ComputerSystem | Select-Object -ExpandProperty UserName

Get-WmiObject has been deprecated. Only use it if Get-CimInstance is not available due to outdated PowerShell version or problems with Windows Remoting. In most cases the two command names should be replaceable with no issues.

Using ADSI

Can be run on remote machines by substituting $env:computername with the computer name of the remote machine. This returns a large amount of useful information on all users.

There is a property called Password, though this did not return anything on my Microsoft Account-enabled machine. Will have to try this on a domain or local account.

Get list of users

Get list of local users

Inferring from user's home folders

Using WMI

Gets display name, description, lockout status, password requirements, login name and domain, and SID.

If run on a domain connected machine dumps all accounts on the whole domain! On a non-domain joined machine lists all local users. Includes Service Accounts.

Groups

Get list of local groups

List group members

PrincipleSource will tell you whether the account is a local, domain, or Microsoft account.

Check for AutoLogon accounts

Active Directory

Enumeration without Active Directory module installed

Using WMI Query Language (WQL)

WQL is an entire subject on its own. If you want to know the full extent of the capabilities of this powerful query language, type Get-Help WQL in a PowerShell prompt. Below are a few examples of queries to pull lists of users from both local machines and from the domain.

WQL uses the backslash (\) as its escape character. This is different from Windows PowerShell, which uses the backtick character (`).

LAPS

LAPS allows you to manage the local Administrator password (which is randomized, unique, and changed regularly) on domain-joined computers. These passwords are centrally stored in Active Directory and restricted to authorized users using ACLs. Passwords are protected in transit from the client to the server using Kerberos v5 and AES.

When using LAPS, two new attributes appear in the computer objects of the domain: ms-msc-AdmPwd and ms-mcs-AdmPwdExpirationTime. These attributes contains the plain-text admin password and the expiration time. In a domain environment, it could be interesting to check which users can read these attributes.

Find Administrator Accounts

TODO: Add more examples

Many administrators set their account passwords to never expire, so searching for these can be valuable. Also, this means the password may have been set a long time ago.

Search for passwords

Search for keyword in registry

The /f flag specifies the keyword to search for. In this case the word "password".

Search in Credential Manager

Check SAM and SYSTEM registry hives

If you can access these files and copy them, you can dump credentials for the system.

ntdsutil

The NTDSUtil "Install from media" (IFM) feature can be used to backup NTDS.dit with the one-liner below.

vssown.vbs

  1. Check the status of the Volume Shadow Copy Service (VSS)

2. Start the volume shadow backup service if it is not currently running.

3. Create a backup of the drive

4. Extract any files that were in use that are of interest (ntds.dit/SAM hive, etc.)

File Permissions

Find files/folders where the "Everyone" group has permissions.

This will recursively search the "Program Files" folders, ignoring (most) errors.

More good groups to search for would be the "BUILTIN\Users" or "Domain Users" groups.

Using accesschk.exe (SysInternals)

You can also use accesschk.exe from Sysinternals to check for writeable folders and files.

OS Information

Get OS Version information

Get basic Windows information

Get-ComputerInfo Gives a ton of information about the current hardware and Windows configuration

Get installed patches

Use the -description "Security update" attribute of Get-Hotfix to list only security updates

Drivers

Get a list of installed drivers

Requires an elevated PowerShell prompt:

Specifies that the action is to be taken on the operating system that is currently running on the local computer.

Default log path

$env:windir\Logs\Dism\dism.log

Make back up of all installed drivers

List Environment Variables

Show all current environment variables: Get-ChildItem Env:

Also aliased to: dir env: or ls env: or gci env:

Check Audit (logging) Settings

These settings show what is being logged, this can be useful information for evasion and persistence

Add the -Name $KeyName property to get the value of a specific key.

Windows Event Forwarding

Check where the logs are sent:

Add the -Name $KeyName property to get the value of a specific key.

Antivirus

Check if there is any antivirus installed:

Windows Firewall

Check the status of the Windows Firewall

Use the -Name Public property (instead of -All) to select a specific firewall profile. Pipe the results to | Get-NetFirewallRule to see the currently configured rules.

Clipboard

Get the contents of the clipboard

Get-Clipboard

Software, Services, and Processes

Software

List the installed software

The below PowerShell script will return a more complete list of all software installed by querying SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall on a list of computer names. It displays the following information:

  • Computer Name,

  • Software Name,

  • Version,

  • Publisher

Uninstall Software

If Get-CimInstance is not able to find your software, you can try this instead:

To get PowerShell to display all the programs in the Control Panel, use an asterisk in place of the Name parameter.

This command only uninstalls the latest version of a program. If you’ve installed multiple versions use the -RequiredVersion 2.0 property of Get-Package to specify the version to uninstall.

Services

Get a list of services:

Get-Service

Get detailed information for a specific service

sc qc $service_name

Enable a disabled service

If you are having this error (for example with SSDPSRV):

System error 1058 has occurred. The service cannot be started, either because it is disabled or because it has no enabled devices associated with it. You can enable it using:

Note: In Windows XP SP1, the service upnphost depends on SSDPSRV to work

Unquoted service paths

Unquoted service paths are paths to services that contain a space in them, that are not surrounded by quotes. These paths can be hijacked to run arbitrary code if the break in the path is a writeable location.

Get running processes

Get-Process

With usernames of process owner

*Admin rights needed to pull owner information

Without usernames

Get permissions of running process binaries

Make sure to also check permissions of the folders of the process binaries (useful for dll injection!)

Get current network connections

View TCP port connections with PowerShell

Get-NetTCPConnection

Get listening connections:

Check for anything that’s listening from any remote address:

To get connection information for a specific port use the -LocalPort $port attribute.

Since this cmdlet returns objects, you can use these objects to return other information, such as getting the process ID associated with each connection:

View UDP port connections with PowerShell

To show listening ports filter for the address 0.0.0.0:

Use the -CimSession $CimSession Parameter to run this on a remote computer after creating a New-CimSession.

PowerShell netstat implementation

Shows TCP and UDP connections, with the following properties: Local Address, Local Port, Remote Address, Remote Port, Connection State, Process Name, and PID

TODO: Make this fully PowerShell implemented, without netstat

UDP info for updating above script (this example only shows connections for port 1900)

https://github.com/carlospolop/hacktricks/blob/master/windows/basic-cmd-for-pentesters.md#network (TODO:check for more network enumeration info here)

Startup/AutoRuns

Check which files are executed when the computer is started, or a user is logged in.

SysInternals AutoRuns

For a comprehensive list of auto-executed files you can use AutoRuns from SysInternals

To run this from a command prompt without popup windows:

autorunsc.exe -m -nobanner -a * -ct /accepteula

SMB/Samba

Port 139 and 445

Server Message Block is a service that enables the user to share files with other machines. May be able to browse files without having credentials (Null Session).

SMB Enumeration Checklist

  • Enumerate Hostname

    • nmblookup -A $ip

  • List Shares

    • smbmap -H $computer

    • echo exit | smbclient -L \\\\$ip

    • nmap --script smb-enum-shares -p 139,445 $ip

  • Check Null Sessions

    • smbmap -H $computer

    • rpcclient -U "" -N $ip

    • smbclient \\\\$ip\\$share_name

  • Check for Vulnerabilities

    • nmap --script smb-vuln* -p 139,445 $ip

  • Overall Scan

    • enum4linux -a $ip

  • Manual Inspection

    • smbver.sh $ip $port

    • Use Wireshark to check pcap

List share drives

Find all connected drives

This can show all connected hard drives, not only network fileshares

Listing all PSDrives can also give you valuable information, showing how to access environment variables, certificates, registry keys, temp folders, and more.

Check for SMB vulnerabilities:

SMB nmap scripts to enumerate shares and OS discovery

Connect using Username

Connect to Shares

Enumerate SMB shares

-a "do everything" option

Get machine name and then enumerate with smbclient

rpcclient

Connect with a null session

Common Checks

scan for vulnerabilities with nmap

Use TCPdump/Wireshark to get version

@rewardone in the PWK forums posted a script to gather Samba versions:

To get Windows SMB information open the pcap in Wireshark and filter on ntlmssp.ntlmv2_response

SNMP

SNMP is based on UDP, a simple, stateless protocol, and is therefore susceptible to IP spoofing, and replay attacks. In addition, the commonly used SNMP protocols 1, 2, and 2c offer no traffic encryption, meaning SNMP information and credentials can be easily intercepted over a local network.

MIB Tree (Management Information Base)

Scanning for SNMP

SNMP most often uses UDP port 161.

You can use a tool such as onesixtyone, which will check for given community strings against an IP list, allowing you to brute force various community strings from a list.

We can probe and query SNMP values using a tool such as snmpwalk once you know the SNMP read-only community string (which in most cases is “public”).

The notation 1.3.6.1.2.1.25.6.3.1.2 is the MIB, which is the shorthand SNMP uses to perform queries.

You can also use snmpenum and snmpcheck to gather information.

  • TODO: Everything below from the above site...in the process of verification, cleanup, and assimilation.

Windows CLI gems. Tweets of @wincmdfu

Windows one line commands that make life easier, shortcuts and command line fu.

Get entries from IPv4 neighbor cache

Get available wireless networks via cmd and netsh

Quick list IP addresses only

Save the following in ip.bat in %PATH%

Call ip from CLI

List ALL services AND their binaries

Export SAM from the Windows Registry to a file

Enable remote desktop using reg

Enable the boot log to see list of drivers loaded during startup

Read via %windir%\ntbtlog.txt

Powershell cmdlet to create System Restore Point

Check the current account for seDebugPrivilege

For all privs:

Enable/disable system users via command line

Get full help on the net user command:

View process that is consuming the most memory using powershell

Create an Alternate Data Stream from a file on an NTFS partition

Export running processes in CSV format

Lock Windows desktop using command line

Start explorer with a file or folder selected/highlighted

Dump VirtualBox image containing RAM and ELF headers

Set Time Zone of the system clock

List available Time zones:

Make folder inside a guest from the host

VirtualBox

Force copy meterpreter binary to remote machines & run as system

Create n/w share called Apps, with read access & limit to 10 conns

List all the drives under My Computer using fsutil

Troubleshoot n/w packet drops with router statistics using pathping

List unsigned dlls for a specific process.

For system wide list, remove the process name

Obtain a list of Windows XP computers on the domain using PS

Server2008

Open the System Properties window, with the Advanced tab selected

Change the number for different tabs

Using the dir command to find Alternate Data Streams

Using streams sysinternals (shows path):

Use procdump to obtain the lsass process memory.

Use mimikatz minidump to get passwords

Run mimikatz in minidump mode & use mini.dmp from procdump

Get list of startup programs using wmic

Add a binary to an Alternate Data Stream

Execute it (XP/2K3):

Execute a binary Alternate Data Stream Win 7/2008 using wmic

Show config & state info for Network Access Protection enabled client

https://technet.microsoft.com/en-us/library/cc730902(v=ws.10).aspx

Get computer system information, including domain name and memory, using wmic

Use the Package Manager in Windows to install the Telnet client on Windows Vista & higher

Secure delete a file/folder in Windows

Sysinternals

To recursively delete folders:

Show all startup entries while hiding Microsoft entries. CSV output

It covers more locations than Windows inbuilt tools

Download files via commandline using PS

Fetch the last 10 entries from the Windows Security event log, in text format

def is XML

Create a dll that runs calc on invoke

Run a command as another user

You will be prompted for password

Get shutdown/reboot events from the last 1000 log entries using PS

Create a new snapshot of the volume that has the AD database and log files

Mount the snapshot

Copy ntds.dit from snapshot & System hive from reg for pwd hashes

Run a process on a remote system using wmic

List the machines, with usernames, that were connected via RDP

List all process that are running on your system by remote users connected via RDP

Reset the Windows TCP\IP stack

List logged on users.

Very useful during a pentest to look for domain admins

Set a static IP on a remote box

Bypass powershell execution policy restrictions

List running processes every second on a remote box

Remove /node:target for localhost

Get a list of running processes and their command line arguments on a remote system

Remotely enable and start the Volume Shadow Copy Service

Ping multiple IPs from ips.txt & see live hosts

Set global proxy in Windows to point to IE proxy

Enumerate list of drivers with complete path information

View Group Policy Objects that have been applied to a system

Very useful during pentests

Reset the WMI repository to what it was when the OS was installed

Very helpful if you have a corrupt repo

Enable the tftp client in Vista & higher

Pull files to a compromised server:

Obtain list of firewall rules on a local system

Can be combined with wmic for remote systems

Get name of current domain controller

Get list of all DCs:

Look at content cached in kernel mode on IIS 7 and higher

Useful when investigating the MS15-034 HTTP.sys vuln

Quick test to check MS15_034

HTTP 416 = Vulnerable

HTTP 20X = Not vulnerable

Get a list of all open Named pipes via Powershell

Possible VENOM detection on VirtualBox

Search 'Storage' & 'Floppy'

List RDP sessions on local or remote in list format

Get a list of service packs & hotfixes using wmic for remote systems listed in file

Export wireless connection profiles

key=clear allows plain text passwords

Unzip using PowerShell

Open the Network & Sharing center

Create a shortcut of this as ns in PATH for ease

Remotely stop/start ftp on several systems

To quickly find large files using cmd

Run from the dir you want

List scheduled tasks & binaries

Weak permissions can be exploited for localprivilege escalation

Display the "Stored User names and Passwords" window

List namespaces & classes in WMI via PowerShell

Convert Between VDI, VMDK, VHD, RAW disk images using VirtualBox

Change file extensions recursively

csv to xls example

List IPs of running VirtualBox machines

Windows Privilege Escalation Slideshow

Windows Privilege Escalation

Enumerate packages with their OEM .inf filenames

Install a driver package using .inf file

Malware Hunting with Mark Russinovich and the Sysinternals

Malware Hunting with Mark Russinovich and the Sysinternals Tools

Windows Nano Server APIs

https://msdn.microsoft.com/en-us/library/mt588480(v=vs.85).aspx

Start a Wi-Fi hotspot using cmd.exe

Open cmd.exe in admin mode

Disable UAC via cmdline

Turn off Windows firewall for all profiles

Useful if you have a bind shell

List Missing Updates

Export SAM and SYSTEM Dump password hashes offline

Convert Binary to base64 string to transfer across restricted RDP

Convert Base64 string to Binary

List services running as SYSTEM and possibly weak file permissions

Check Bitlocker status on a remote box

Use wmic /node:@ips.txt & process alias for multiple.

Export failed logon attempts

Alternate Data Streams and PS

  • List all ADS for all files in current dir

  • Read ADS

  • Create ADS using text input

  • Delete ADS

Run the Windows Assessment tool for cpu and ram and disk

Port forward (proxy) traffic to remote host and port

Enable/Disable NetBIOS over TCP/IP

Compact multiple VDI files across folders

Full scan using WinDefender

Generate 32 char random password

Misc

echo %cd% - Same as pwd in Linux

Find files by name with cmd.exe

For files in %PATH%

where $filename

For files not in %PATH%

Find file by name with PowerShell

Get-Childitem -Path C: -Recurse -ErrorAction SilentlyContinue | ? {$_.Name = $filename}

  • you can use wildcards here for name and for extension (e.g. pass* could match password)

Resolve IP to Hostname

[System.Net.Dns]::GetHostByAddress('$IP').HostName

PowerShell 'Watch' Command

while (1) { $command_to_watch ; sleep 5}

Get WiFi Passwords

First, you have to know the SSID of the access point (AP) to get the password from

Next, get the cleartext password:

Gather hostnames of machines on a network

Winpeas

winpeas.exe cmd searchall searchfast #cmd commands, search all filenames and avoid sleeping (noisy - CTFs)

winpeas.exe #Will execute all checks except the ones that use a CMD

winpeas.exe cmd #All checks

winpeas.exe systeminfo userinfo #Only systeminfo and userinfo checks executed

winpeas.exe notcolor #Do not color the output

winpeas.exe cmd wait #cmd commands and wait between tests

In Linux the ouput will be colored using ANSI colors. If you are executing winpeas.exe from a Windows console, you need to set a registry value to see the colors (and open a new CMD): REG ADD HKCU\Console /v VirtualTerminalLevel /t REG_DWORD /d 1

References

If you like this content and would like to see more, please consider buying me a coffee!

Last updated