Created
November 1, 2021 23:14
-
-
Save V1V1/b3a3315a90817fef8fa0f45334e2e196 to your computer and use it in GitHub Desktop.
Converts .NET assemblies into AutoIt script Base64 variables
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
function CSharpToAutoItBase64 | |
{ | |
# This entire script is heavily adapted from - https://s3cur3th1ssh1t.github.io/Playing-with-OffensiveNim/ | |
# Huge shoutout to S3cur3Th1sSh1t (https://twitter.com/ShitSecure) for writing the original script | |
Param | |
( | |
[string] | |
$inputfile, | |
[switch] | |
$folder | |
) | |
if ($folder) | |
{ | |
$Files = Get-Childitem -Path $inputfile -File | |
$fullname = $Files.FullName | |
Write-Host "`n" | |
foreach($file in $fullname) | |
{ | |
Write-Host -ForegroundColor yellow "[*] Converting $file" | |
$outfile = $File + ".AutoItBase64.txt" | |
$base64String = [convert]::ToBase64String((Get-Content -path $File -Encoding byte)) | |
# Some string shenanigans to split the base64 assembly | |
$stringSplit = $base64String -split '(\w.{999})', 1000 | ? {$_} | |
$stringSplit = $stringSplit | Out-String | |
$stringSplit = $stringSplit.replace("`r`n","'`r`n") | |
$stringSplit = ($stringSplit.split("`n") | ForEach-Object {"`$Base64Assembly &= '$_"}) -join("`n") | |
$stringSplit = $stringSplit -replace ".{20}$" | |
# Write results | |
$stringSplit | out-file $outfile | |
} | |
Write-Host -ForegroundColor green "`n[+] Base64 conversion results written to the same folder`n" | |
} | |
else | |
{ | |
Write-Host -ForegroundColor yellow "`n[*] Converting $inputFile to AutoIt Base64`n" | |
$outFile = $inputFile + ".AutoItBase64.txt" | |
$base64String = [convert]::ToBase64String((Get-Content -path $inputFile -Encoding byte)) | |
# Some string shenanigans to split the base64 assembly | |
$stringSplit = $base64String -split '(\w.{999})', 1000 | ? {$_} | |
$stringSplit = $stringSplit | Out-String | |
$stringSplit = $stringSplit.replace("`r`n","'`r`n") | |
$stringSplit = ($stringSplit.split("`n") | ForEach-Object {"`$Base64Assembly &= '$_"}) -join("`n") | |
$stringSplit = $stringSplit -replace ".{20}$" | |
# Write results | |
$stringSplit | out-file $outFile | |
Write-Host -ForegroundColor green "`n[+] Base64 conversion results written to $outFile`n" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment