Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Converts .NET assemblies into AutoIt script Base64 variables
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