What steps will reproduce the problem?
1. Encode a command using StringtoBase64
2. Use that command with powershell.exe -EncodedCommand <encodedstringhere>
What is the expected output? What do you see instead?
Powershell fails to execute it.
Revision 30 fixes this. Please update repos.
Original email report to me is copied below:
**************************************************************************
Hi
I found a problem about nishang on my computer.
look at the source code
StringToBase64.ps1
=========================================================================
Param( [Parameter(Position = 0, Mandatory = $True)] [String] $Str)
function StringtoBase64
{
$utfbytes = [System.Text.Encoding]::UTF8.GetBytes($Str)
$base64utfstring = [System.Convert]::ToBase64String($utfbytes)
$base64utfstring
}
StringToBase64
StringToBase64_MyTest.ps1
=========================================================================
Param( [Parameter(Position = 0, Mandatory = $True)] [String] $Str)
function StringtoBase64
{
$unicodebytes = [System.Text.Encoding]::Unicode.GetBytes($Str)
$base64unicodestring = [System.Convert]::ToBase64String($unicodebytes)
$base64unicodestring
}
StringToBase64
========================================================================
testing
--------------------------------------------------------------
powershell -executionpolicy Bypass -file C:\Users\Administrator\Documents\StringToBase64.ps1 -Str "dir 'c:\'"
ZGlyICdjOlwn
powershell -executionpolicy Bypass -file C:\Users\Administrator\Documents\StringToBase64_MyTest.ps1 -Str "dir 'c:\'"
ZABpAHIAIAAnAGMAOgBcACcA
result
------------------------------------------------------------------------------------------------------------------------
powershell -Encodedcommand ZGlyICdjOlwn #some error like powershell.exe : The term '?????' is not recognized as the name of a cmdlet, function .....
powershell -Encodedcommand ZABpAHIAIAAnAGMAOgBcACcA #succeed
I think there are some particular problems in encoding operations, the [System.Text.Encoding]::Unicode is better
thanks
--------------------------------------------------------------------------
**************************************************************************