use sudo on need
This commit is contained in:
		| @ -6,11 +6,7 @@ Scanne le réseau avec `nmap` et affiche les résultats dans une page web. | |||||||
|  |  | ||||||
| Certaines options nécessitent l'accès root. | Certaines options nécessitent l'accès root. | ||||||
| Pour donner les droits à lanScan sous Linux, installer `sudo` au besoin, puis créer le fichier `/etc/sudoers.d/lanScan` avec le contenu | Pour donner les droits à lanScan sous Linux, installer `sudo` au besoin, puis créer le fichier `/etc/sudoers.d/lanScan` avec le contenu | ||||||
| (en remplaçant `www-data` par le compte du service web) : | (en remplaçant `www-data` par l'utilisateur du service web) : | ||||||
| ``` | ``` | ||||||
| www-data ALL = NOPASSWD: /usr/bin/nmap | www-data ALL = NOPASSWD: /usr/bin/nmap | ||||||
| ```` | ```` | ||||||
| et modifier le fichier `config.php` avec : |  | ||||||
| ```php |  | ||||||
| $sudo = true; |  | ||||||
| ``` |  | ||||||
| @ -16,8 +16,8 @@ $HOSTSCAN_OPTIONS = [ | |||||||
|     'stylesheet' => "$BASEDIR/hostScan.xsl" |     'stylesheet' => "$BASEDIR/hostScan.xsl" | ||||||
| ]; | ]; | ||||||
|  |  | ||||||
|  | $refreshPeriod = 60; | ||||||
|  |  | ||||||
| $SCANSDIR = 'scans'; | $SCANSDIR = 'scans'; | ||||||
| $DATADIR  = '/usr/share/nmap'; | $DATADIR  = '/usr/share/nmap'; | ||||||
|  |  | ||||||
| $sudo = true; |  | ||||||
| $refreshPeriod = 60; |  | ||||||
|  | |||||||
							
								
								
									
										13
									
								
								scan.php
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								scan.php
									
									
									
									
									
								
							| @ -28,8 +28,17 @@ foreach ($inputs as $arg => $value) { | |||||||
|  |  | ||||||
| $tempPath = tempnam(sys_get_temp_dir(), 'scan_').".xml"; | $tempPath = tempnam(sys_get_temp_dir(), 'scan_').".xml"; | ||||||
|  |  | ||||||
| exec(($sudo ? "sudo " : "") . "nmap$args -oX '$tempPath' $targets 2>&1", $stderr, $code); | $command = "nmap$args -oX '$tempPath' $targets 2>&1"; | ||||||
| if ($code) { |  | ||||||
|  | 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); |     http_response_code(500); | ||||||
|     die(implode("<br/>\n", $stderr)); |     die(implode("<br/>\n", $stderr)); | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user