use sudo on need

This commit is contained in:
2024-10-15 16:24:07 +02:00
parent 9a525b6ffe
commit 386d0fc65d
3 changed files with 14 additions and 9 deletions

View File

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