Created
April 4, 2024 02:29
-
-
Save Dump-GUY/905012a32c00d1fc94408431e2a1386a to your computer and use it in GitHub Desktop.
PowerShell IEX Hooking via Harmony Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Harmony Reference: https://github.com/pardeike/Harmony | |
using assembly '.\net48\0Harmony.dll' | |
using namespace HarmonyLib | |
class HooK | |
{ | |
static [bool] PreFix_IEX($scriptText) | |
{ | |
[Console]::WriteLine("Original IEX Command: '$scriptText'") | |
return $true | |
} | |
} | |
function Hook-IEX() | |
{ | |
[Harmony]$Global:harmony = [Harmony]::new("IEXPatch") | |
$target = [AccessTools]::Method("System.Management.Automation.CommandInvocationIntrinsics:NewScriptBlock") | |
$patch = ([HooK]).GetMethod("PreFix_IEX") | |
$Global:harmony.Patch($target, [HarmonyMethod]::new($patch)) | Out-Null | |
} | |
function UnHook-IEX() | |
{ | |
$Global:harmony.UnpatchAll() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More info: https://x.com/vinopaljiri/status/1775717012112617580