Basic PowerShell for Pentesters

Default PowerShell locations

C:\windows\syswow64\windowspowershell\v1.0\powershell
C:\Windows\System32\WindowsPowerShell\v1.0\powershell

Basic 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:

  1. Identify the target method to hook

  2. Define a method with the same function prototype as the target

  3. Use reflection to find the methods

  4. Ensure each method has been compiled

  5. Find the location of each method in memory

  6. 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/SharpView

Users

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

Last updated