Merge pull request #838 from shreyamalviya/add-run-as-user-option

Add option to run as a certain user on the Run Monkey page
This commit is contained in:
VakarisZ 2021-01-11 10:19:34 +02:00 committed by GitHub
commit f2b9f850d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 29 deletions

View File

@ -7,6 +7,7 @@ import GenerateLocalWindowsPowershell from '../commands/local_windows_powershell
import GenerateLocalLinuxWget from '../commands/local_linux_wget'; import GenerateLocalLinuxWget from '../commands/local_linux_wget';
import GenerateLocalLinuxCurl from '../commands/local_linux_curl'; import GenerateLocalLinuxCurl from '../commands/local_linux_curl';
import CommandDisplay from '../utils/CommandDisplay'; import CommandDisplay from '../utils/CommandDisplay';
import {Form} from 'react-bootstrap';
const LocalManualRunOptions = (props) => { const LocalManualRunOptions = (props) => {
@ -28,22 +29,32 @@ const getContents = (props) => {
const [osType, setOsType] = useState(OS_TYPES.WINDOWS_64); const [osType, setOsType] = useState(OS_TYPES.WINDOWS_64);
const [selectedIp, setSelectedIp] = useState(props.ips[0]); const [selectedIp, setSelectedIp] = useState(props.ips[0]);
const [commands, setCommands] = useState(generateCommands()); const [commands, setCommands] = useState(generateCommands());
const [customUsername, setCustomUsername] = useState('');
useEffect(() => { useEffect(() => {
setCommands(generateCommands()); setCommands(generateCommands());
}, [osType, selectedIp]) }, [osType, selectedIp, customUsername])
function setIp(index) { function setIp(index) {
setSelectedIp(props.ips[index]); setSelectedIp(props.ips[index]);
} }
function setUsername(inputVal) {
if (inputVal) { // checks that it's not just whitespaces
setCustomUsername(inputVal);
}
else {
setCustomUsername('');
}
}
function generateCommands() { function generateCommands() {
if (osType === OS_TYPES.WINDOWS_64 || osType === OS_TYPES.WINDOWS_32) { if (osType === OS_TYPES.WINDOWS_64 || osType === OS_TYPES.WINDOWS_32) {
return [{type: 'CMD', command: GenerateLocalWindowsCmd(selectedIp, osType)}, return [{type: 'CMD', command: GenerateLocalWindowsCmd(selectedIp, osType, customUsername)},
{type: 'Powershell', command: GenerateLocalWindowsPowershell(selectedIp, osType)}] {type: 'Powershell', command: GenerateLocalWindowsPowershell(selectedIp, osType, customUsername)}]
} else { } else {
return [{type: 'CURL', command: GenerateLocalLinuxCurl(selectedIp, osType)}, return [{type: 'CURL', command: GenerateLocalLinuxCurl(selectedIp, osType, customUsername)},
{type: 'WGET', command: GenerateLocalLinuxWget(selectedIp, osType)}] {type: 'WGET', command: GenerateLocalLinuxWget(selectedIp, osType, customUsername)}]
} }
} }
@ -51,6 +62,19 @@ const getContents = (props) => {
<> <>
<DropdownSelect defaultKey={OS_TYPES.WINDOWS_64} options={osTypes} onClick={setOsType} variant={'outline-monkey'}/> <DropdownSelect defaultKey={OS_TYPES.WINDOWS_64} options={osTypes} onClick={setOsType} variant={'outline-monkey'}/>
<DropdownSelect defaultKey={0} options={props.ips} onClick={setIp} variant={'outline-monkey'}/> <DropdownSelect defaultKey={0} options={props.ips} onClick={setIp} variant={'outline-monkey'}/>
<div style={{'marginTop': '1.4em'}}>
<p style={{'fontSize': '1.2em'}}>
Run as a user by entering their username:
</p>
<div>
<Form>
<Form.Control
type="text"
onChange={input => setUsername(input.target.value.trim())}
/>
</Form>
</div>
</div>
<CommandDisplay commands={commands}/> <CommandDisplay commands={commands}/>
</> </>
) )

View File

@ -1,13 +1,16 @@
import {OS_TYPES} from '../utils/OsTypes'; 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'; let bitText = osType === OS_TYPES.LINUX_32 ? '32' : '64';
return `curl https://${ip}:5000/api/monkey/download/monkey-linux-${bitText} -k let command = `curl https://${ip}:5000/api/monkey/download/monkey-linux-${bitText} -k `
-o monkey-linux-${bitText}; + `-o monkey-linux-${bitText}; `
chmod +x monkey-linux-${bitText}; + `chmod +x monkey-linux-${bitText}; `
./monkey-linux-${bitText} m0nk3y -s ${ip}:5000\`;`; + `./monkey-linux-${bitText} m0nk3y -s ${ip}:5000;`;
if (username != '') {
command = `su - ${username} -c "${command}"`;
} }
return command;
}

View File

@ -1,10 +1,16 @@
import {OS_TYPES} from '../utils/OsTypes'; 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'; let bitText = osType === OS_TYPES.LINUX_32 ? '32' : '64';
return `wget --no-check-certificate https://${ip}:5000/api/monkey/download/ let command = `wget --no-check-certificate https://${ip}:5000/api/monkey/download/`
monkey-linux-${bitText}; + `monkey-linux-${bitText}; `
chmod +x monkey-linux-${bitText}; + `chmod +x monkey-linux-${bitText}; `
./monkey-linux-${bitText} m0nk3y -s ${ip}:5000`; + `./monkey-linux-${bitText} m0nk3y -s ${ip}:5000`;
if (username != '') {
command = `su - ${username} -c "${command}"`;
} }
return command;
}

View File

@ -1,10 +1,16 @@
import {OS_TYPES} from '../utils/OsTypes'; 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'; let bitText = osType === OS_TYPES.WINDOWS_32 ? '32' : '64';
return `powershell [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; let command = `powershell [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; `
(New-Object System.Net.WebClient).DownloadFile('https://${ip}:5000/api/monkey/download/ + `(New-Object System.Net.WebClient).DownloadFile('https://${ip}:5000/api/monkey/download/ `
monkey-windows-${bitText}.exe','.\\monkey.exe'); + `monkey-windows-${bitText}.exe','.\\monkey.exe'); `
;Start-Process -FilePath '.\\monkey.exe' -ArgumentList 'm0nk3y -s ${ip}:5000';`; + `;Start-Process -FilePath '.\\monkey.exe' -ArgumentList 'm0nk3y -s ${ip}:5000';`;
if (username != '') {
command = `runas /user:${username} "cmd /K ${command}"`;
}
return command;
} }

View File

@ -1,10 +1,16 @@
import {OS_TYPES} from '../utils/OsTypes'; 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'; let bitText = osType === OS_TYPES.WINDOWS_32 ? '32' : '64';
return `[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; let command = `[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; `
(New-Object System.Net.WebClient).DownloadFile('https://${ip}:5000/api/monkey/download/ + `(New-Object System.Net.WebClient).DownloadFile('https://${ip}:5000/api/monkey/download/ `
monkey-windows-${bitText}.exe','.\\monkey.exe'); + `monkey-windows-${bitText}.exe','.\\monkey.exe'); `
;Start-Process -FilePath '.\\monkey.exe' -ArgumentList 'm0nk3y -s ${ip}:5000';`; + `;Start-Process -FilePath '.\\monkey.exe' -ArgumentList 'm0nk3y -s ${ip}:5000';`;
if (username != '') {
command = `Start-Process powershell.exe -ArgumentList "-noexit ${command}" -Credential ${username}`;
}
return command;
} }