From 570e8f2252fe980e18c99b090d474a93d630584c Mon Sep 17 00:00:00 2001 From: adrien Date: Wed, 16 Oct 2024 11:04:12 +0200 Subject: [PATCH] use sudo at will --- README.md | 4 ++++ config.php | 1 + scan.php | 7 +------ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 589efc4..52eda0e 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,7 @@ Pour donner les droits à lanScan sous Linux, installer `sudo` au besoin, puis c ``` www-data ALL = NOPASSWD: /usr/bin/nmap ```` +et modifier le fichier `config.php` avec : +```php +$use_sudo = true; +``` diff --git a/config.php b/config.php index 64593da..e30194f 100644 --- a/config.php +++ b/config.php @@ -17,6 +17,7 @@ $HOSTSCAN_OPTIONS = [ ]; $refreshPeriod = 60; +$use_sudo = false; $SCANSDIR = 'scans'; $DATADIR = '/usr/share/nmap'; diff --git a/scan.php b/scan.php index a28b427..dcc0c12 100755 --- a/scan.php +++ b/scan.php @@ -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("
\n", $stderr);