Compare commits

...

10 Commits

Author SHA1 Message Date
9df3ae155a Merge branch 'master' of https://git.malingrey.fr/adrien/lanScan2 2023-05-16 09:47:55 +02:00
3775302fd1 five columns 2023-05-16 09:47:33 +02:00
d20c41693e change title order 2023-05-15 18:52:25 +02:00
3f662bafcc change 'hosts' to 'group' 2023-05-15 16:40:36 +02:00
87cedd0bce change file extensions 2023-05-15 16:17:18 +02:00
1046de0b8d change file extensions 2023-05-15 16:15:30 +02:00
0ac085a97e -Pn 2023-05-12 17:52:17 +02:00
bc04ce19a7 smb-shares-size in port script 2023-05-12 02:40:34 +02:00
1e26473930 show min(FreeSize/TotalSize) in smb button 2023-05-12 00:24:37 +02:00
657946708a css .share-size 2023-05-11 13:31:17 +02:00
11 changed files with 70 additions and 51 deletions

View File

@ -4,8 +4,8 @@ Scanne des hôtes avec `nmap`
et affiche le résultat dans une page web. 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). * 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 <CIDR>`. Il peut être généré en scannant un réseau avec : `./discover.sh <CIDR>`.
* Scanner avec le script `./scan_all` (utiliser une tâche cron !). * Scanner avec le script `./scan_all.sh` (utiliser une tâche cron !).
* Voir les résultats en ouvrant `.\index.php` dans le navigateur web. * Voir les résultats en ouvrant `.\index.php` dans le navigateur web.
## Exemple ## Exemple

View File

@ -3,8 +3,8 @@
Scan hosts with `nmap` and display results in webpage. Scan hosts with `nmap` and display results in webpage.
* Create a configuration yaml file in ./configs/ subdirectory (see example below). * Create a configuration yaml file in ./configs/ subdirectory (see example below).
It may be generated by scanning a network with `./discover <CIDR>`. It may be generated by scanning a network with `./discover.sh <CIDR>`.
* Scan with `./scan_all` (use a cron task!). * Scan with `./scan_all.sh` (use a cron task!).
* Open `.\index.php` in web browser to see results. * Open `.\index.php` in web browser to see results.
## Example ## Example

View File

@ -19,7 +19,7 @@ site="${network/\//_}"
mkdir -p "scans" mkdir -p "scans"
nmap -F -oX "scans/$site.xml" $network nmap -F -oX "scans/$site.xml" $network
mkdir -p "configs" mkdir -p "configs"
xsltproc --stringparam network "$network" to_config.xsl "scans/$site.xml" > "configs/$site.yaml" xsltproc --stringparam network "$network" to_config.xsl "scans/$site.xml" > "configs/$site.yml"
php to_XML.php "configs/$site.yaml" > "site/$site.xml" php to_XML.php "configs/$site.yml" > "site/$site.xml"
popd > /dev/null popd > /dev/null

View File

@ -8,7 +8,7 @@
<xsl:param name="site"/> <xsl:param name="site"/>
<xsl:template match="lanScan"> <xsl:template match="lanScan">
<xsl:text>nmap -v -T4 -p </xsl:text> <xsl:text>nmap -v -T4 -Pn -p </xsl:text>
<xsl:apply-templates select="//service[not(.=preceding::*)]" /> <xsl:apply-templates select="//service[not(.=preceding::*)]" />
<xsl:text> --script nse/ --datadir nse/ --script-args-file script-args.ini -oX "</xsl:text> <xsl:text> --script nse/ --datadir nse/ --script-args-file script-args.ini -oX "</xsl:text>
<xsl:value-of select="@scanpath"/> <xsl:value-of select="@scanpath"/>
@ -32,4 +32,4 @@
</xsl:if> </xsl:if>
</xsl:template> </xsl:template>
</xsl:stylesheet> </xsl:stylesheet>

View File

@ -20,7 +20,6 @@ license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
portrule = shortport.service({"http", "https", "ssl"}) portrule = shortport.service({"http", "https", "ssl"})
local http = require "http" local http = require "http"
local stdnse = require "stdnse" local stdnse = require "stdnse"

View File

@ -1,7 +1,9 @@
local stdnse = require "stdnse" local stdnse = require "stdnse"
local smb = require "smb" local smb = require "smb"
local msrpc = require "msrpc" local smb2 = require "smb2"
local bin = require "bin" local msrpc = require "msrpc"
local bin = require "bin"
local shortport = require "shortport"
description = [[ description = [[
Return free and total size in octets of each SMB shares Return free and total size in octets of each SMB shares
@ -25,9 +27,8 @@ categories = {"discovery", "intrusive"}
author = "Adrien Malingrey" author = "Adrien Malingrey"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html" license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
hostrule = function(host) portrule = shortport.service({"microsoft-ds", "netbios-ssn", "smb"})
return smb.get_port(host) ~= nil
end
action = function(host) action = function(host)
local status, shares, extra local status, shares, extra
@ -146,7 +147,11 @@ function send_transaction2(smbstate, sub_command, function_parameters, function_
stdnse.debug2("SMB: Sending SMB_COM_TRANSACTION2") stdnse.debug2("SMB: Sending SMB_COM_TRANSACTION2")
local result, err = smb.smb_send(smbstate, header, parameters, data, overrides) local result, err = smb.smb_send(smbstate, header, parameters, data, overrides)
if(result == false) then if(result == false) then
return false, err stdnse.debug1("SMB: Try SMBv2 connexion")
local result, err = smb2.smb2_send(smbstate, header, parameters, data, overrides)
if(result == false) then
return false, err
end
end end
return true return true
@ -157,7 +162,11 @@ function receive_transaction2(smbstate)
-- Read the result -- Read the result
local status, header, parameters, data = smb.smb_read(smbstate) local status, header, parameters, data = smb.smb_read(smbstate)
if(status ~= true) then if(status ~= true) then
return false, header stdnse.debug1("SMB: Try SMBv2 connexion")
local status, header, parameters, data = smb2.smb2_read(smbstate)
if(status ~= true) then
return false, header
end
end end
-- Check if it worked -- Check if it worked

View File

@ -10,7 +10,7 @@
<xsl:template match="lanScan"> <xsl:template match="lanScan">
<html lang="fr"> <html lang="fr">
<head> <head>
<title>lanScan - <xsl:value-of select="@site"/></title> <title><xsl:value-of select="@site"/> - lanScan</title>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.3/dist/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.3/dist/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/fomantic-ui@2.9.2/dist/semantic.min.css"/> <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/fomantic-ui@2.9.2/dist/semantic.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/fomantic-ui@2.9.2/dist/semantic.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/fomantic-ui@2.9.2/dist/semantic.min.js"></script>
@ -34,19 +34,11 @@
margin: auto; margin: auto;
} }
.button.share-size {
--bg: #21ba45;
}
.item.share-size {
--bg: white;
}
.share-size { .share-size {
--free-ratio: calc(var(--free) / var(--total)); --free-ratio: calc(var(--free) / var(--total));
--used-percent: calc(100% - 100%*var(--free-ratio)); --used-percent: calc(100% - 100%*var(--free-ratio));
--color: hsl(calc(120*var(--free-ratio)) 100% 50%); --color: hsl(calc(120*var(--free-ratio)) 100% 50%);
background: linear-gradient(to right, var(--color) var(--used-percent), var(--bg) var(--used-percent), var(--bg)) !important; background-image: linear-gradient(to right, var(--color) var(--used-percent), transparent var(--used-percent), transparent) !important;
} }
</style> </style>
<meta http-equiv="refresh" content="60"/> <meta http-equiv="refresh" content="60"/>
@ -77,7 +69,7 @@
</div> </div>
</xsl:when> </xsl:when>
</xsl:choose> </xsl:choose>
<xsl:apply-templates select="hosts"/> <xsl:apply-templates select="group"/>
</div> </div>
<script> <script>
$('.ui.dropdown').dropdown() $('.ui.dropdown').dropdown()
@ -86,9 +78,9 @@
</html> </html>
</xsl:template> </xsl:template>
<xsl:template match="hosts"> <xsl:template match="group">
<h1 class="ui header"><xsl:value-of select="@name"/></h1> <h1 class="ui header"><xsl:value-of select="@name"/></h1>
<div class="ui doubling stackable four column compact grid"> <div class="ui doubling stackable five column compact grid">
<xsl:apply-templates select="host"/> <xsl:apply-templates select="host"/>
</div> </div>
</xsl:template> </xsl:template>
@ -150,10 +142,8 @@
<xsl:variable name="scannedPort" select="$scannedHost/ports/port[service/@name=$serviceName or @portid=$serviceName][1]"/> <xsl:variable name="scannedPort" select="$scannedHost/ports/port[service/@name=$serviceName or @portid=$serviceName][1]"/>
<xsl:variable name="state"> <xsl:variable name="state">
<xsl:choose> <xsl:choose>
<xsl:when test="$scannedPort/script[@id='http-info']/elem[@key='status']>=500">red</xsl:when>
<xsl:when test="$scannedPort/script[@id='http-info']/elem[@key='status']>=400">yellow</xsl:when>
<xsl:when test="$scannedPort/state/@state='filtered'">yellow</xsl:when>
<xsl:when test="$scannedPort/state/@state='open'">green</xsl:when> <xsl:when test="$scannedPort/state/@state='open'">green</xsl:when>
<xsl:when test="$scannedPort/state/@state='filtered'">yellow</xsl:when>
<xsl:otherwise>red</xsl:otherwise> <xsl:otherwise>red</xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:variable> </xsl:variable>
@ -165,29 +155,49 @@
<xsl:value-of select="$scannedPort/state/@state"/> <xsl:value-of select="$scannedPort/state/@state"/>
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<xsl:value-of select="$scannedPort/service/@name"/> <xsl:value-of select="$scannedPort/service/@name"/>
<xsl:if test="$scannedPort/script[@id='http-info']"><xsl:text>
</xsl:text><xsl:value-of select="$scannedPort/script[@id='http-info']/elem[@key='status-line']"/>
<xsl:value-of select="$scannedPort/script[@id='http-info']/elem[@key='title']"/>
</xsl:if>
</xsl:variable> </xsl:variable>
<xsl:choose> <xsl:choose>
<xsl:when test="($scannedPort/service/@name='microsoft-ds' or $scannedPort/service/@name='netbios-ssn' or $scannedPort/service/@name='smb') and $scannedHost/hostscript/script[@id='smb-shares-size']"> <xsl:when test="$scannedPort/script[@id='smb-shares-size']/table">
<div class="ui {$state} dropdown mini button share-size" title="{$title}" style="--free:{$scannedHost/hostscript/script[@id='smb-shares-size']/table/elem[@key='FreeSize']}; --total:{$scannedHost/hostscript/script[@id='smb-shares-size']/table/elem[@key='TotalSize']}"> <div class="ui {$state} dropdown mini button share-size" title="{$title}">
<xsl:attribute name="style">
<xsl:for-each select="$scannedPort/script[@id='smb-shares-size']/table">
<xsl:sort select="elem[@key='FreeSize'] div elem[@key='TotalSize']" order="ascending"/>
<xsl:if test="position()=1">
<xsl:text>--free: </xsl:text>
<xsl:value-of select="elem[@key='FreeSize']"/>
<xsl:text>; --total: </xsl:text>
<xsl:value-of select="elem[@key='TotalSize']"/>
</xsl:if>
</xsl:for-each>
</xsl:attribute>
<xsl:value-of select="$serviceName"/> <xsl:value-of select="$serviceName"/>
<i class="dropdown icon"></i> <i class="dropdown icon"></i>
<div class="menu"> <div class="menu">
<!-- xsl:apply-templates select="$scannedHost/hostscript/script[@id='smb-shares-size']/table[not(contains(@key, '$'))]" --> <xsl:apply-templates select="$scannedPort/script[@id='smb-shares-size']/table">
<xsl:apply-templates select="$scannedHost/hostscript/script[@id='smb-shares-size']/table">
<xsl:with-param name="scannedHostAddress" select="$scannedHostAddress"/> <xsl:with-param name="scannedHostAddress" select="$scannedHostAddress"/>
</xsl:apply-templates> </xsl:apply-templates>
</div> </div>
</div> </div>
</xsl:when> </xsl:when>
<xsl:when test="$scannedPort/service/@name='ms-wbt-server' or $scannedPort/service/@name='msrpc'"> <xsl:when test="$scannedPort/service/@name='ms-wbt-server' or $scannedPort/service/@name='rdp'">
<a class="ui {$state} mini button" href="../rdp.php?v={$scannedHostAddress}:{$scannedPort/@portid}" title="{$title}"> <a class="ui {$state} mini button" href="../rdp.php?v={$scannedHostAddress}:{$scannedPort/@portid}" title="{$title}">
<xsl:value-of select="$serviceName"/> <xsl:value-of select="$serviceName"/>
</a> </a>
</xsl:when> </xsl:when>
<xsl:when test="$scannedPort/script[@id='http-info']">
<xsl:variable name="status">
<xsl:choose>
<xsl:when test="$scannedPort/script[@id='http-info']/elem[@key='status']>=500">red</xsl:when>
<xsl:when test="$scannedPort/script[@id='http-info']/elem[@key='status']>=400">yellow</xsl:when>
<xsl:when test="$scannedPort/script[@id='http-info']/elem[@key='status']>=200">green</xsl:when>
<xsl:otherwise>red</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a class="ui {$status} mini button" href="{$scannedPort/service/@name}://{$scannedHostAddress}:{$scannedPort/@portid}" target="_blank"
title="{$scannedPort/script[@id='http-info']/elem[@key='title' or @key='status-line']}">
<xsl:value-of select="$serviceName"/>
</a>
</xsl:when>
<xsl:when test="$scannedPort/service/@name='ftp' or $scannedPort/service/@name='ssh' or $scannedPort/service/@name='http' or $scannedPort/service/@name='https'"> <xsl:when test="$scannedPort/service/@name='ftp' or $scannedPort/service/@name='ssh' or $scannedPort/service/@name='http' or $scannedPort/service/@name='https'">
<a class="ui {$state} mini button" href="{$scannedPort/service/@name}://{$scannedHostAddress}:{$scannedPort/@portid}" target="_blank" title="{$title}"> <a class="ui {$state} mini button" href="{$scannedPort/service/@name}://{$scannedHostAddress}:{$scannedPort/@portid}" target="_blank" title="{$title}">
<xsl:value-of select="$serviceName"/> <xsl:value-of select="$serviceName"/>
@ -204,7 +214,7 @@
<xsl:template match="table"> <xsl:template match="table">
<xsl:param name="scannedHostAddress"/> <xsl:param name="scannedHostAddress"/>
<a class="item share-size" href="file://///{$scannedHostAddress}/{@key}" target="_blank" rel="noopener noreferrer" style="--free:{elem[@key='FreeSize']}; --total:{elem[@key='TotalSize']}"> <a class="item share-size" href="file://///{$scannedHostAddress}/{@key}" target="_blank" rel="noopener noreferrer" style="--free: {elem[@key='FreeSize']}; --total: {elem[@key='TotalSize']}">
<xsl:value-of select="@key"/> <xsl:value-of select="@key"/>
</a> </a>
</xsl:template> </xsl:template>

View File

@ -6,9 +6,9 @@ if [ "$#" -ne 1 ]; then
fi fi
pushd "$(dirname -- "$0")" > /dev/null pushd "$(dirname -- "$0")" > /dev/null
site="$(basename ${1/.yaml/})" site="$(basename ${1/.yml/})"
php "to_XML.php" "configs/$site.yaml" > "site/$site.xml" \ php "to_XML.php" "configs/$site.yml" > "site/$site.xml" \
&& eval $(xsltproc "nmap_cmd.xsl" "site/$site.xml") \ && eval $(xsltproc "nmap_cmd.xsl" "site/$site.xml") \
&& mv "scans/$site.xml.tmp" "scans/$site.xml" && mv "scans/$site.xml.tmp" "scans/$site.xml"

View File

@ -5,11 +5,11 @@ pushd "$(dirname -- $0)" > /dev/null
mkdir -p scans mkdir -p scans
mkdir -p site mkdir -p site
for config in configs/*.yaml for config in configs/*.yml
do do
site="$(basename ${config/.yaml/})" site="$(basename ${config/.yml/})"
echo "Scan $site" echo "Scan $site"
./scan "$site" ./scan.sh "$site"
done done
popd > /dev/null popd > /dev/null

View File

@ -1,6 +1,6 @@
<?php <?php
$file = $argv[1]; $file = $argv[1];
$site = basename($file, ".yaml"); $site = basename($file, ".yml");
$__DIR__ = __DIR__; $__DIR__ = __DIR__;
$conf = yaml_parse_file($file); $conf = yaml_parse_file($file);

View File

@ -11,11 +11,12 @@
<xsl:text>--- <xsl:text>---
site: Nom du site site: Nom du site
hosts: group:
- name: Réseau </xsl:text><xsl:value-of select="$network"/><xsl:text> - name: Réseau </xsl:text><xsl:value-of select="$network"/><xsl:text>
host: host:
</xsl:text> </xsl:text>
<xsl:apply-templates select="host"/> <xsl:apply-templates select="host"/>
<xsl:text>...</xsl:text>
</xsl:template> </xsl:template>
<xsl:template match="host"> <xsl:template match="host">