Basic PowerShell for Pentesters
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Default PowerShell locations
C:\windows\syswow64\windowspowershell\v1.0\powershell
C:\Windows\System32\WindowsPowerShell\v1.0\powershellBasic 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
Download & Execute in background with AMSI Bypass
Using b64 from linux
Download
System.Net.WebClient
Invoke-WebRequest
Wget
BitsTransfer
Base64 Kali & EncodedCommand
Enable WinRM (Remote PS)
Disable Defender
AMSI bypass
amsi.dll is loaded into your process, and has the necessary exports for any application interact with. And because it's loaded into the memory space of a process you control, you can change its behaviour by overwriting instructions in memory. Making it not detect anything.
Therefore, the goal of the AMSI bypasses you will are to overwrite the instructions of that DLL in memory to make the detection useless.
AMSI bypass generator web page: https://amsi.fail/
AMSI Bypass 2 - Managed API Call Hooking
Check this post for detailed info and the code. Introduction:
This new technique relies upon API call hooking of .NET methods. As it turns out, .NET Methods need to get compiled down to native machine instructions in memory which end up looking very similar to native methods. These compiled methods can hooked to change the control flow of a program.
The steps performing API cal hooking of .NET methods are:
Identify the target method to hook
Define a method with the same function prototype as the target
Use reflection to find the methods
Ensure each method has been compiled
Find the location of each method in memory
Overwrite the target method with instructions pointing to our malicious method
AMSI Bypass 3 - SeDebug Privilege
Following this guide & code you can see how with enough privileges to debug processes, you can spawn a powershell.exe process, debug it, monitor when it loads amsi.dll and disable it.
AMSI Bypass - More Resources
PS-History
Find a newer files
Options : CreationTime, CreationTimeUtc, LastAccessTime, LastAccessTimeUtc, LastWriteTime, LastWriteTimeUtc
Get permissions
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/SharpViewUsers
Secure String to Plaintext
Or directly parsing form XML:
SUDO
Groups
Clipboard
Processes
Services
Password from secure string
Scheduled Tasks
Network
Port Scan
Interfaces
Firewall
Route
ARP
Hosts
Ping
SNMP
Converting the SDDL String into a Readable Format
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Last updated