Windows Command Line Interface (CLI)
Powershell
Powershell is an object-oriented language. Powershell returns an object for each command which can be piped | into a function.
Recommended Tools: VS-Code
Helpful Commands
Get-Command- Lists all available commands
- Using
Get-Command -CommandType "Function"limits results to functions such as math operations
Get-Help- Can be used to explain any command
Get-Help Get-Date- Adding
-examplesshows common uses
Get-FileHash- Defaults to SHA256. Use
-Algorithm.
- Defaults to SHA256. Use
Windows commands
Get-ComputerInfoGet-LocalUser- Returns a list of all local accounts
Get-NetIPConfiguration- DNS, Gateway, Adapter descriptions
Get-NetIPAddress- Useful to determine IPv6 schemes
Invoke-Command- Uses PSRemoting (WinRM) to execute commands on a remote machine
Live commands
Get-Process- Similar to Task Manager
Get-ServiceGet-NetTCPConnection
File manipulation
New-ItemNew-Item -Path "C:\folder" -ItemType "Directory"New-Item -Path "C:\file.txt" -ItemType "File"
Remove-Item -PathCopy-Item -PathGet-Content -Path- Similar to cmd's
typeand Unix'scat
- Similar to cmd's
Aliases
- Common commands such as
cdordirare actually aliases to their Verb-Noun counterparts;Set-LocationandGet-ChildItemrespectively. - Avoid using aliases in scripts when alternatives are available. VS-Code will warn when alternatives are available.
Piping
Sort-ObjectGet-ChildItem | Sort-Object Length- Sorts the directory by file size
Where-ObjectGet-ChildItem | Where-Object -Property "Name" -like "flag*"- Recursively searches an array (or folder) for anything matching. Returns multiple objects
Operations
- ==
-eq, !=-ne, >-gt, >=-ge, <-lt, <=-le Select-String- Uses
-patternto search for Regex
- Uses
Further reading
- Modules
- Just like any other programming language, Powershell contains libraries called Modules. They can be searched using
Find-Moduleand installed usingInstall-Module.
- Just like any other programming language, Powershell contains libraries called Modules. They can be searched using
Cmd Commands
Systeminfo
- Hostname
- OS Version
- IP address + NICS
Control
- Opens control panel / settings windows
control /name Microsoft.WindowsUpdate
Tracert
Netstat
- Active connections
netstat -abon-adisplays all established connections and listening ports-bshows the program associated with each listening port and established connection-oreveals the process ID (PID) associated with the connection-nuses a numerical form for addresses and port numbers
- Check for listeners that seem suspicious (high port numbers, ESTABLISHED but not listening, incorrect port numbers)
File navigation
dir- The Windows equivalent of ls
- /a displays hidden and system files
- /s displays files in the current directory and subdirectories
- Use tree instead
mkidrandrmdir
File manipulation
type- Windows equivalent of
cat
- Windows equivalent of
more/less- Pipe long commands into more command | more
copy/movedel/erase
Tasklist
- Use filters
tasklist /?
tasklist /FI "imagename eq sshd.exe"taskkill /PID 1234- Most system tasks should be ABOVE explorer.exe
wmic
- use alias
processfor blue team- check for bad launch arguments (Ports, ips, etc)
Sysinternals
-accepteula
handle.exe
- equivalent to lsof
autorunsc
- hunt for persistence
- scans registries for autorun commands
sigcheck
- -o use virustotal