57 lines
1.7 KiB
PHP
Executable File
57 lines
1.7 KiB
PHP
Executable File
<?php
|
|
|
|
include_once 'config.php';
|
|
include_once 'filter_inputs.php';
|
|
|
|
if (!$targets) {
|
|
http_response_code(400);
|
|
die('Paramètre manquant : targets');
|
|
}
|
|
|
|
if (!file_exists($SCANS_DIR)) {
|
|
mkdir($SCANS_DIR);
|
|
}
|
|
|
|
$basedir = "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}" . dirname($_SERVER['REQUEST_URI']);
|
|
|
|
$args = '';
|
|
foreach ($inputs as $arg => $value) {
|
|
if (is_null($value)) {
|
|
http_response_code(400);
|
|
die("Valeur incorecte pour le paramètre $arg : " . filter_input(INPUT_GET, $arg, FILTER_SANITIZE_FULL_SPECIAL_CHARS));
|
|
} else if ($value) {
|
|
if ($value === true) {
|
|
if (strlen($arg)<=2) $args .= " -$arg";
|
|
else $arg = "--$arg";
|
|
} else {
|
|
if (strlen($arg)<=2) $args .= " -$arg" . ($value);
|
|
else $arg = "--$arg " . ($value);
|
|
}
|
|
}
|
|
}
|
|
|
|
exec("nmap$args --stylesheet $basedir/stylesheet.xsl -oX - $targets 2>&1", $result, $code);
|
|
if ($code) {
|
|
http_response_code(500);
|
|
die(implode("<br/>\n", $result));
|
|
}
|
|
|
|
$xml = new DOMDocument();
|
|
$xml->loadXML(implode("\n", $result));
|
|
|
|
$xml->insertBefore($xml->createProcessingInstruction('xslt-param', "name='name' value='$name'"), $xml->documentElement);
|
|
$xml->insertBefore($xml->createProcessingInstruction('xslt-param', "name='scansDir' value='$SCANS_DIR'"), $xml->documentElement);
|
|
$xml->insertBefore($xml->createProcessingInstruction('xslt-param', "name='compareWith' value='$compareWith'"), $xml->documentElement);
|
|
|
|
if ($name) {
|
|
if (!file_exists($SCANS_DIR)) mkdir($SCANS_DIR);
|
|
$path = "$SCANS_DIR/$name.xml";
|
|
$xml->save($path);
|
|
|
|
header("Location: $path");
|
|
exit();
|
|
} else {
|
|
header('Content-type: text/xml');
|
|
exit($xml->saveXML());
|
|
}
|