diff --git a/scripts/HTTPAuth.nse b/scripts/HTTPAuth.nse index 5092dcb13..4f6417d1c 100644 --- a/scripts/HTTPAuth.nse +++ b/scripts/HTTPAuth.nse @@ -13,19 +13,9 @@ license = "See nmaps COPYING for licence" -- categories = {"safe"} categories = {"intrusive"} -portrule = function(host, port) - if - ( port.number == 80 - or port.number == 8080 - or port.service == "http") - and port.protocol == "tcp" - and port.state == "open" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.port_or_service({80, 8080}, "http") action = function(host, port) local socket diff --git a/scripts/MSSQLm.nse b/scripts/MSSQLm.nse index d8a1c9f82..4e6e42b62 100644 --- a/scripts/MSSQLm.nse +++ b/scripts/MSSQLm.nse @@ -12,21 +12,9 @@ license = "See nmaps COPYING for licence" categories = {"discovery", "intrusive"} require('stdnse') +require "shortport" -portrule = function(host, port) - if - ( port.number == 1433 - or port.number == 1434 ) - and port.protocol == "udp" - -- if we only run against open or open|filtered ports anyway, leave next two lines commented - -- and ( port.state == "open" - -- or port.state == "open|filtered" ) - then - return true - else - return false - end -end +portrule = shortport.portnumber({1433, 1434}, "udp", {"open", "open|filtered"}) action = function(host, port) diff --git a/scripts/RealVNC_auth_bypass.nse b/scripts/RealVNC_auth_bypass.nse index 9d4ee9325..eccd69f35 100644 --- a/scripts/RealVNC_auth_bypass.nse +++ b/scripts/RealVNC_auth_bypass.nse @@ -5,17 +5,9 @@ license = "See nmaps COPYING for licence" categories = {"backdoor"} -portrule = function(host, port) - if (port.number == 5900 - or port.service == "vnc") - and port.protocol == "tcp" - and port.state == "open" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.port_or_service(5900, "vnc") action = function(host, port) local socket = nmap.new_socket() diff --git a/scripts/SMTP_openrelay_test.nse b/scripts/SMTP_openrelay_test.nse index 6b7c54b93..0e8fa4ea6 100644 --- a/scripts/SMTP_openrelay_test.nse +++ b/scripts/SMTP_openrelay_test.nse @@ -14,18 +14,11 @@ id="Open Relay SMTP" description="Checks to see if a SMTP server is an open relay" categories = {"demo"} +require "shortport" + ourdomain="scanme.org" -portrule = function(host, port) - if (port.number == 25 - or port.service == "smtp") - and port.protocol == "tcp" - then - return true - else - return false - end -end +portrule = shortport.port_or_service(25, "smtp") action = function(host, port) local socket = nmap.new_socket() diff --git a/scripts/SMTPcommands.nse b/scripts/SMTPcommands.nse index 63b256684..a3b7952a3 100644 --- a/scripts/SMTPcommands.nse +++ b/scripts/SMTPcommands.nse @@ -12,19 +12,9 @@ author = "Jason DePriest " license = "See nmaps COPYING for licence" categories = {"discovery", "intrusive"} -portrule = function(host, port) - if (port.number == 25 - or port.number == 587 - or port.number == 465 - or port.service == "smtp") - and port.state == "open" - and port.protocol == "tcp" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.port_or_service({25, 587, 465}, "smtp") action = function(host, port) diff --git a/scripts/SNMPsysdesr.nse b/scripts/SNMPsysdesr.nse index 42b1f1a21..03efcd7da 100644 --- a/scripts/SNMPsysdesr.nse +++ b/scripts/SNMPsysdesr.nse @@ -11,19 +11,9 @@ license = "See nmaps COPYING for licence" categories = {"discovery", "safe"} -portrule = function(host, port) - if - port.number == 161 - and port.protocol == "udp" - -- if we only run against open or open|filtered ports anyway, leave next two lines commented - -- and ( port.state == "open" - -- or port.state == "open|filtered" ) - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.portnumber(161, "udp", {"open", "open|filtered"}) action = function(host, port) diff --git a/scripts/SSHv1-support.nse b/scripts/SSHv1-support.nse index 2b9b046d3..6d0edcaeb 100644 --- a/scripts/SSHv1-support.nse +++ b/scripts/SSHv1-support.nse @@ -4,17 +4,9 @@ author = "Brandon Enright " license = "See nmaps COPYING for licence" categories = {"intrusive"} -portrule = function(host, port) - if (port.number == 22 - or port.service == "ssh") - and port.protocol == "tcp" - and port.state == "open" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.port_or_service(22, "ssh") action = function(host, port) local socket = nmap.new_socket() diff --git a/scripts/SSLv2-support.nse b/scripts/SSLv2-support.nse index 9f666be2e..0f974e72e 100644 --- a/scripts/SSLv2-support.nse +++ b/scripts/SSLv2-support.nse @@ -5,20 +5,9 @@ license = "See nmaps COPYING for licence" categories = {"intrusive"} -portrule = function(host, port) - if ( port.number == 443 - or port.service == "ssl/http" - or port.service == "ssl" - or port.service == "https") - and port.protocol == "tcp" - and port.state == "open" - then - return true - else - return false - end +require "shortport" -end +portrule = shortport.port_or_service(443, {"ssl/http", "ssl", "https"}) hex2dec = function(hex) diff --git a/scripts/anonFTP.nse b/scripts/anonFTP.nse index 84aa8c836..316a5eb28 100644 --- a/scripts/anonFTP.nse +++ b/scripts/anonFTP.nse @@ -8,17 +8,9 @@ license = "See nmaps COPYING for licence" categories = {"intrusive"} -portrule = function(host, port) - if (port.number == 21 - or port.service == "ftp") - and port.protocol == "tcp" - and port.state == "open" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.port_or_service(21, "ftp") action = function(host, port) local socket = nmap.new_socket() diff --git a/scripts/chargenTest.nse b/scripts/chargenTest.nse index 74904deb4..059b7e6d4 100644 --- a/scripts/chargenTest.nse +++ b/scripts/chargenTest.nse @@ -8,16 +8,9 @@ license = "See nmaps COPYING for licence" categories = {"demo"} -portrule = function(host, port) - if port.number == 19 - and port.service == "chargen" - and port.protocol == "udp" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.port_or_service(19, "chargen", "udp") action = function(host, port) local socket = nmap.new_socket() diff --git a/scripts/daytimeTest.nse b/scripts/daytimeTest.nse index 9869336b5..f4b22f746 100644 --- a/scripts/daytimeTest.nse +++ b/scripts/daytimeTest.nse @@ -8,16 +8,9 @@ license = "See nmaps COPYING for licence" categories = {"demo"} -portrule = function(host, port) - if port.number == 13 - and port.service == "daytime" - and port.protocol == "udp" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.port_or_service(13, "daytime", "udp") action = function(host, port) local socket = nmap.new_socket() diff --git a/scripts/dns-test-open-recursion.nse b/scripts/dns-test-open-recursion.nse index 20f7176fa..19a7cc979 100644 --- a/scripts/dns-test-open-recursion.nse +++ b/scripts/dns-test-open-recursion.nse @@ -9,16 +9,9 @@ license = "See nmaps COPYING for licence" categories = {"intrusive"} require "bit" +require "shortport" -portrule = function(host, port) - if port.number == 53 - and port.protocol == "udp" - then - return true - else - return false - end -end +portrule = shortport.portnumber(53, "udp") action = function(host, port) diff --git a/scripts/echoTest.nse b/scripts/echoTest.nse index 7a4ca953b..636eeb9a8 100644 --- a/scripts/echoTest.nse +++ b/scripts/echoTest.nse @@ -9,16 +9,9 @@ license = "See nmaps COPYING for licence" categories = {"demo"} -portrule = function(host, port) - if port.number == 7 - and port.service == "echo" - and port.protocol == "udp" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.port_or_service(7, "echo", "udp") action = function(host, port) local echostr = "hello there" diff --git a/scripts/finger.nse b/scripts/finger.nse index 0e0833bc2..7838b2f10 100644 --- a/scripts/finger.nse +++ b/scripts/finger.nse @@ -8,17 +8,9 @@ license = "See nmaps COPYING for licence" categories = {"discovery"} -portrule = function(host, port) - if (port.number == 79 - or port.service == "finger") - and port.protocol == "tcp" - and port.state == "open" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.port_or_service(79, "finger") action = function(host, port) local socket = nmap.new_socket() diff --git a/scripts/ftpbounce.nse b/scripts/ftpbounce.nse index ea9e11f5d..5269450d1 100644 --- a/scripts/ftpbounce.nse +++ b/scripts/ftpbounce.nse @@ -5,16 +5,9 @@ license="See nmaps COPYING for licence" categories = {"intrusive"} -portrule = function(host, port) - if port.service == "ftp" - and port.protocol == "tcp" - and port.state == "open" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.service("ftp") line_iterate = function(s) local line diff --git a/scripts/iax2Detect.nse b/scripts/iax2Detect.nse index ef66d644b..a6b60f905 100644 --- a/scripts/iax2Detect.nse +++ b/scripts/iax2Detect.nse @@ -9,15 +9,9 @@ license = "See nmap's COPYING for license" categories = {"safe", "discovery"} -portrule = function(host, port) - if port.number == 4569 and - port.protocol == "udp" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.portnumber(4569, "udp") action = function(host, port) local soc = nmap.new_socket() diff --git a/scripts/ircServerInfo.nse b/scripts/ircServerInfo.nse index 55591a13d..b77cd8b5d 100644 --- a/scripts/ircServerInfo.nse +++ b/scripts/ircServerInfo.nse @@ -9,14 +9,9 @@ license = "See Nmap's COPYING" categories = {"discovery"} require("stdnse") +require "shortport" -portrule = function(host, port) - return (portnumber == 6667 or port.service == "irc") - and port.protocol == "tcp" - and port.state == "open" -end - - +portrule = shortport.port_or_service(6667, "irc") init = function() -- Start of MOTD, we'll take the server name from here diff --git a/scripts/ircZombieTest.nse b/scripts/ircZombieTest.nse index 4bfb79171..a6d6cb4b1 100644 --- a/scripts/ircZombieTest.nse +++ b/scripts/ircZombieTest.nse @@ -9,19 +9,9 @@ license = "See nmaps COPYING for licence" categories = {"malware"} -portrule = function(host, port) - if - ( port.number == 113 - or port.service == "auth") - and port.protocol == "tcp" - and port.state == "open" - then - return true - else - return false - end +require "shortport" -end +portrule = shortport.port_or_service(113, "auth") action = function(host, port) local status = 0 diff --git a/scripts/kibuvDetection.nse b/scripts/kibuvDetection.nse index 24af73b25..77cad93be 100644 --- a/scripts/kibuvDetection.nse +++ b/scripts/kibuvDetection.nse @@ -16,25 +16,9 @@ license = "See nmaps COPYING for licence" categories = {"malware"} -portrule = function(host, port) - local decision - if - ( port.number == 7955 - or - port.number == 14920 - or - port.number == 42260) - and port.service == "ftp" - and port.protocol == "tcp" - and port.state == "open" - then - decision = true - else - decision = false - end +require "shortport" - return decision -end +portrule = shortport.port_or_service({7955, 14920, 42260}, "ftp") action = function(host, port) local socket = nmap.new_socket() diff --git a/scripts/mswindowsShell.nse b/scripts/mswindowsShell.nse index 6ce76e46d..7f136b6f9 100644 --- a/scripts/mswindowsShell.nse +++ b/scripts/mswindowsShell.nse @@ -9,21 +9,9 @@ license = "See nmaps COPYING for licence" categories = {"backdoor"} -portrule = function(host, port) - local decision - if - ( port.number == 8888 - or port.service == "auth") - and port.protocol == "tcp" - and port.state == "open" - then - decision = true - else - decision = false - end +require "shortport" - return decision -end +portrule = shortport.port_or_service(8888, "auth") action = function(host, port) local status = 0 diff --git a/scripts/showHTTPVersion.nse b/scripts/showHTTPVersion.nse index e295d058e..db93fcf81 100644 --- a/scripts/showHTTPVersion.nse +++ b/scripts/showHTTPVersion.nse @@ -17,24 +17,9 @@ categories = {""} runlevel = 1.0 -portrule = function(host, port) +require "shortport" - - if - -- remove next line if you really want to run this script - false and - ( port.number == 80 - or port.service == "http" ) - and port.protocol == "tcp" - and port.state == "open" - -- and host.name ~= nil - -- and string.match(host.name, "www.+") - then - return true - else - return false - end -end +portrule = shortport.port_or_service(80, "http") action = function(host, port) diff --git a/scripts/showSMTPVersion.nse b/scripts/showSMTPVersion.nse index b356bbc65..cf450e42e 100644 --- a/scripts/showSMTPVersion.nse +++ b/scripts/showSMTPVersion.nse @@ -8,22 +8,9 @@ license = "See nmaps COPYING for licence" categories = {"demo"} -portrule = function(host, port) - local decision - - if - ( port.number == 25 - or port.service == "smtp") - and port.protocol == "tcp" - and port.state == "open" - then - decision = true - else - decision = false - end +require "shortport" - return decision -end +portrule = shortport.port_or_service(25, "smtp") action = function(host, port) diff --git a/scripts/showSSHVersion.nse b/scripts/showSSHVersion.nse index 16f4e2031..287e696cb 100644 --- a/scripts/showSSHVersion.nse +++ b/scripts/showSSHVersion.nse @@ -9,17 +9,9 @@ license = "See nmaps COPYING for licence" categories = {"demo"} -portrule = function(host, port) - if - port.service == "ssh" - and port.protocol == "tcp" - and port.state == "open" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.service("ssh") action = function(host, port) local result, socket diff --git a/scripts/xamppDefaultPass.nse b/scripts/xamppDefaultPass.nse index 34197a1d2..35bf42ca9 100644 --- a/scripts/xamppDefaultPass.nse +++ b/scripts/xamppDefaultPass.nse @@ -10,17 +10,9 @@ license = "See nmaps COPYING for licence" categories = {"vulnerability"} -portrule = function(host, port) - if port.number == 21 - and port.service == "ftp" - and port.protocol == "tcp" - and port.state == "open" - then - return true - else - return false - end -end +require "shortport" + +portrule = shortport.port_or_service(21, "ftp") login = function(socket, user, pass) res = ""