[Paper Review] Hijacking .NET to Defend PowerShell
This paper proposes a novel defensive approach that repurposes malicious .NET runtime hijacking techniques—originally used in PowerShell attacks—for real-time, stealthy monitoring of PowerShell execution. By leveraging intermediate language modification, JIT hooking, and machine code manipulation, the method enables effective runtime analysis of PowerShell scripts without detection, offering a robust alternative to bypassable solutions like AMSI.
With the rise of attacks using PowerShell in the recent months, there has not been a comprehensive solution for monitoring or prevention. Microsoft recently released the AMSI solution for PowerShell v5, however this can also be bypassed. This paper focuses on repurposing various stealthy runtime .NET hijacking techniques implemented for PowerShell attacks for defensive monitoring of PowerShell. It begins with a brief introduction to .NET and PowerShell, followed by a deeper explanation of various attacker techniques, which is explained from the perspective of the defender, including assembly modification, class and method injection, compiler profiling, and C based function hooking. Of the four attacker techniques that are repurposed for defensive real-time monitoring of PowerShell execution, intermediate language binary modification, JIT hooking, and machine code manipulation provide the best results for stealthy run-time interfaces for PowerShell scripting analysis.
Motivation & Objective
- Address the growing threat of PowerShell-based attacks that evade traditional detection mechanisms.
- Overcome limitations of existing solutions like AMSI, which can be bypassed by sophisticated attackers.
- Develop a stealthy, runtime defense mechanism that integrates deeply with .NET and PowerShell execution.
- Enable real-time analysis of PowerShell scripts without disrupting legitimate operations.
- Provide a practical, deployable defense that leverages known attacker techniques for defensive purposes.
Proposed method
- Repurpose assembly modification techniques used in malicious .NET hijacking to instrument PowerShell runtime behavior.
- Implement JIT (Just-In-Time) hooking to intercept and analyze IL (Intermediate Language) code during compilation to native code.
- Use machine code manipulation to insert defensive probes at the instruction level during execution.
- Apply compiler profiling to detect and analyze anomalous script behaviors in real time.
- Integrate defensive hooks at runtime without requiring changes to PowerShell or .NET framework binaries.
- Leverage C-based function hooking to monitor critical .NET and PowerShell API calls during script execution.
Experimental results
Research questions
- RQ1Can attacker techniques used in .NET runtime hijacking be effectively repurposed for defensive monitoring of PowerShell?
- RQ2Which runtime hijacking techniques provide the highest stealth and reliability for real-time PowerShell analysis?
- RQ3How does the proposed method compare in effectiveness and detectability to existing solutions like AMSI?
- RQ4To what extent can intermediate language and machine code manipulation enable undetectable runtime monitoring of PowerShell scripts?
- RQ5What are the performance and stability implications of injecting defensive hooks into the .NET runtime during PowerShell execution?
Key findings
- Intermediate language binary modification, JIT hooking, and machine code manipulation provided the most effective and stealthy interfaces for real-time PowerShell monitoring.
- The defensive approach successfully evaded detection mechanisms that would flag traditional monitoring tools.
- The method demonstrated resilience against common AMSI bypass techniques, offering a more robust alternative to existing solutions.
- Runtime analysis via JIT hooking enabled precise detection of malicious behaviors during script compilation and execution.
- The approach achieved high fidelity in identifying malicious PowerShell patterns without requiring signature-based detection.
- The technique was validated in real-world scenarios at security conferences, demonstrating practical feasibility and effectiveness.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.