Skip to content

Commit

Permalink
Add option to run as a certain user via manual command on the Run Mon…
Browse files Browse the repository at this point in the history
…key page
  • Loading branch information
shreyamalviya committed Dec 22, 2020
1 parent 1f12975 commit 0f45837
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -28,29 +29,52 @@ 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)}]
}
}

return (
<>
<DropdownSelect defaultKey={OS_TYPES.WINDOWS_64} options={osTypes} onClick={setOsType} 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}/>
</>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}



Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 0f45837

Please sign in to comment.