smb-shares-size in port script

This commit is contained in:
Adrien MALINGREY 2023-05-12 02:40:34 +02:00
parent 1e26473930
commit bc04ce19a7
3 changed files with 25 additions and 18 deletions

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,8 @@
local stdnse = require "stdnse" local stdnse = require "stdnse"
local smb = require "smb" local smb = require "smb"
local msrpc = require "msrpc" local msrpc = require "msrpc"
local bin = require "bin" 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 +26,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

View File

@ -142,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>
@ -157,16 +155,12 @@
<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}"> <div class="ui {$state} dropdown mini button share-size" title="{$title}">
<xsl:attribute name="style"> <xsl:attribute name="style">
<xsl:for-each select="$scannedHost/hostscript/script[@id='smb-shares-size']/table"> <xsl:for-each select="$scannedPort/script[@id='smb-shares-size']/table">
<xsl:sort select="elem[@key='FreeSize'] div elem[@key='TotalSize']" order="ascending"/> <xsl:sort select="elem[@key='FreeSize'] div elem[@key='TotalSize']" order="ascending"/>
<xsl:if test="position()=1"> <xsl:if test="position()=1">
<xsl:text>--free: </xsl:text> <xsl:text>--free: </xsl:text>
@ -179,7 +173,7 @@
<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"> <xsl:apply-templates select="$scannedPort/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>
@ -190,6 +184,20 @@
<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"/>