Inspired by a post I saw on this sub a while back. Turns out, Powershell (and most languages apparently- I’ve replicated this in Python and C++) will allow you to do math with booleans. You can use this to build commands out of what looks like gibberish. Any boolean will work, but I chose empty arrays because it really hurts your head to read. For example: “Write-host ‘hello world'” turns into this monstrosity:
("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!!@()))") ("$((!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!!@()))") ("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!@())+(!@()))"+"$((!@())+(!@()))") ("$((!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!!@()))") ("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!!@()))") ("$((!@())+(!@())+(!@()))"+"$((!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!!@()))") ("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))") ("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!!@())+(!!@()))") ("$((!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))") <#Silly way of obfuscating code. The function converts a given command to a series of null-arrays, which can then be decoded back into the original command. To run the obfuscated command, you can invoke it like so: From file: iex ([system.text.encoding]::utf8.getstring((get-content $OutputPath | foreach {(iex $_)}))) From variable: iex ([system.text.encoding]::utf8.getstring(($obfcode | foreach {(iex $_)}))) #> Function obfuscate-mycode { [cmdletbinding()] param( [parameter(mandatory=$true)] [string[]]$MyCode, [parameter(mandatory=$false)] [string[]]$OutputPath ) $Command=($mycode).tochararray() $global:ObfCode=switch ($command) { a {'("$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} b {'("$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} c {'("$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))”)'} d {'("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!!@())+(!!@()))")'} e {'("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!!@()))")'} f {'("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+”$((!@())+(!@()))”)'} g {'("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@()))")'} h {'("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@()))")'} i {'("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@()))")'} j {'("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} k {'("$((!@())+(!!@()))"+"((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} l {'("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} m {'("$((!@())+(!!@()))"+"$((!!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} n {'("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!!@())+(!!@()))")'} o {'("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!!@()))")'} p {'("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@()))")'} q {'("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@()))")'} r {'("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@()))")'} s {'("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@()))")'} t {'("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} u {'("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} v {'("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} w {'("$((!@())+(!!@()))"+"$((!@())+(!!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} x {'("$((!@())+(!!@()))"+"$((!@())+(!@()))"+"$((!!@())+(!!@()))")'} y {'("$((!@())+(!!@()))"+"$((!@())+(!@()))"+"$((!@())+(!!@()))")'} z {'("$((!@())+(!!@()))"+"$((!@())+(!@()))"+"$((!@())+(!@())")'} 0 {'("$((!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} 1 {'("$((!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} 2 {'("$((!@())+(!@())+(!@())+(!@())+(!@()))"+"$((!!@())+(!!@()))")'} 3 {'("$((!@())+(!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!!@()))")'} 4 {'("$((!@())+(!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@()))")'} 5 {'("$((!@())+(!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@()))")'} 6 {'("$((!@())+(!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@()))")'} 7 {'("$((!@())+(!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@()))")'} 8 {'("$((!@())+(!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} 9 {'("$((!@())+(!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} ! {'("$((!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@()))")'} `" {'("$((!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@()))")'} `# {'("$((!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@()))")'} `$ {'("$((!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} `% {'("$((!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} `& {'("$((!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} `' {'("$((!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} `( {'("$((!@())+(!@())+(!@())+(!@()))"+"$((!!@())+(!!@()))")'} `) {'("$((!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!!@()))")'} `* {'("$((!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@()))")'} `+ {'("$((!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@()))")'} `, {'("$((!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@()))")'} `- {'("$((!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@()))")'} `. {'("$((!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} `/ {'("$((!@())+(!@())+(!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@())+(!@())+(!@()))")'} `{ {'("$((!@())+(!!@()))"+"$((!@())+(!@()))"+"$((!@())+(!@())+(!@()))")'} `| {'("$((!@())+(!!@()))"+"$((!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@()))")'} `} {'("$((!@())+(!!@()))"+"$((!@())+(!@()))"+"$((!@())+(!@())+(!@())+(!@())+(!@()))")'} " " {'("$((!@())+(!@())+(!@()))"+"$((!@())+(!@()))")'} } if ($outputpath -ne $null) {$ObfCode | out-file "$Outputpath"} }
submitted by /u/laserpewpewAK
[link] [comments]
The post Obfuscating code with booleans appeared first on How to Code .NET.