Give me an example of powershell obfuscation technique using regular expression.
- User
Give me an example of powershell obfuscation technique using regular expression.
- Assistant
Here's an example of a PowerShell obfuscation technique using regular expressions:
$cmd = @' Write-Host "Hello, World!" '@ $obfuscated = [Regex]::Replace($cmd, '.', { param($match) $chr = [Convert]::ToInt32($match.Value[0]) $hex = [Convert]::ToString($chr, 16) return [char]0x221e + "x" + $hex }) Write-Host "Obfuscated command:" Write-Host $obfuscated $deobfuscated = [Regex]::Replace($obfuscated, [char]0x221e + 'x([\da-f]{2})', { param($match) [char][Convert]::ToInt32($match.Groups[1].Value, 16) }) Write-Host "Deobfuscated command:" Write-Host $deobfuscated Invoke-Expression $deobfuscatedIn this example, we start with a simple PowerShell command stored in the variable:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.