This commit is contained in:
Adrien MALINGREY 2025-01-24 17:38:33 +01:00
parent a593148c38
commit e2c1c6604e
12 changed files with 42 additions and 30 deletions

View File

@ -1,29 +1,31 @@
<?php
$port = (($_SERVER['REQUEST_SCHEME'] == "http" && $_SERVER['SERVER_PORT'] == 80) || ($_SERVER['REQUEST_SCHEME'] == "https" && $_SERVER['SERVER_PORT'] == 443)) ? "" : ":{$_SERVER['SERVER_PORT']}";
$BASEDIR = "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['SERVER_NAME']}$port" . dirname($_SERVER['SCRIPT_NAME']);
$SCANSDIR = 'scans';
$NMAPDIR = dirname(`which nmap`) . "/../share/nmap";
$DATADIR = "datadir";
$SCRIPTARGS = "script-args.ini";
$port = (($_SERVER['REQUEST_SCHEME'] == "http" && $_SERVER['SERVER_PORT'] == 80) || ($_SERVER['REQUEST_SCHEME'] == "https" && $_SERVER['SERVER_PORT'] == 443)) ? "" : ":{$_SERVER['SERVER_PORT']}";
$BASEDIR = "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['SERVER_NAME']}$port" . dirname($_SERVER['SCRIPT_NAME']);
$SCANSDIR = 'scans';
$TEMPLATESDIR = "templates";
$NMAP = 'sudo nmap'; # nmap command, E.g. 'nmap', 'sudo nmap' for root privileges or '/usr/bin/nmap' if not in PATH
$NMAPDIR = dirname(`which nmap`) . "/../share/nmap";
$DATADIR = ".";
$SCRIPTARGS = "script-args.ini";
$presets = [
"default" => [
'-PS' => 'microsoft-ds',
'-F' => true,
'-T' => 5,
'--stylesheet' => "$BASEDIR/templates/lanScan.xsl",
'--stylesheet' => "lanScan.xsl",
'refreshPeriod' => 60,
'sudo' => false,
],
"host" => [
'-Pn' => true,
'-F' => true,
'-sV' => true,
'-T' => 5,
'--script' => "http-info,smb-shares-size",
'--stylesheet' => "$BASEDIR/templates/hostScan.xsl",
'refreshPeriod' => 60,
'sudo' => true,
'-Pn' => true,
'-F' => true,
'-sV' => true,
'-T' => 5,
'--script' => "http-info,smb-shares-size",
'--stylesheet' => "hostScan.xsl",
'refreshPeriod' => 60,
'sudo' => true,
],
];

View File

@ -107,7 +107,7 @@ if ($preset && isset($presets[$preset])) {
'-V' => FILTER_VALIDATE_BOOLEAN,
'--unprivileged' => FILTER_VALIDATE_BOOLEAN,
'-h' => FILTER_VALIDATE_BOOLEAN,
'--stylesheet' => FILTER_VALIDATE_URL,
'--stylesheet' => ['filter' => FILTER_VALIDATE_REGEXP, 'options' => ['regexp' => $fileNameRegex]],
// lanScan
'name' => ['filter' => FILTER_VALIDATE_REGEXP, 'options' => ['regexp' => $fileNameRegex]],
'originalURL' => FILTER_VALIDATE_URL,

View File

@ -583,10 +583,10 @@ Exemples: <?= $_SERVER['REMOTE_ADDR']; ?>/24 <?= $_SERVER['SERVER_NAME']; ?> 10.
<label for="stylesheetSelect" title="--stylesheet">Feuille de style</label>
<select id="stylesheetSelect" class="ui dropdown" name="--stylesheet" value="<?= $options["--stylesheet"] ?? ""?>">
<?php
foreach (scandir('templates') as $filename) {
foreach (scandir($TEMPLATESDIR) as $filename) {
if (substr($filename, -4) === '.xsl') {
$name = substr($filename, 0, -4);
$URL = "$BASEDIR/templates/".rawurlencode($filename);
$URL = rawurlencode($filename);
if (isset($options["--stylesheet"]) && $URL == $options["--stylesheet"]) {
echo " <option value='$URL' selected>$name</option>\n";
} else {
@ -627,13 +627,14 @@ foreach (scandir($SCANSDIR) as $filename) {
<div class="ui label">secondes</div>
</div>
</div>
<!--
<div class="inline field">
<div class="ui toggle checkbox">
<input id="sudoCheckbox" type="checkbox" name="sudo" <?= $options["sudo"] ?? false ? 'checked' : ''; ?>/>
<label for="sudoCheckbox" title="sudo">Exécuter en tant qu'administrateur</label>
</div>
</div>
-->
</div>
</div>
@ -768,6 +769,15 @@ foreach ([$DATADIR, $NMAPDIR] as $dir) {
newScanForm.onsubmit = function(event) {
if (this.checkValidity()) {
newScanForm.classList.add("loading")
$.toast({
title : 'Scan en cours...',
message : 'Merci de patienter',
class : 'info',
showIcon : 'satellite dish',
displayTime: 0,
closeIcon : true,
position : 'bottom right',
})
return true
} else {
event.preventDefault()

View File

@ -3,9 +3,10 @@
include_once 'config.php';
include_once 'filter_inputs.php';
if (!file_exists($SCANSDIR)) mkdir($SCANSDIR);
if (!$options["name"]) $options["name"] = str_replace('/', '!', $targets);
$options["--stylesheet"] = "$BASEDIR/$TEMPLATESDIR/${options["--stylesheet"]}?";
if (isset($options["name"])) {
$options["--stylesheet"] .= "name=" . rawurlencode($options["name"]) . "&";
}
$args = "";
foreach ($options as $option => $value) {
@ -27,11 +28,10 @@ foreach ($options as $option => $value) {
}
$command = "nmap $args -oX - $targets";
if (isset($options["sudo"])) $command = "sudo $command";
$command = "$NMAP $args -oX - $targets";
if (isset($options["name"])) {
if (!file_exists($SCANSDIR)) mkdir($SCANSDIR);
$path = "$SCANSDIR/{$options["name"]}.xml";
$command .= " | tee '$path'";
}

0
script-args.ini Normal file
View File

View File

@ -19,7 +19,7 @@
<xsl:param name="sudo" select="false"/>
<xsl:variable name="current" select="./nmaprun"/>
<xsl:variable name="stylesheetURL" select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'),'&quot;')"/>
<xsl:variable name="stylesheetURL" select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'), '?')"/>
<xsl:variable name="basedir" select="concat($stylesheetURL, '/../..')"/>
<xsl:variable name="init" select="document($originalURL)/nmaprun"/>
<xsl:variable name="nextComparison">

View File

@ -19,7 +19,7 @@
<xsl:param name="sudo" select="false"/>
<xsl:variable name="current" select="./nmaprun"/>
<xsl:variable name="stylesheetURL" select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'),'&quot;')"/>
<xsl:variable name="stylesheetURL" select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'), '?')"/>
<xsl:variable name="basedir" select="concat($stylesheetURL, '/../..')"/>
<xsl:variable name="init" select="document($originalURL)/nmaprun"/>
<xsl:variable name="nextComparison">
@ -51,7 +51,7 @@
<xsl:with-param name="sudo" select="$sudo"/>
</xsl:apply-templates>
<main class="ui container">
<main class="ui wide container">
<h1 class="ui header"><xsl:value-of select="$targets"/></h1>
<div class="form">

View File

@ -19,7 +19,7 @@
<xsl:param name="sudo" select="false"/>
<xsl:variable name="current" select="./nmaprun"/>
<xsl:variable name="stylesheetURL" select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'),'&quot;')"/>
<xsl:variable name="stylesheetURL" select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'), '?')"/>
<xsl:variable name="basedir" select="concat($stylesheetURL, '/../..')"/>
<xsl:variable name="init" select="document($originalURL)/nmaprun"/>
<xsl:variable name="nextComparison">

View File

@ -19,7 +19,7 @@
<xsl:param name="sudo" select="false"/>
<xsl:variable name="current" select="./nmaprun"/>
<xsl:variable name="stylesheetURL" select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'),'&quot;')"/>
<xsl:variable name="stylesheetURL" select="substring-before(substring-after(processing-instruction('xml-stylesheet'),'href=&quot;'), '?')"/>
<xsl:variable name="basedir" select="concat($stylesheetURL, '/../..')"/>
<xsl:variable name="init" select="document($originalURL)/nmaprun"/>
<xsl:variable name="nextComparison">