diff --git a/README.md b/README.md index 7c21adb..a699f2d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Scan hosts with nmap and display results in webpage. * Create a configuration yaml file in confs/ subdirectory (see example below). It may be generated by scanning a network with `init.sh`. -* Scan with `php scan_all.php` (use a cron task!). +* Scan with `./scan_all.sh` (use a cron task!). * Open index.php to see results. ## Example diff --git a/init.sh b/init.sh index a2c068f..925d627 100755 --- a/init.sh +++ b/init.sh @@ -16,4 +16,4 @@ read network nmap --script smb-enum-shares.nse -oX "scans/$filename.xml" $network -xsltproc --stringparam site "$site" --stringparam network $network toyaml.xsl "$DIR/scans/$filename.xml" > "$DIR/confs/$filename.yaml" +xsltproc --stringparam site "$site" --stringparam network $network to_yaml.xsl "$DIR/scans/$filename.xml" > "$DIR/confs/$filename.yaml" diff --git a/nmap_cmd.php b/nmap_cmd.php new file mode 100644 index 0000000..116aded --- /dev/null +++ b/nmap_cmd.php @@ -0,0 +1,26 @@ + $value) { + if ($key != "site") { + foreach($value as $hostaddress => $servicesList) { + $targets[$hostaddress] = true; + if ($servicesList) foreach ($servicesList as $service) { + $services[$service] = true; + } + } + } +} + +$targets = join(array_keys($targets), " "); +$services = join(array_keys($services), ","); + +echo ("nmap -v -Pn -p $services --script smb-enum-shares,$__DIR__/nmap -oX $__DIR__/scans/.~$site.xml $targets"); +?> diff --git a/scan_all.php b/scan_all.php index 07a011e..9ef5459 100644 --- a/scan_all.php +++ b/scan_all.php @@ -1,4 +1,6 @@ asXML("$__DIR__/site/$site.xml"); } diff --git a/scan_all.sh b/scan_all.sh new file mode 100755 index 0000000..0c7f2bd --- /dev/null +++ b/scan_all.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +DIR="$(dirname -- "$0")" + +mkdir -p "$DIR/scans" +mkdir -p "$DIR/site" + +for conf in confs/*.yaml +do + 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" +done diff --git a/to_xml.php b/to_xml.php new file mode 100644 index 0000000..0d4fc4a --- /dev/null +++ b/to_xml.php @@ -0,0 +1,32 @@ + + + +XML +); + +foreach ($conf as $key => $value) { + if ($key == "site") { + $xml->addAttribute("site", $value); + } else { + $xmlGroup = $xml->addChild("group"); + $xmlGroup->addAttribute("name", $key); + foreach($value as $hostaddress => $servicesList) { + $xmlHost = $xmlGroup->addChild("host"); + $xmlHost->addAttribute("address", $hostaddress); + if ($servicesList) foreach ($servicesList as $service) { + $xmlService = $xmlHost->addChild("service"); + $xmlService->addAttribute("name", $service); + } + } + } +} + +echo $xml->asXML(); +?> diff --git a/toyaml.xsl b/to_yaml.xsl similarity index 100% rename from toyaml.xsl rename to to_yaml.xsl