Cyber Security

New ScriptBlock Smuggling Attack Let Ackers Bypass PowerShell Security Logs And AMSI

Ever since the introduction of PowerShell v5, there have been less usage of the application specifically among threat actors, penetration testers and red teamers.

This is because PowerShell v5 introduced PowerShell security logging which allows Blue teams with additional options to prevent powershell based threats.

There were several techniques introduced later to bypass this PowerShell security logging like AMSI (Antimalware Scan Interface) bypasses and ScriptBlock logging bypasses.

However, all of these techniques involved completely disabling the logging instead of spoofing the logs.

Scan Your Business Email Inbox to Find Advanced Email Threats - Try AI-Powered Free Threat Scan

Researchers have discovered a new technique whith does not require any reflection or memory patching to be executed and that it can spoof any arbitrary message into the ScriptBlock logs while bypassing AMSI.

As an added fact, PowerShell uses AST (Abstract Syntax Trees). ASTs are tree-like structures created from source code to machine code via a compiler.

Compiler performing Source code to Machine code by AST (Source:  Pulse/LinkedIn)

Additionally, all the language compilers work in a similar way when there is a creation of ScriptBlock within PowerShell. The parent node for all the PowerShell AST is the ScriptBlock.

One of the properties used in the ScriptBlock AST is the Extent which isa string representation of our ScriptBlock.

ScriptBlock Smuggling

According to the reports shared with Cyber Security News, all the security features within the PowerShell pass only the Extent of the ScriptBlock.

Further, whenever a ScriptBlock is creating by wrapping a {} or using  [ScriptBlock]::create() the AST and subsequently the Extent are automatically generated. This can be used to build a custom AST.

The ScriptBlocks are not logged until the first time the ScriptBlock is executed. To prove this theory, researchers created a log-like Write-Output ‘Hello’ which originally executed the Write-Output ‘World’.

In addition, the executed code was not observed by the logs or AMSI. 

Logs not observed (Source: Pulse/LinkedIn)

Another test was conducted by creating a ScriptBlock with C# which executed Write-Output ‘amsicontext’ demonstrating the ability to bypass AMSI without needing any patching or reflection. 

C# based ScriptBlock (Source: Pulse/LinkedIn)

This particular behaviour can be leveraged as a basic AMSI bypass but this technique can be escalated to critical things like command hooking.

ScriptBlock smuggling allows users to spoof PowerShell security logs which will allow an unauthenticated user or threat actor to bypass all kinds of AV and EDR detections.

Free Webinar! 3 Security Trends to Maximize MSP Growth -> Register For Free

Eswar

Eswar is a Cyber security reporter with a passion for creating captivating and informative content. With years of experience under his belt in Cyber Security, he is reporting data breach, Privacy and APT Threats.

Recent Posts

FBI Reveals How Hackers Use ARTEX AI Agents to Gain Privileged Access in Under Three Hours

The FBI has warned that hackers are using ARTEX AI agents to automate network attacks,…

10 hours ago

Microsoft Warns of Active Password Stealing Attack Exploiting the Microsoft 365 Service Disruption

Microsoft has warned of an active phishing campaign using the November 12 Microsoft 365 service…

10 hours ago

Cursor Reveals How a Leaked Fireworks AI Key Led to a Backdoored Claude Code Extension

Cursor has traced its October security breach to an access key exposed by Fireworks AI.…

12 hours ago

CISA Warns of Check Point 0-Day Vulnerability Exploited to Gain Root Access

CISA has warned that attackers are exploiting a Check Point security flaw that lets a…

17 hours ago

Uber Confirms Data Breach – Hackers Stole Users’ Personal Information

Uber has confirmed a data breach involving the personal information of thousands of U.S. drivers…

20 hours ago

New TypoPrompting Attacks Turn Mistyped AI Website Addresses Into Malware Installation Traps

A simple typing mistake can now cost you more than a failed page load. Researchers…

1 day ago