Harden Raven Muninn remote script runners

This commit is contained in:
Meta Vens 2026-06-19 23:40:33 +01:00
commit c8622e5e77
3 changed files with 9 additions and 9 deletions

View file

@ -254,6 +254,7 @@ if (Test-Path -LiteralPath `$target) {
Move-Item -LiteralPath `$incoming -Destination `$target -Force
`$item = Get-Item -LiteralPath `$target
Write-Output ("muninn.exe deployed length={0} path={1}" -f `$item.Length, `$item.FullName)
`$global:LASTEXITCODE = 0
"@
Set-AsciiFile -Path $localRemoteScript -Content $remoteScript
@ -276,16 +277,15 @@ Write-Output ("muninn.exe deployed length={0} path={1}" -f `$item.Length, `$item
`$ErrorActionPreference = "Stop"
try {
& "$remoteScriptPath"
`$code = `$LASTEXITCODE
exit 0
} finally {
Remove-Item -LiteralPath "$remoteScriptPath" -Force -ErrorAction SilentlyContinue
}
exit `$code
"@
$encodedRunner = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($remoteRunner))
$commonArgs = Get-SshCommonArgs
$sshTarget = Get-SshTarget -Target $RavenHost
& ssh.exe @commonArgs $sshTarget "powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encodedRunner"
& ssh.exe @commonArgs $sshTarget "powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -OutputFormat Text -EncodedCommand $encodedRunner"
if ($LASTEXITCODE -ne 0) {
throw "remote Muninn binary deploy failed with exit code $LASTEXITCODE"
}

View file

@ -71,18 +71,18 @@ function Invoke-RavenUploadedPowerShell {
$remoteRunner = @"
`$ErrorActionPreference = "Stop"
`$ProgressPreference = "SilentlyContinue"
try {
& "$remotePsPath"
`$code = `$LASTEXITCODE
exit 0
} finally {
Remove-Item -LiteralPath "$remotePsPath" -Force -ErrorAction SilentlyContinue
}
exit `$code
"@
$encodedRunner = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($remoteRunner))
$commonArgs = Get-SshCommonArgs
$sshTarget = Get-SshTarget -Target $RavenHost
& ssh.exe @commonArgs $sshTarget "powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encodedRunner"
& ssh.exe @commonArgs $sshTarget "powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -OutputFormat Text -EncodedCommand $encodedRunner"
} finally {
Remove-Item -LiteralPath $localTempRoot -Recurse -Force -ErrorAction SilentlyContinue
}

View file

@ -230,18 +230,18 @@ function Invoke-RavenUploadedPowerShell {
$remoteRunner = @"
`$ErrorActionPreference = "Stop"
`$ProgressPreference = "SilentlyContinue"
try {
& "$remotePsPath"
`$code = `$LASTEXITCODE
exit 0
} finally {
Remove-Item -LiteralPath "$remotePsPath" -Force -ErrorAction SilentlyContinue
}
exit `$code
"@
$encodedRunner = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($remoteRunner))
$commonArgs = Get-SshCommonArgs
$sshTarget = Get-SshTarget -Target $RavenHost
& ssh.exe @commonArgs $sshTarget "powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encodedRunner"
& ssh.exe @commonArgs $sshTarget "powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -OutputFormat Text -EncodedCommand $encodedRunner"
} finally {
Remove-Item -LiteralPath $localTempRoot -Recurse -Force -ErrorAction SilentlyContinue
}