This commit is contained in:
Adrien MALINGREY 2024-11-25 18:02:54 +01:00
parent dc8fa57c0f
commit 0c72ceb620
5 changed files with 31 additions and 50 deletions

View File

@ -641,24 +641,25 @@ foreach (scandir($SCANSDIR) as $filename) {
<button type="submit" class="ui teal submit button">Démarrer</button> <button type="submit" class="ui teal submit button">Démarrer</button>
</form> </form>
<h2 class="ui header">Scans enregistrés</h1> <h2 class="ui header">Derniers scans</h2>
<div class="ui large relaxed card"> <div class="ui relaxed list">
<div class="content">
<div class="ui divided link list">
<?php <?php
if (!file_exists($SCANSDIR)) { if (!file_exists($SCANSDIR)) {
mkdir($SCANSDIR); mkdir($SCANSDIR);
} }
$scans = [];
foreach (scandir($SCANSDIR) as $filename) { foreach (scandir($SCANSDIR) as $filename) {
if (substr($filename, -4) == '.xml') { if (substr($filename, -4) == '.xml') {
$name = str_replace('!', '/', substr_replace($filename, '', -4)); $scans[$filename] = filemtime("$SCANSDIR/$filename");
echo "<a class='item' href='$SCANSDIR/".rawurlencode($filename)."'>$name</a>\n";
} }
} }
arsort($scans);
foreach ($scans as $filename => $date) {
$name = str_replace('!', '/', substr_replace($filename, '', -4));
echo " <div class='item'><a class='header' href='$SCANSDIR/".rawurlencode($filename)."'>$name</a><div class='description'>".date(DATE_RFC7231, $date)."</div></div>\n";
}
?> ?>
</div> </div>
</div>
</div>
</main> </main>
<footer class="ui footer segment"> <footer class="ui footer segment">

View File

@ -8,7 +8,10 @@ $options["--script-args-file"] = $SCRIPTARGS;
if (!file_exists($SCANSDIR)) mkdir($SCANSDIR); if (!file_exists($SCANSDIR)) mkdir($SCANSDIR);
$command = ($options["sudo"]?? false ? "sudo " : "") . "nmap"; if (!$options["name"]) $options["name"] = str_replace('/', '!', $targets);
//$command = ($options["sudo"]?? false ? "sudo " : "") . "nmap";
$args = "";
foreach ($options as $option => $value) { foreach ($options as $option => $value) {
if (substr($option, 0, 1) == '-') { if (substr($option, 0, 1) == '-') {
if (is_null($value)) { if (is_null($value)) {
@ -18,47 +21,20 @@ foreach ($options as $option => $value) {
die(); die();
} else if ($value) { } else if ($value) {
if ($value === true) { if ($value === true) {
$command .= " $option"; $args .= " $option";
} else { } else {
if (substr($option, 0, 2) == '--') $command .= " $option " . escapeshellarg($value); if (substr($option, 0, 2) == '--') $args .= " $option " . escapeshellarg($value);
else $command .= " $option" . escapeshellarg($value); else $args .= " $option" . escapeshellarg($value);
} }
} }
} }
} }
$tempPath = tempnam(sys_get_temp_dir(), 'scan_').".xml"; $path = "$SCANSDIR/{$options["name"]}.xml";
$command .= " -oX '$tempPath' $targets 2>&1"; $command = "nmap $args -oX - $targets | tee '$path'";
exec($command, $stderr, $retcode); header('Content-type: text/xml');
system($command, $retcode);
if ($retcode) { exit();
http_response_code(500);
$errorMessage = implode("<br/>\n", $stderr);
include_once ".";
die();
}
$xml = new DOMDocument();
$xml->load($tempPath);
`rm "$tempPath"`;
$thisURL = $options["name"]?? false ? "$BASEDIR/$SCANSDIR/".rawurlencode($options["name"]).".xml" : "";
$xml->insertBefore($xml->createProcessingInstruction('xslt-param', "name='thisURL' value='".htmlentities($thisURL, ENT_QUOTES)."'"), $xml->documentElement);
foreach ($options as $option => $value) {
if (substr($option, 0, 1) != '-') {
$xml->insertBefore($xml->createProcessingInstruction('xslt-param', "name='$option' value='".htmlentities($value, ENT_QUOTES)."'"), $xml->documentElement);
}
}
if ($options["name"] ?? false) {
$path = "$SCANSDIR/{$options["name"]}.xml";
$xml->save($path);
header("Location: $path");
exit();
} else {
header('Content-type: text/xml');
exit($xml->saveXML());
}

View File

@ -12,6 +12,10 @@ main {
min-height: calc(100vh - var(--footer-height) - 1rem) min-height: calc(100vh - var(--footer-height) - 1rem)
} }
h1:first-child, h2:first-child, h3:first-child, h4:first-child, h5:first-child, .ui.header:first-child {
margin-top: 1rem;
}
svg { svg {
margin: -0.3em -0.5em -0.5em -0.4em; margin: -0.3em -0.5em -0.5em -0.4em;
fill: currentColor; fill: currentColor;

View File

@ -31,7 +31,7 @@
</xsl:variable> </xsl:variable>
<xsl:template match="nmaprun"> <xsl:template match="nmaprun">
<xsl:variable name="targets" select="substring-after(@args, '.xml ')"/> <xsl:variable name="targets" select="substring-after(@args, '-oX - ')"/>
<html lang="fr"> <html lang="fr">
<xsl:apply-templates select="." mode="head"> <xsl:apply-templates select="." mode="head">
@ -51,7 +51,7 @@
<xsl:with-param name="sudo" select="$sudo"/> <xsl:with-param name="sudo" select="$sudo"/>
</xsl:apply-templates> </xsl:apply-templates>
<main class="ui main container"> <main class="ui main wide container">
<h1 class="ui header"><xsl:value-of select="$targets"/></h1> <h1 class="ui header"><xsl:value-of select="$targets"/></h1>
<table id="scanResultsTable" style="width:100%" role="grid" class="ui sortable small table"> <table id="scanResultsTable" style="width:100%" role="grid" class="ui sortable small table">
@ -61,7 +61,7 @@
<th>Adresse IP</th> <th>Adresse IP</th>
<th>Nom</th> <th>Nom</th>
<th>Fabricant</th> <th>Fabricant</th>
<th class="eight wide">Services</th> <th class="six wide">Services</th>
<th>Scanner les services</th> <th>Scanner les services</th>
</tr> </tr>
</thead> </thead>
@ -177,7 +177,7 @@ function hostScanning(link) {
<xsl:attribute name="href"> <xsl:attribute name="href">
<xsl:value-of select="$basedir"/> <xsl:value-of select="$basedir"/>
<xsl:text>/scan.php?preset=host&amp;targets=</xsl:text> <xsl:text>/scan.php?preset=host&amp;targets=</xsl:text>
<xsl:value-of select="$hostAddress"/> <xsl:value-of select="address/@addr"/>
</xsl:attribute> </xsl:attribute>
<i class="satellite dish icon"></i> <i class="satellite dish icon"></i>
<xsl:text> Services</xsl:text> <xsl:text> Services</xsl:text>
@ -186,7 +186,7 @@ function hostScanning(link) {
<xsl:attribute name="href"> <xsl:attribute name="href">
<xsl:value-of select="$basedir"/> <xsl:value-of select="$basedir"/>
<xsl:text>/?preset=host&amp;targets=</xsl:text> <xsl:text>/?preset=host&amp;targets=</xsl:text>
<xsl:value-of select="$hostAddress"/> <xsl:value-of select="address/@addr"/>
</xsl:attribute> </xsl:attribute>
<i class="settings icon"></i> <i class="settings icon"></i>
</a> </a>