From 22d9f703746c5ee1a3c5223272d0c5692ac14a0b Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 22 Dec 2020 22:03:49 +0530 Subject: [PATCH 1/2] Add option to run as a certain user via manual command on the Run Monkey page --- .../RunManually/LocalManualRunOptions.js | 34 ++++++++++++++++--- .../commands/local_linux_curl.js | 16 ++++----- .../commands/local_linux_wget.js | 13 ++++--- .../commands/local_windows_cmd.js | 14 +++++--- .../commands/local_windows_powershell.js | 13 ++++--- 5 files changed, 62 insertions(+), 28 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunManually/LocalManualRunOptions.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunManually/LocalManualRunOptions.js index bd396e256..f0b139531 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunManually/LocalManualRunOptions.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunManually/LocalManualRunOptions.js @@ -7,6 +7,7 @@ import GenerateLocalWindowsPowershell from '../commands/local_windows_powershell import GenerateLocalLinuxWget from '../commands/local_linux_wget'; import GenerateLocalLinuxCurl from '../commands/local_linux_curl'; import CommandDisplay from '../utils/CommandDisplay'; +import {Form} from 'react-bootstrap'; const LocalManualRunOptions = (props) => { @@ -28,22 +29,32 @@ const getContents = (props) => { const [osType, setOsType] = useState(OS_TYPES.WINDOWS_64); const [selectedIp, setSelectedIp] = useState(props.ips[0]); const [commands, setCommands] = useState(generateCommands()); + const [customUsername, setCustomUsername] = useState(''); useEffect(() => { setCommands(generateCommands()); - }, [osType, selectedIp]) + }, [osType, selectedIp, customUsername]) function setIp(index) { setSelectedIp(props.ips[index]); } + function setUsername(inputVal) { + if (inputVal) { // checks that it's not just whitespaces + setCustomUsername(inputVal); + } + else { + setCustomUsername(''); + } + } + function generateCommands() { if (osType === OS_TYPES.WINDOWS_64 || osType === OS_TYPES.WINDOWS_32) { - return [{type: 'CMD', command: GenerateLocalWindowsCmd(selectedIp, osType)}, - {type: 'Powershell', command: GenerateLocalWindowsPowershell(selectedIp, osType)}] + return [{type: 'CMD', command: GenerateLocalWindowsCmd(selectedIp, osType, customUsername)}, + {type: 'Powershell', command: GenerateLocalWindowsPowershell(selectedIp, osType, customUsername)}] } else { - return [{type: 'CURL', command: GenerateLocalLinuxCurl(selectedIp, osType)}, - {type: 'WGET', command: GenerateLocalLinuxWget(selectedIp, osType)}] + return [{type: 'CURL', command: GenerateLocalLinuxCurl(selectedIp, osType, customUsername)}, + {type: 'WGET', command: GenerateLocalLinuxWget(selectedIp, osType, customUsername)}] } } @@ -51,6 +62,19 @@ const getContents = (props) => { <> +
+

+ Run as a user by entering their username: +

+
+
+ setUsername(input.target.value.trim())} + /> + +
+
) diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js index 2f0d5a5d0..a837d237e 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js @@ -1,13 +1,13 @@ import {OS_TYPES} from '../utils/OsTypes'; -export default function generateLocalLinuxCurl(ip, osType) { +export default function generateLocalLinuxCurl(ip, osType, username) { let bitText = osType === OS_TYPES.LINUX_32 ? '32' : '64'; - return `curl https://${ip}:5000/api/monkey/download/monkey-linux-${bitText} -k - -o monkey-linux-${bitText}; - chmod +x monkey-linux-${bitText}; - ./monkey-linux-${bitText} m0nk3y -s ${ip}:5000\`;`; + let command = `curl https://${ip}:5000/api/monkey/download/monkey-linux-${bitText} -k ` + + `-o monkey-linux-${bitText}; ` + + `chmod +x monkey-linux-${bitText}; ` + + `./monkey-linux-${bitText} m0nk3y -s ${ip}:5000;`; + if (username != '') + command = `su - ${username} -c "${command}"`; + return command; } - - - diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js index b1d2a5a30..08645b23d 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js @@ -1,10 +1,13 @@ import {OS_TYPES} from '../utils/OsTypes'; -export default function generateLocalLinuxWget(ip, osType) { +export default function generateLocalLinuxWget(ip, osType, username) { let bitText = osType === OS_TYPES.LINUX_32 ? '32' : '64'; - return `wget --no-check-certificate https://${ip}:5000/api/monkey/download/ - monkey-linux-${bitText}; - chmod +x monkey-linux-${bitText}; - ./monkey-linux-${bitText} m0nk3y -s ${ip}:5000`; + let command = `wget --no-check-certificate https://${ip}:5000/api/monkey/download/` + + `monkey-linux-${bitText}; ` + + `chmod +x monkey-linux-${bitText}; ` + + `./monkey-linux-${bitText} m0nk3y -s ${ip}:5000`; + if (username != '') + command = `su - ${username} -c "${command}"`; + return command; } diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_cmd.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_cmd.js index 1cb9c2979..82cf35d8e 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_cmd.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_cmd.js @@ -1,10 +1,14 @@ import {OS_TYPES} from '../utils/OsTypes'; -export default function generateLocalWindowsCmd(ip, osType) { +export default function generateLocalWindowsCmd(ip, osType, username) { let bitText = osType === OS_TYPES.WINDOWS_32 ? '32' : '64'; - return `powershell [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';`; + let command = `powershell [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';`; + + if (username != '') + command = `runas /user:${username} "cmd /K ${command}"`; + return command; } 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 97d95fb63..7845a59c0 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,10 +1,13 @@ import {OS_TYPES} from '../utils/OsTypes'; -export default function generateLocalWindowsPowershell(ip, osType) { +export default function generateLocalWindowsPowershell(ip, osType, username) { let bitText = osType === OS_TYPES.WINDOWS_32 ? '32' : '64'; - return `[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';`; + 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';`; + if (username != '') + command = `Start-Process powershell.exe -ArgumentList "-noexit ${command}" -Credential ${username}`; + return command; } From 55dae3f29d477618bd42be222366deddad2f6a46 Mon Sep 17 00:00:00 2001 From: Shreya Date: Fri, 8 Jan 2021 15:15:15 +0530 Subject: [PATCH 2/2] Minor code changes --- .../commands/local_linux_curl.js | 19 +++++++++++-------- .../commands/local_linux_wget.js | 19 +++++++++++-------- .../commands/local_windows_cmd.js | 8 +++++--- .../commands/local_windows_powershell.js | 9 ++++++--- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js index a837d237e..ed9ffdec6 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_curl.js @@ -2,12 +2,15 @@ import {OS_TYPES} from '../utils/OsTypes'; export default function generateLocalLinuxCurl(ip, osType, username) { - let bitText = osType === OS_TYPES.LINUX_32 ? '32' : '64'; - let command = `curl https://${ip}:5000/api/monkey/download/monkey-linux-${bitText} -k ` - + `-o monkey-linux-${bitText}; ` - + `chmod +x monkey-linux-${bitText}; ` - + `./monkey-linux-${bitText} m0nk3y -s ${ip}:5000;`; - if (username != '') - command = `su - ${username} -c "${command}"`; - return command; + let bitText = osType === OS_TYPES.LINUX_32 ? '32' : '64'; + let command = `curl https://${ip}:5000/api/monkey/download/monkey-linux-${bitText} -k ` + + `-o monkey-linux-${bitText}; ` + + `chmod +x monkey-linux-${bitText}; ` + + `./monkey-linux-${bitText} m0nk3y -s ${ip}:5000;`; + + if (username != '') { + command = `su - ${username} -c "${command}"`; } + + return command; +} diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js index 08645b23d..3f47dc996 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_linux_wget.js @@ -2,12 +2,15 @@ import {OS_TYPES} from '../utils/OsTypes'; export default function generateLocalLinuxWget(ip, osType, username) { - let bitText = osType === OS_TYPES.LINUX_32 ? '32' : '64'; - let command = `wget --no-check-certificate https://${ip}:5000/api/monkey/download/` - + `monkey-linux-${bitText}; ` - + `chmod +x monkey-linux-${bitText}; ` - + `./monkey-linux-${bitText} m0nk3y -s ${ip}:5000`; - if (username != '') - command = `su - ${username} -c "${command}"`; - return command; + let bitText = osType === OS_TYPES.LINUX_32 ? '32' : '64'; + let command = `wget --no-check-certificate https://${ip}:5000/api/monkey/download/` + + `monkey-linux-${bitText}; ` + + `chmod +x monkey-linux-${bitText}; ` + + `./monkey-linux-${bitText} m0nk3y -s ${ip}:5000`; + + if (username != '') { + command = `su - ${username} -c "${command}"`; } + + return command; +} diff --git a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_cmd.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_cmd.js index 82cf35d8e..1f66740f6 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_cmd.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/commands/local_windows_cmd.js @@ -8,7 +8,9 @@ export default function generateLocalWindowsCmd(ip, osType, username) { + `monkey-windows-${bitText}.exe','.\\monkey.exe'); ` + `;Start-Process -FilePath '.\\monkey.exe' -ArgumentList 'm0nk3y -s ${ip}:5000';`; - if (username != '') - command = `runas /user:${username} "cmd /K ${command}"`; - return command; + if (username != '') { + command = `runas /user:${username} "cmd /K ${command}"`; + } + + return command; } 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 7845a59c0..7244615ed 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 @@ -7,7 +7,10 @@ export default function generateLocalWindowsPowershell(ip, osType, username) { + `(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';`; - if (username != '') - command = `Start-Process powershell.exe -ArgumentList "-noexit ${command}" -Credential ${username}`; - return command; + + if (username != '') { + command = `Start-Process powershell.exe -ArgumentList "-noexit ${command}" -Credential ${username}`; + } + + return command; }