From 0f45837287f5fde590c8108ed68a1ca9ed83311c Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 22 Dec 2020 22:03:49 +0530 Subject: [PATCH] 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 bd396e256f5..f0b13953158 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 2f0d5a5d0a2..a837d237e2c 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 b1d2a5a3004..08645b23d26 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 1cb9c2979ce..82cf35d8e1e 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 97d95fb63c3..7845a59c0fe 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; }