diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_powershell.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_powershell.js index aa9a96a17..a9f1c0d2c 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_powershell.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_powershell.js @@ -1,15 +1,20 @@ import {OS_TYPES} from '../utils/OsTypes'; -export default function generateLocalWindowsPowershell(ip, osType, username) { +export function getAgentDownloadCommand(ip, osType) { let bitText = osType === OS_TYPES.WINDOWS_32 ? '32' : '64'; - let command = `[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; ` - + `(New-Object System.Net.WebClient).DownloadFile('https://${ip}:5000/api/monkey/download/` - + `monkey-windows-${bitText}.exe','.\\monkey.exe'); ` - + `;Start-Process -FilePath '.\\monkey.exe' -ArgumentList 'm0nk3y -s ${ip}:5000';`; + return `$execCmd = @"\r\n` + + `-noexit [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {\`$true};` + + `(New-Object System.Net.WebClient).DownloadFile('https://${ip}:5000/api/monkey/download/monkey-windows-${bitText}.exe',` + + `"""$env:TEMP\\monkey.exe""");Start-Process -FilePath '$env:TEMP\\monkey.exe' -ArgumentList 'm0nk3y -s ${ip}:5000';` + + `\r\n"@; \r\n` + + `Start-Process -FilePath powershell.exe -ArgumentList $execCmd` +} +export default function generateLocalWindowsPowershell(ip, osType, username) { + let command = getAgentDownloadCommand(ip, osType) if (username != '') { - command = `Start-Process powershell.exe -ArgumentList "-noexit ${command}" -Credential ${username}`; + command += ` -Credential ${username}`; } return command;