diff --git a/LISEZMOI.md b/LISEZMOI.md new file mode 100644 index 0000000..a8f7855 --- /dev/null +++ b/LISEZMOI.md @@ -0,0 +1,28 @@ +# lanScan + +Scanne des hôtes avec `nmap` +et affiche le résultat dans une page web. + +* Créer un fichier de configuration YAML dans un sous-dossier ./configs/ (voir l'exemple ci-dessous). +Il peut être généré en scannant un réseau avec : `./discover `. +* Scanner avec le script `./scan_all` (utiliser une tâche cron !). +* Voir les résultats en ouvrant `.\index.php` dans le navigateur web. + +## Exemple +```yaml +--- +site: Nom du site + +hosts: + - name: Nom du premier groupe + host: + - address: host1.local + services: [ssh, http] + - address: 192.168.1.100 + services: [ftp, https, 5432] + - name: Nom du 2ème groupe + host: + - adress: host3.local + services: [ssh, ftp, 8006] +``` + diff --git a/README.md b/README.md index a71d3f7..3b6afa2 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,13 @@ # lanScan -Scanne des hôtes spécifiées avec un fichier de configuration en YAML -et affiche le résultat dans une page web. +Scan hosts with `nmap` and display results in webpage. -* Créer un fichier de configuration YAML dans un sous-dossier ./configs/ (voir l'exemple ci-dessous). -Il peut être généré en scannant un réseau (en notation CIDR) avec : `./discover XXX.XXX.XXX.XXX/XX`. -* Scanner avec le script `./scan_all` (utiliser une tâche cron !). -* Voir les résultats dans le navigateur web. +* Create a configuration yaml file in ./configs/ subdirectory (see example below). +It may be generated by scanning a network with `./discover `. +* Scan with `./scan_all` (use a cron task!). +* Open `.\index.php` in web browser to see results. -## Exemple +## Example ```yaml --- site: Nom du site diff --git a/discover b/discover index f952913..f44050c 100755 --- a/discover +++ b/discover @@ -3,17 +3,23 @@ ### # # Scan un réseau avec nmap pour créer un fichier de configuration -# Usage : ./discover avec network en notation CIDR XXX.XXX.XXX.XXX/XX +# Usage : ./discover avec reseau en notation CIDR XXX.XXX.XXX.XXX/XX # ### -DIR="$(dirname -- "$0")" +if [ "$#" -ne 1 ]; then + echo -e "Usage : ./discover \navec l'adresse réseau en notation CIDR (XXX.XXX.XXX.XXX/XX)" >&2 + exit 1 +fi + +pushd "$(dirname -- "$0")" > /dev/null network="$1" -filename="${network/\//_}" +site="${network/\//_}" -mkdir -p "$DIR/scans" -nmap -F -oX "$DIR/scans/$filename.xml" $network -mkdir -p "$DIR/configs" -xsltproc --stringparam network "$network" to_config.xsl "$DIR/scans/$filename.xml" > "$DIR/configs/$filename.yaml" -php to_XML.php "$DIR/configs/$filename.yaml" > "$DIR/site/$site.xml" +mkdir -p "scans" +nmap -F -oX "scans/$site.xml" $network +mkdir -p "configs" +xsltproc --stringparam network "$network" to_config.xsl "scans/$site.xml" > "configs/$site.yaml" +php to_XML.php "configs/$site.yaml" > "site/$site.xml" +popd > /dev/null \ No newline at end of file diff --git a/nmap_cmd.php b/nmap_cmd.php deleted file mode 100644 index 7324a83..0000000 --- a/nmap_cmd.php +++ /dev/null @@ -1,43 +0,0 @@ - - - -XML -); - -$targets = []; -$services = []; - -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); - $targets[$hostaddress] = true; - if ($servicesList) foreach ($servicesList as $service) { - $xmlService = $xmlHost->addChild("service"); - $xmlService->addAttribute("name", $service); - $services[$service] = true; - } - } - } -} - -$xml->asXML("site/$site.xml"); - -$targets = join(array_keys($targets), " "); -$services = join(array_keys($services), ","); - -echo ("nmap -v -T4 -p $services --script $__DIR__/http-info.nse -oX $__DIR__/scans/.~$site.xml $targets"); -?> diff --git a/nmap_cmd.xsl b/nmap_cmd.xsl index 1c265a7..2c20c54 100644 --- a/nmap_cmd.xsl +++ b/nmap_cmd.xsl @@ -10,7 +10,7 @@ nmap -v -T4 -p - --script "$DIR/http-info.nse" -oX "$DIR/ + --script "http-info.nse" -oX " .tmp" diff --git a/scan b/scan index 2705fd3..587408e 100755 --- a/scan +++ b/scan @@ -1,9 +1,15 @@ #!/usr/bin/env bash -export DIR="$(dirname -- "$0")" -config="$1" +if [ "$#" -ne 1 ]; then + echo "Usage: ./scan " >&2 + exit 1 +fi -site="$(basename ${config/.yaml/})" -php to_XML.php "$config" > "$DIR/site/$site.xml" -xsltproc nmap_cmd.xsl "$DIR/site/$site.xml" | sh -mv "$DIR/scans/$site.xml.tmp" "$DIR/scans/$site.xml" \ No newline at end of file +pushd "$(dirname -- "$0")" > /dev/null +site="$(basename ${1/.yaml/})" + +php "to_XML.php" "configs/$site.yaml" > "site/$site.xml" +eval $(xsltproc "nmap_cmd.xsl" "site/$site.xml") +mv "scans/$site.xml.tmp" "scans/$site.xml" + +popd > /dev/null \ No newline at end of file diff --git a/scan_all b/scan_all index 8f0d990..359aca7 100755 --- a/scan_all +++ b/scan_all @@ -1,12 +1,15 @@ #!/usr/bin/env bash -DIR="$(dirname -- $0)" +pushd "$(dirname -- $0)" > /dev/null -mkdir -p "$DIR"/scans -mkdir -p "$DIR"/site +mkdir -p scans +mkdir -p site -for config in "$DIR"/configs/*.yaml +for config in configs/*.yaml do - echo $config - ./scan "$config" & + site="$(basename ${config/.yaml/})" + echo "Scan $site" + ./scan "$site" & done + +popd > /dev/null \ No newline at end of file diff --git a/to_XML.php b/to_XML.php index 56228e1..ebea4ef 100644 --- a/to_XML.php +++ b/to_XML.php @@ -5,10 +5,12 @@ $__DIR__ = __DIR__; $conf = yaml_parse_file($file); -$xml = new DomDocument("1.0"); +$xml = new DomDocument("1.0", "utf-8"); +$xml->preserveWhiteSpace = false; +$xml->formatOutput = true; $xml->appendChild($xml->createProcessingInstruction("xml-stylesheet", "href='../results.xsl' type='text/xsl'")); $root = $xml->appendChild($xml->createElement("lanScan")); -$root->setAttribute("scanpath", "scans/$site.xml"); +$root->setAttribute("scanpath", "./scans/$site.xml"); function appendArray($document, $node, $array) { foreach ($array as $key => $value) {