save only first scan

This commit is contained in:
Adrien MALINGREY 2024-10-07 12:09:12 +02:00
parent 1d8457d020
commit 6dd728ce0d
5 changed files with 33 additions and 30 deletions

View File

@ -1,4 +1,4 @@
<?php <?php
$NMAP_OPTIONS = '-PS22,80,443,445 -F -T5'; $NMAP_OPTIONS = '-Pn -F -T5';
$SCANS_DIR = 'scans'; $SCANS_DIR = 'scans';

View File

@ -49,8 +49,8 @@ if (!file_exists($SCANS_DIR)) {
mkdir($SCANS_DIR); mkdir($SCANS_DIR);
} }
foreach (scandir($SCANS_DIR) as $scan) { foreach (scandir($SCANS_DIR) as $scan) {
if (substr($scan, -9) == '_init.xml') { if (substr($scan, -4) == '.xml') {
$targets = str_replace('!', '/', substr_replace($scan, '', -9)); $targets = str_replace('!', '/', substr_replace($scan, '', -4));
echo "<li><a class='item' href='scan.php?targets=".urlencode($targets)."'>$targets</a></li>\n"; echo "<li><a class='item' href='scan.php?targets=".urlencode($targets)."'>$targets</a></li>\n";
} }
} }

View File

@ -1,5 +1,9 @@
<?php <?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
include_once 'config.php'; include_once 'config.php';
$targets = filter_input(INPUT_GET, 'targets', FILTER_VALIDATE_REGEXP, [ $targets = filter_input(INPUT_GET, 'targets', FILTER_VALIDATE_REGEXP, [
@ -11,12 +15,11 @@ if (!$targets) {
exit('Paramètre targets manquant.'); exit('Paramètre targets manquant.');
} }
$basedir = "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}".dirname($_SERVER['REQUEST_URI']);
$dir = $SCANS_DIR; $dir = $SCANS_DIR;
if (!file_exists($SCANS_DIR)) { if (!file_exists($SCANS_DIR)) {
mkdir($SCANS_DIR); mkdir($SCANS_DIR);
} }
$initPath = "$SCANS_DIR/".str_replace('/', '!', $targets).'_init.xml'; $initPath = "$SCANS_DIR/".str_replace('/', '!', $targets).'_init.xml';
if (file_exists($initPath)) { if (file_exists($initPath)) {
$currentPath = ("$SCANS_DIR/".str_replace('/', '!', $targets).'_current.xml'); $currentPath = ("$SCANS_DIR/".str_replace('/', '!', $targets).'_current.xml');
@ -25,28 +28,29 @@ if (file_exists($initPath)) {
$initPath = ''; $initPath = '';
} }
$stylesheetUrl = "$basedir/stylesheet.xsl"; $result = `nmap $NMAP_OPTIONS --stylesheet stylesheet.xsl -oX - $targets`;
$command = "NMAPDIR=./nmap nmap $NMAP_OPTIONS -oX ".escapeshellarg($currentPath)." --stylesheet $basedir/stylesheet.xsl $targets"; if ($result) {
$xml = new DOMDocument();
$xml->loadXML($result);
$xml->insertBefore($xml->createProcessingInstruction('xslt-param', "name='targets' value='$targets'"), $xml->documentElement);
exec($command, $output, $retval); $dir = $SCANS_DIR;
if (!file_exists($SCANS_DIR)) {
mkdir($SCANS_DIR);
}
$path = "$SCANS_DIR/".str_replace('/', '!', $targets).'.xml';
if (!file_exists($path)) {
$xml->insertBefore($xml->createProcessingInstruction('xslt-param', "name='compareWith' value=''"), $xml->documentElement);
$xml->save($path);
} else {
$xml->insertBefore($xml->createProcessingInstruction('xslt-param', "name='compareWith' value='$path'"), $xml->documentElement);
}
if (!file_exists($currentPath)) { header('Content-type: text/xml');
exit($xml->saveXML());
} else {
http_response_code(500); http_response_code(500);
exit(implode("<br/>\n", $output)); exit();
} }
// Add params
$xml = new DOMDocument();
$xml->load($currentPath);
$processingInstruction = $xml->createProcessingInstruction('xslt-param', "name='targets' value='$targets'");
$xml->insertBefore($processingInstruction, $xml->documentElement);
$processingInstruction = $xml->createProcessingInstruction('xslt-param', "name='basedir' value='$basedir'");
$xml->insertBefore($processingInstruction, $xml->documentElement);
$processingInstruction = $xml->createProcessingInstruction('xslt-param', "name='compareWith' value='$initPath'");
$xml->insertBefore($processingInstruction, $xml->documentElement);
$xml->save($currentPath);
//header('Location: '.$currentPath);
header('Content-type: text/xml');
exit($xml->saveXML());

View File

@ -4,7 +4,6 @@
<xsl:output method="html" encoding="UTF-8" /> <xsl:output method="html" encoding="UTF-8" />
<xsl:output indent="yes" /> <xsl:output indent="yes" />
<xsl:strip-space elements='*' /> <xsl:strip-space elements='*' />
<xsl:param name="basedir" />
<xsl:param name="targets" /> <xsl:param name="targets" />
<xsl:param name="compareWith" /> <xsl:param name="compareWith" />
<xsl:variable name="current" select="./nmaprun" /> <xsl:variable name="current" select="./nmaprun" />
@ -20,7 +19,7 @@
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/fomantic-ui@2.9.3/dist/semantic.min.css" /> <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/fomantic-ui@2.9.3/dist/semantic.min.css" />
<link href="https://cdn.jsdelivr.net/npm/@yaireo/tagify/dist/tagify.css" rel="stylesheet" type="text/css" /> <link href="https://cdn.jsdelivr.net/npm/@yaireo/tagify/dist/tagify.css" rel="stylesheet" type="text/css" />
<link href="https://cdn.datatables.net/v/dt/jszip-3.10.1/dt-2.1.8/b-3.1.2/b-html5-3.1.2/b-print-3.1.2/fh-4.0.1/r-3.0.3/datatables.css" rel="stylesheet" /> <link href="https://cdn.datatables.net/v/dt/jszip-3.10.1/dt-2.1.8/b-3.1.2/b-html5-3.1.2/b-print-3.1.2/fh-4.0.1/r-3.0.3/datatables.css" rel="stylesheet" />
<link href="{$basedir}/style.css" rel="stylesheet" type="text/css" /> <link href="style.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.7.1.js"></script> <script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.2/semantic.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.9.2/semantic.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@yaireo/tagify"></script> <script src="https://cdn.jsdelivr.net/npm/@yaireo/tagify"></script>
@ -32,7 +31,7 @@
<body> <body>
<nav class="ui inverted teal fixed menu"> <nav class="ui inverted teal fixed menu">
<a class="header item" href="{$basedir}"> <a class="header item" href=".">
<xsl:text>lan</xsl:text> <xsl:text>lan</xsl:text>
<svg class="logo" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 24 24" xml:space="preserve" width="40" height="40" <svg class="logo" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 24 24" xml:space="preserve" width="40" height="40"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -87,7 +86,7 @@
<div class="right menu"> <div class="right menu">
<iconsearch class="ui right aligned search category item"> <iconsearch class="ui right aligned search category item">
<div class="ui icon input"> <div class="ui icon input">
<form id="newScanForm" class="ui form" method="get" action="{$basedir}/scan.php"> <form id="newScanForm" class="ui form" method="get" action="scan.php">
<input class="prompt" type="text" name="targets" placeholder="Scanner un réseau..." required="" autocomplete="off" title="Les cibles peuvent être spécifiées par des noms d'hôtes, des adresses IP, des adresses de réseaux, etc. <input class="prompt" type="text" name="targets" placeholder="Scanner un réseau..." required="" autocomplete="off" title="Les cibles peuvent être spécifiées par des noms d'hôtes, des adresses IP, des adresses de réseaux, etc.
Exemple: scanme.nmap.org microsoft.com/24 192.168.0.1 10.0-255.0-255.1-254" pattern="[a-zA-Z0-9._\/ \-]+" value="{$targets}" /> Exemple: scanme.nmap.org microsoft.com/24 192.168.0.1 10.0-255.0-255.1-254" pattern="[a-zA-Z0-9._\/ \-]+" value="{$targets}" />
</form> </form>