Skip to content

Commit

Permalink
Use a more straightforward return style in script rules. Instead of
Browse files Browse the repository at this point in the history
	if cond then
		return true
	else
		return false
	end

just do

	return cond
  • Loading branch information
david committed Nov 18, 2008
1 parent f4b970f commit 85deff9
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 127 deletions.
8 changes: 1 addition & 7 deletions scripts/auth-owners.nse
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,10 @@ portrule = function(host, port)
local auth_port = { number=113, protocol="tcp" }
local identd = nmap.get_port_state(host, auth_port)

if
identd ~= nil
return identd ~= nil
and identd.state == "open"
and port.protocol == "tcp"
and port.state == "open"
then
return true
else
return false
end
end

action = function(host, port)
Expand Down
2 changes: 1 addition & 1 deletion scripts/banner.nse
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ local stdnse = require "stdnse"
---
-- Script is executed for any TCP port.
portrule = function( host, port )
return (port.protocol == "tcp" and true) or false
return port.protocol == "tcp"
end


Expand Down
1 change: 0 additions & 1 deletion scripts/dns-random-txid.nse
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

description = [[
Checks a DNS server for the predictable-TXID DNS recursion
vulnerability. Predictable TXID values can make a DNS server vulnerable to
Expand Down
9 changes: 1 addition & 8 deletions scripts/mysql-info.nse
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,12 @@ end
portrule = function(host, port)
local extra = port.version.extrainfo

if
(port.number == 3306
or port.service == "mysql")
return (port.number == 3306 or port.service == "mysql")
and port.protocol == "tcp"
and port.state == "open"
and not (extra ~= nil
and (extra:match("[Uu]nauthorized")
or extra:match("[Tt]oo many connection")))
then
return true
end

return false
end

action = function(host, port)
Expand Down
10 changes: 2 additions & 8 deletions scripts/nbstat.nse
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,12 @@ hostrule = function(host)
local port_u137 = nmap.get_port_state(host,
{number=137, protocol="udp"})

if (
(port_t135 ~= nil and port_t135.state == "open") or
return (port_t135 ~= nil and port_t135.state == "open") or
(port_t139 ~= nil and port_t139.state == "open") or
(port_t445 ~= nil and port_t445.state == "open") or
(port_u137 ~= nil and
(port_u137.state == "open" or
port_u137.state == "open|filtered")))
then
return true
else
return false
end
port_u137.state == "open|filtered"))
end


Expand Down
10 changes: 1 addition & 9 deletions scripts/smb-check-vulns.nse
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@ require 'smb'
require 'stdnse'

hostrule = function(host)

local port = smb.get_port(host)

if(port == nil) then
return false
else
return true
end

return smb.get_port(host) ~= nil
end

local VULNERABLE = 1
Expand Down
10 changes: 1 addition & 9 deletions scripts/smb-enum-domains.nse
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,7 @@ require 'smb'
require 'stdnse'

hostrule = function(host)

local port = smb.get_port(host)

if(port == nil) then
return false
else
return true
end

return smb.get_port(host) ~= nil
end

action = function(host)
Expand Down
10 changes: 1 addition & 9 deletions scripts/smb-enum-sessions.nse
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,7 @@ require 'smb'
require 'stdnse'

hostrule = function(host)

local port = smb.get_port(host)

if(port == nil) then
return false
else
return true
end

return smb.get_port(host) ~= nil
end

---Attempts to enumerate the sessions on a remote system using MSRPC calls. This will likely fail
Expand Down
10 changes: 1 addition & 9 deletions scripts/smb-enum-shares.nse
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,7 @@ require 'smb'
require 'stdnse'

hostrule = function(host)

local port = smb.get_port(host)

if(port == nil) then
return false
else
return true
end

return smb.get_port(host) ~= nil
end

---Attempts to enumerate the shares on a remote system using MSRPC calls. This will likely fail
Expand Down
10 changes: 1 addition & 9 deletions scripts/smb-enum-users.nse
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,7 @@ require 'smb'
require 'stdnse'

hostrule = function(host)

local port = smb.get_port(host)

if(port == nil) then
return false
else
return true
end

return smb.get_port(host) ~= nil
end

---Attempt to enumerate users through SAMR methods. See the file description for more information.
Expand Down
10 changes: 1 addition & 9 deletions scripts/smb-os-discovery.nse
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ require 'stdnse'

--- Check whether or not this script should be run.
hostrule = function(host)

local port = smb.get_port(host)

if(port == nil) then
return false
else
return true
end

return smb.get_port(host) ~= nil
end

--- Converts numbered Windows version strings (<code>"Windows 5.0"</code>, <code>"Windows 5.1"</code>) to names (<code>"Windows 2000"</code>, <code>"Windows XP"</code>).
Expand Down
10 changes: 1 addition & 9 deletions scripts/smb-security-mode.nse
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,7 @@ require 'smb'

-- Check whether or not this script should be run.
hostrule = function(host)

local port = smb.get_port(host)

if(port == nil) then
return false
else
return true
end

return smb.get_port(host) ~= nil
end


Expand Down
10 changes: 1 addition & 9 deletions scripts/smb-server-stats.nse
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,7 @@ require 'smb'
require 'stdnse'

hostrule = function(host)

local port = smb.get_port(host)

if(port == nil) then
return false
else
return true
end

return smb.get_port(host) ~= nil
end

action = function(host)
Expand Down
10 changes: 1 addition & 9 deletions scripts/smb-system-info.nse
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,7 @@ require 'smb'
require 'stdnse'

hostrule = function(host)

local port = smb.get_port(host)

if(port == nil) then
return false
else
return true
end

return smb.get_port(host) ~= nil
end

---Retrieves the requested value from the registry.
Expand Down
15 changes: 2 additions & 13 deletions scripts/smtp-strangeport.nse
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,10 @@ license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
categories = {"malware"}

portrule = function(host, port)
if
( port.number ~= 25
and
port.number ~= 465
and
port.number ~= 587
and
port.service == "smtp" )
return port.service == "smtp" and
port.number ~= 25 and port.number ~= 465 and port.number ~= 587
and port.protocol == "tcp"
and port.state == "open"
then
return true
else
return false
end
end

action = function()
Expand Down
13 changes: 5 additions & 8 deletions scripts/sniffer-detect.nse
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ categories = {"discovery"}

-- okay, we're interested only in hosts that are on our ethernet lan
hostrule = function(host, port)
if host.directly_connected == true and
host.mac_addr ~= nil and
host.mac_addr_src ~= nil and
host.interface ~= nil and
nmap.get_interface_link(host.interface) == 'ethernet' then
return true
end
return false
return host.directly_connected == true and
host.mac_addr ~= nil and
host.mac_addr_src ~= nil and
host.interface ~= nil and
nmap.get_interface_link(host.interface) == 'ethernet'
end

--[[
Expand Down

0 comments on commit 85deff9

Please sign in to comment.