Ubuntu VM or Mac with Powershell installed??? (aka PFM)
Uses Powershell core (and doesn’t need docker, just homebrew)
Powershell Basics:
Variables:
1 2
$var1 = 5 $var2 = “55”
Operations:
Addition:
1 2
$var1 + $var2 $var2 + $var1
Why are they different?
1 2
var ++ var += 5
Equality:
1 2 3 4 5 6 7
-eq: equals -ne: not equal to -ceq: case sensitive comparison -gt: greater than -gte: greater than or equal to -lt: less than -lte: less than or equal to
Booleans:
1 2
-and -or
Conditionals:
1 2 3 4 5 6
If (<condition>){ <code/commands> } Else{ <code/commands> }
Loops:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$question = "Are we there yet?" $answer = "Noooooo!" for ($i = 3; $i-gt0; $i--){ $question sleep2 } Write-Output"`n$answer" **(`n) = new line, not \n like python/java/c
$services = get-service ForEach ($thingin$services){ $thing.name + " : " + $thing.status } Write-Output"`nThe last service is $($thing.name)"
Register-CimIndicationEvent-Query"Select * from __InstanceCreationEvent within 15 where targetInstance isa 'win32_process' and (targetinstance.name = 'notepad.exe' OR targetinstance.name = 'wordpad.exe')" ` -SourceIdentifier"trigger"-Action{Write-Output"$(get-date) - Temp WMI Register Executed Successfully" | Out-File$env:USERPROFILE\Desktop\logger.txt -Append}
Register-WmiEvent-Query"Select * from __InstanceoperationEvent within 20 where targetinstance ISA 'win32_process' AND targetinstance.name='lsass.exe'"-SourceIdentifier"beacon" ` -Action{ $socket = new-object System.Net.Sockets.TcpClient("127.0.0.1", "6602") $data = [System.Text.Encoding]::ASCII.GetBytes("This is a test") $stream = $socket.GetStream() $stream.Write($data, 0, $data.Length) }
Register-WmiEvent-Query"Select * from __InstanceModificationEvent within 30 WHERE TargetInstance ISA 'Win32_LocalTime' AND targetinstance.hour = 20 AND targetinstance.minute = 42 group within 30"-SourceIdentifier"beacon2" ` -Action{ $socket = new-object System.Net.Sockets.TcpClient("127.0.0.1", "6602") $data = [System.Text.Encoding]::ASCII.GetBytes("This is a test") $stream = $socket.GetStream() $stream.Write($data, 0, $data.Length) }
if ($PSVersionTable.PSVersion -gt [Version]"2.0") { powershell -Version2-File$MyInvocation.MyCommand.Definition exit } 'run some code'Read-Host-Prompt"Scripts Completed : Press any key to exit"