use sudo at will

This commit is contained in:
2024-10-16 11:04:12 +02:00
parent cd6f64679b
commit 570e8f2252
3 changed files with 6 additions and 6 deletions

View File

@ -32,15 +32,10 @@ foreach ($inputs as $arg => $value) {
$tempPath = tempnam(sys_get_temp_dir(), 'scan_').".xml";
$command = "nmap$args -oX '$tempPath' $targets 2>&1";
$command = ($use_sudo? "sudo " : "") . "nmap$args -oX '$tempPath' $targets 2>&1";
exec($command, $stderr, $retcode);
if ($retcode && strpos(implode($stderr), " root ") !== false) {
// Retry with sudo
exec("sudo $command", $stderr, $retcode);
}
if ($retcode) {
http_response_code(500);
$errorMessage = implode("<br/>\n", $stderr);