This commit is contained in:
2024-10-07 02:48:34 +02:00
parent f44e1d8267
commit 42e16d3ef8
5 changed files with 223 additions and 118 deletions

View File

@ -2,15 +2,6 @@
include_once 'config.php';
$name = filter_input(INPUT_GET, 'name', FILTER_VALIDATE_REGEXP, [
'flags' => FILTER_NULL_ON_FAILURE,
'options' => ['regexp' => '/^[^@<>:"\/|?]+$/'],
]);
if (!$name) {
http_response_code(400);
exit('Paramètre name manquant.');
}
$targets = filter_input(INPUT_GET, 'targets', FILTER_VALIDATE_REGEXP, [
'flags' => FILTER_NULL_ON_FAILURE,
'options' => ['regexp' => "/^[\da-zA-Z.:\/_ -]+$/"],
@ -20,15 +11,15 @@ if (!$targets) {
exit('Paramètre targets manquant.');
}
$basedir = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['REQUEST_URI']);
$basedir = "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}".dirname($_SERVER['REQUEST_URI']);
$dir = $SCANS_DIR;
if (!file_exists($dir)) {
mkdir($dir);
if (!file_exists($SCANS_DIR)) {
mkdir($SCANS_DIR);
}
$firstPath = ("$dir/${name}.xml");
$firstPath = "$SCANS_DIR/".str_replace('/', '!', $targets).'_init.xml';
if (file_exists($firstPath)) {
$path = ("$dir/${name}@".date('YmdHis').'.xml');
$path = ("$SCANS_DIR/".str_replace('/', '!', $targets).'_current.xml');
} else {
$path = $firstPath;
$firstPath = '';
@ -36,15 +27,11 @@ if (file_exists($firstPath)) {
$stylesheetUrl = "$basedir/stylesheet.xsl";
$command = 'NMAPDIR=./nmap nmap';
$command .= " $NMAP_OPTIONS";
$command .= ' -oX '.escapeshellarg($path);
$command .= ' --stylesheet '.escapeshellarg($stylesheetUrl);
$command .= " $targets";
$command = "NMAPDIR=./nmap nmap $NMAP_OPTIONS -oX ".escapeshellarg($path)." --stylesheet $basedir/stylesheet.xsl $targets";
exec($command, $output, $retval);
if (!file_exists(__DIR__."/$path")) {
if (!file_exists($path)) {
http_response_code(500);
exit(implode("<br/>\n", $output));
}
@ -52,13 +39,11 @@ if (!file_exists(__DIR__."/$path")) {
// Add params
$xml = new DOMDocument();
$xml->load($path);
$processingInstruction = $xml->createProcessingInstruction('xslt-param', "name='name' value='$name'");
$xml->insertBefore($processingInstruction, $xml->documentElement);
$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='$basedir/$firstPath'");
$processingInstruction = $xml->createProcessingInstruction('xslt-param', "name='compareWith' value='$firstPath'");
$xml->insertBefore($processingInstruction, $xml->documentElement);
$xml->save($path);