使用 -noexit 参数将代码转换为 .EXE
Convert code to .EXE using -noexit parameter
我想将我的 PowerShell 转换为 .EXE 以便稍微混淆代码,但到目前为止我无法实现我的目标。
我尝试了不同的工具,例如 PS2exe、powergui、steroids 等,其中 none 让我可以将参数添加到 PowerShell 命令。
powershell.exe -noexit -windowstyle hidden -file c:\temp\myscript.ps1
谁能告诉我如何实现这一点?或任何其他混淆代码的方法?
这就是我最终成功的方法。嵌入代码! :)
ScriptBlock 是关键。
$sb = {
$query = 'SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE TargetInstance ISA ''Win32_LogicalDisk'' AND TargetInstance.DriveType=2'
Register-WmiEvent -Query $query -SourceIdentifier RemovableDiskDetection -Action {
$class = $eventArgs.NewEvent.__CLASS
$device = $eventArgs.NewEvent.TargetInstance.DeviceID
$wshell = New-Object -ComObject Wscript.Shell
switch ($class)
{
__InstanceCreationEvent {
$path = $device + '\flag\'
Write-Host '*** Checking the existence of the file $path'
if (Test-Path -Path $path)
{
$wshell.Popup('Inserted, device id: $device WITH flag', 0, 'Done', 0x1)
}
else
{
$wshell.Popup('Inserted, device id: $device WITHOUT flag', 0, 'Done', 0x1)
}
}
__InstanceDeletionEvent {
$wshell.Popup('Removed, device id: $device ', 0, 'Done', 0x1)
}
}
}
}
start-process powershell.exe -argument "-noexit -nologo -noprofile -windowstyle hidden -command $sb"
一旦我设法嵌入参数并得到一个正常的 ps1 文件,我就使用 PS2EXE 工具编译它。
.\ps2exe.ps1 -noConsole -inputFile .\magic.ps1 -outPutFile magic.exe
我想将我的 PowerShell 转换为 .EXE 以便稍微混淆代码,但到目前为止我无法实现我的目标。 我尝试了不同的工具,例如 PS2exe、powergui、steroids 等,其中 none 让我可以将参数添加到 PowerShell 命令。
powershell.exe -noexit -windowstyle hidden -file c:\temp\myscript.ps1
谁能告诉我如何实现这一点?或任何其他混淆代码的方法?
这就是我最终成功的方法。嵌入代码! :) ScriptBlock 是关键。
$sb = {
$query = 'SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE TargetInstance ISA ''Win32_LogicalDisk'' AND TargetInstance.DriveType=2'
Register-WmiEvent -Query $query -SourceIdentifier RemovableDiskDetection -Action {
$class = $eventArgs.NewEvent.__CLASS
$device = $eventArgs.NewEvent.TargetInstance.DeviceID
$wshell = New-Object -ComObject Wscript.Shell
switch ($class)
{
__InstanceCreationEvent {
$path = $device + '\flag\'
Write-Host '*** Checking the existence of the file $path'
if (Test-Path -Path $path)
{
$wshell.Popup('Inserted, device id: $device WITH flag', 0, 'Done', 0x1)
}
else
{
$wshell.Popup('Inserted, device id: $device WITHOUT flag', 0, 'Done', 0x1)
}
}
__InstanceDeletionEvent {
$wshell.Popup('Removed, device id: $device ', 0, 'Done', 0x1)
}
}
}
}
start-process powershell.exe -argument "-noexit -nologo -noprofile -windowstyle hidden -command $sb"
一旦我设法嵌入参数并得到一个正常的 ps1 文件,我就使用 PS2EXE 工具编译它。
.\ps2exe.ps1 -noConsole -inputFile .\magic.ps1 -outPutFile magic.exe