我對PowerShell比較陌生,對腳本有點奇怪的問題。我已經搜索論壇,並沒有找到任何有效的工具。丟失原始格式的數據
我遇到的問題是,當我通過自定義協議來隱藏命令輸出到base64和從base64輸出時,我們在我們的環境中使用它正在失去格式。通過將命令字符串傳遞給IEX並將輸出存儲到變量,可以在遠程系統上執行命令。我使用下面的命令
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($str1)
$EncodedCmd = [Convert]::ToBase64String($Bytes)
在另一端輸出轉換爲Base64格式,當我們收到我們轉換回用命令的輸出
[System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($EncodedCmd))
我遇到的問題是,雖然輸出是正確的輸出格式已丟失。例如,如果我運行ipconfig命令
Windows IP Configuration Ethernet adapter Local Area Connection 2: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Ethernet
adapter Local Area Connection 3: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::3cd8:3c7f:c78b:a78f%14 IPv4 Address. . . . . . . . . . .
: 192.168.10.64 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.10.100 Ethernet adapter Local Area Connection: Connection-sp
ecific DNS Suffix . : IPv4 Address. . . . . . . . . . . : 172.10.15.201 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 172.10.15
1.200 Tunnel adapter isatap.{42EDCBE-8172-5478-AD67E-8A28273E95}: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Tunnel ada
pter isatap.{42EDCBE-8172-5478-AD67E-8A28273E95}: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Tunnel adapter isatap.{42EDCBE-8172-5478-AD67E-8A28273E95}: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . : Tunnel adapter Teredo Tunneling Pseudo-Inter
face: Media State . . . . . . . . . . . : Media disconnected Connection-specific DNS Suffix . :
格式將所有的地方,難以閱讀,我與它發揮各地了一點,但我無法找到返回命令的一個真正好方法以正確的格式輸出。欣賞關於如何修復格式的任何想法
這看起來像陣列濺射的問題。你如何填充'$ str1'變量? – vonPryz