fix scan_all.sh
This commit is contained in:
parent
fad7c6164e
commit
c6e1977ca2
59
scan_all.php
59
scan_all.php
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
set_time_limit(0);
|
||||
|
||||
if (! function_exists('str_ends_with')) {
|
||||
function str_ends_with(string $haystack, string $needle): bool {
|
||||
$needle_len = strlen($needle);
|
||||
return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, - $needle_len));
|
||||
}
|
||||
}
|
||||
|
||||
$__DIR__ = __DIR__;
|
||||
|
||||
if (!file_exists("$__DIR__/scans")) mkdir("$__DIR__/scans");
|
||||
if (!file_exists("$__DIR__/site")) mkdir("$__DIR__/site");
|
||||
|
||||
foreach (scandir("$__DIR__/confs") as $file) {
|
||||
if (str_ends_with($file, ".yaml")) {
|
||||
$site = str_replace(".yaml", "", $file);
|
||||
$yaml = yaml_parse_file("$__DIR__/confs/$file");
|
||||
|
||||
$targets = [];
|
||||
$services = [];
|
||||
|
||||
$xml = new SimpleXMLElement(<<<XML
|
||||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href='../results.xsl' type='text/xsl'?>
|
||||
<lanScanConf/>
|
||||
XML
|
||||
);
|
||||
$xml->addAttribute("scanpath", "scans/$site.xml");
|
||||
|
||||
foreach ($yaml as $key => $value) {
|
||||
if ($key == "site") {
|
||||
$xml->addAttribute("site", $value);
|
||||
} else {
|
||||
$xmlGroup = $xml->addChild("group");
|
||||
$xmlGroup->addAttribute("name", $key);
|
||||
foreach($value as $hostaddress => $servicesList) {
|
||||
$targets[$hostaddress] = true;
|
||||
$xmlHost = $xmlGroup->addChild("host");
|
||||
$xmlHost->addAttribute("address", $hostaddress);
|
||||
if ($servicesList) foreach ($servicesList as $service) {
|
||||
$services[$service] = true;
|
||||
$xmlService = $xmlHost->addChild("service");
|
||||
$xmlService->addAttribute("name", $service);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$targets = join(array_keys($targets), " ");
|
||||
$services = join(array_keys($services), ",");
|
||||
|
||||
`nmap -v -Pn -p $services --script smb-enum-shares,"$__DIR__/nmap" -oX "$__DIR__/scans/.~$site.xml" $targets && mv "$__DIR__/scans/.~$site.xml" "$__DIR__/scans/$site.xml"`;
|
||||
|
||||
$xml->asXML("$__DIR__/site/$site.xml");
|
||||
}
|
||||
}
|
||||
?>
|
@ -2,12 +2,12 @@
|
||||
|
||||
DIR="$(dirname -- "$0")"
|
||||
|
||||
mkdir -p "$DIR/scans"
|
||||
mkdir -p "$DIR/site"
|
||||
mkdir -p "$DIR"/scans
|
||||
mkdir -p "$DIR"/site
|
||||
|
||||
for conf in "$DIR/confs/*.yaml"
|
||||
for conf in "$DIR"/confs/*.yaml
|
||||
do
|
||||
site="basename ${conf/.yaml/}"
|
||||
site="$(basename ${conf/.yaml/})"
|
||||
php "$DIR/to_xml.php" $conf > "$DIR/site/$site.xml"
|
||||
php "$DIR/nmap_cmd.php" $conf | sh
|
||||
mv "$DIR/scans/.~$site.xml" "$DIR/scans/$site.xml"
|
||||
|
Reference in New Issue
Block a user