Index: scripts/http-userdir-enum.nse =================================================================== --- scripts/http-userdir-enum.nse (revision 29496) +++ scripts/http-userdir-enum.nse (working copy) @@ -3,7 +3,6 @@ local datafiles = require "datafiles" local http = require "http" local nmap = require "nmap" -local openssl = require "openssl" local os = require "os" local shortport = require "shortport" local stdnse = require "stdnse" @@ -158,7 +157,8 @@ function randomstring() local rnd, s, l, _ - if pcall(require, "openssl") then + local status, openssl = pcall(require, "openssl") + if status then rnd = openssl.rand_pseudo_bytes end s = rnd and rnd(8) or tostring( os.time() ) Index: scripts/http-virustotal.nse =================================================================== --- scripts/http-virustotal.nse (revision 29496) +++ scripts/http-virustotal.nse (working copy) @@ -1,8 +1,8 @@ local http = require "http" local io = require "io" local json = require "json" -local openssl = require "openssl" local stdnse = require "stdnse" +local openssl = stdnse.silent_require "openssl" local tab = require "tab" local table = require "table" Index: scripts/dns-nsec3-enum.nse =================================================================== --- scripts/dns-nsec3-enum.nse (revision 29496) +++ scripts/dns-nsec3-enum.nse (working copy) @@ -2,7 +2,6 @@ local shortport = require "shortport" local dns = require "dns" local base32 = require "base32" -local openssl = require "openssl" local msrpc = require "msrpc" -- just for random string generation local math = require "math" local bin = require "bin" @@ -10,6 +9,8 @@ local string = require "string" local table = require "table" +local openssl = stdnse.silent_require "openssl" + description = [[ Tries to enumerate domain names from the DNS server that supports DNSSEC NSEC3 records. Index: scripts/svn-brute.nse =================================================================== --- scripts/svn-brute.nse (revision 29496) +++ scripts/svn-brute.nse (working copy) @@ -1,9 +1,9 @@ local brute = require "brute" local creds = require "creds" local nmap = require "nmap" -local openssl = require "openssl" local shortport = require "shortport" local stdnse = require "stdnse" +local openssl = stdnse.silent_require "openssl" description = [[ Performs brute force password auditing against Subversion source code control servers. Index: scripts/smb-ls.nse =================================================================== --- scripts/smb-ls.nse (revision 29496) +++ scripts/smb-ls.nse (working copy) @@ -3,7 +3,7 @@ local stdnse = require 'stdnse' local tab = require 'tab' local table = require "table" -local openssl= require 'openssl' +local openssl= stdnse.silent_require 'openssl' description = [[ Attempts to retrieve useful information about files shared on SMB volumes. Index: nselib/mssql.lua =================================================================== --- nselib/mssql.lua (revision 29496) +++ nselib/mssql.lua (working copy) @@ -107,7 +107,6 @@ local math = require "math" local match = require "match" local nmap = require "nmap" -local openssl = require "openssl" local os = require "os" local shortport = require "shortport" local smb = require "smb" @@ -132,7 +131,7 @@ -- -- (Patrik Karlsson, Chris Woodbury) -HAVE_SSL = (nmap.have_ssl() and pcall(require, "openssl")) +local openssl, HAVE_SSL = pcall(require, "openssl") do namedpipes = smb.namedpipes Index: nselib/afp.lua =================================================================== --- nselib/afp.lua (revision 29496) +++ nselib/afp.lua (working copy) @@ -114,19 +114,14 @@ local bin = require "bin" local bit = require "bit" local nmap = require "nmap" -local openssl = require "openssl" local os = require "os" local stdnse = require "stdnse" local string = require "string" local table = require "table" _ENV = stdnse.module("afp", stdnse.seeall); -local HAVE_SSL = false +local HAVE_SSL, openssl = pcall(require,'openssl') -if pcall(require,'openssl') then - HAVE_SSL = true -end - -- Table of valid REQUESTs local REQUEST = { CloseSession = 0x01, Index: nselib/http.lua =================================================================== --- nselib/http.lua (revision 29496) +++ nselib/http.lua (working copy) @@ -105,7 +105,6 @@ local comm = require "comm" local coroutine = require "coroutine" local nmap = require "nmap" -local openssl = require "openssl" local os = require "os" local stdnse = require "stdnse" local string = require "string" @@ -114,7 +113,7 @@ _ENV = stdnse.module("http", stdnse.seeall) ---Use ssl if we have it -local have_ssl = (nmap.have_ssl() and pcall(require, "openssl")) +local have_ssl, openssl = pcall(require,'openssl') local USER_AGENT = stdnse.get_script_args('http.useragent') or "Mozilla/5.0 (compatible; Nmap Scripting Engine; http://nmap.org/book/nse.html)" local MAX_REDIRECT_COUNT = 5 Index: nselib/pop3.lua =================================================================== --- nselib/pop3.lua (revision 29496) +++ nselib/pop3.lua (working copy) @@ -6,20 +6,14 @@ local base64 = require "base64" local comm = require "comm" local nmap = require "nmap" -local openssl = require "openssl" local stdnse = require "stdnse" local string = require "string" local table = require "table" _ENV = stdnse.module("pop3", stdnse.seeall) -local HAVE_SSL = false +local HAVE_SSL, openssl = pcall(require,'openssl') -if pcall(require,'openssl') then - HAVE_SSL = true -end - - err = { none = 0, userError = 1, Index: nselib/iscsi.lua =================================================================== --- nselib/iscsi.lua (revision 29496) +++ nselib/iscsi.lua (working copy) @@ -40,8 +40,8 @@ local bit = require "bit" local ipOps = require "ipOps" local nmap = require "nmap" -local openssl = require "openssl" local stdnse = require "stdnse" +local openssl = stdnse.silent_require "openssl" local string = require "string" local table = require "table" _ENV = stdnse.module("iscsi", stdnse.seeall) Index: nselib/ssh1.lua =================================================================== --- nselib/ssh1.lua (revision 29496) +++ nselib/ssh1.lua (working copy) @@ -10,8 +10,8 @@ local bit = require "bit" local math = require "math" local nmap = require "nmap" -local openssl = require "openssl" local stdnse = require "stdnse" +local openssl = stdnse.silent_require "openssl" _ENV = stdnse.module("ssh1", stdnse.seeall) --- Retrieve the size of the packet that is being received Index: nselib/sasl.lua =================================================================== --- nselib/sasl.lua (revision 29496) +++ nselib/sasl.lua (working copy) @@ -43,206 +43,201 @@ local bin = require "bin" local bit = require "bit" -local openssl = require "openssl" local smbauth = require "smbauth" local stdnse = require "stdnse" local string = require "string" _ENV = stdnse.module("sasl", stdnse.seeall) -local HAVE_SSL = false - +local HAVE_SSL, openssl = pcall(require, 'openssl') +if ( not(HAVE_SSL) ) then + stdnse.print_debug(1, + "sasl.lua: OpenSSL not present, SASL support limited.") +end local MECHANISMS = { } --- Calculates a DIGEST MD5 response -DigestMD5 = { - - --- Instantiates DigestMD5 - -- - -- @param chall string containing the base64 decoded challenge - -- @return a new instance of DigestMD5 - new = function(self, chall, username, password, method, uri, service, realm) - local o = { nc = 0, - chall = chall, - challnvs = {}, - username = username, - password = password, - method = method, - uri = uri, - service = service, - realm = realm } - setmetatable(o, self) - self.__index = self - o:parseChallenge() - return o - end, - - -- parses a challenge received from the server - -- takes care of both quoted and unqoted identifiers - -- regardless of what RFC says - parseChallenge = function(self) - local results = {} - local start, stop = 0,0 - while(true) do - local name, value - start, stop, name = self.chall:find("([^=]*)=%s*", stop + 1) - if ( not(start) ) then break end - if ( self.chall:sub(stop + 1, stop + 1) == "\"" ) then - start, stop, value = self.chall:find("(.-)\"", stop + 2) - else - start, stop, value = self.chall:find("([^,]*)", stop + 1) +if HAVE_SSL then + -- Calculates a DIGEST MD5 response + DigestMD5 = { + + --- Instantiates DigestMD5 + -- + -- @param chall string containing the base64 decoded challenge + -- @return a new instance of DigestMD5 + new = function(self, chall, username, password, method, uri, service, realm) + local o = { nc = 0, + chall = chall, + challnvs = {}, + username = username, + password = password, + method = method, + uri = uri, + service = service, + realm = realm } + setmetatable(o, self) + self.__index = self + o:parseChallenge() + return o + end, + + -- parses a challenge received from the server + -- takes care of both quoted and unqoted identifiers + -- regardless of what RFC says + parseChallenge = function(self) + local results = {} + local start, stop = 0,0 + while(true) do + local name, value + start, stop, name = self.chall:find("([^=]*)=%s*", stop + 1) + if ( not(start) ) then break end + if ( self.chall:sub(stop + 1, stop + 1) == "\"" ) then + start, stop, value = self.chall:find("(.-)\"", stop + 2) + else + start, stop, value = self.chall:find("([^,]*)", stop + 1) + end + self.challnvs[name:lower()] = value + start, stop = self.chall:find("%s*,%s*", stop + 1) + if ( not(start) ) then break end end - self.challnvs[name:lower()] = value - start, stop = self.chall:find("%s*,%s*", stop + 1) - if ( not(start) ) then break end - end - end, - - --- Calculates the digest - calcDigest = function( self ) - local uri = self.uri or ("%s/%s"):format(self.service, "localhost") - local realm = self.realm or self.challnvs.realm or "" - local cnonce = stdnse.tohex(openssl.rand_bytes( 8 )) - local qop = "auth" - self.nc = self.nc + 1 - local A1_part1 = openssl.md5(self.username .. ":" .. (self.challnvs.realm or "") .. ":" .. self.password) - local A1 = stdnse.tohex(openssl.md5(A1_part1 .. ":" .. self.challnvs.nonce .. ':' .. cnonce)) - local A2 = stdnse.tohex(openssl.md5(("%s:%s"):format(self.method, uri))) - local digest = stdnse.tohex(openssl.md5(A1 .. ":" .. self.challnvs.nonce .. ":" .. - ("%08d"):format(self.nc) .. ":" .. cnonce .. ":" .. - qop .. ":" .. A2)) - - local response = "username=\"" .. self.username .. "\"" - response = response .. (",%s=\"%s\""):format("realm", realm) - response = response .. (",%s=\"%s\""):format("nonce", self.challnvs.nonce) - response = response .. (",%s=\"%s\""):format("cnonce", cnonce) - response = response .. (",%s=%08d"):format("nc", self.nc) - response = response .. (",%s=%s"):format("qop", "auth") - response = response .. (",%s=\"%s\""):format("digest-uri", uri) - response = response .. (",%s=%s"):format("response", digest) - response = response .. (",%s=%s"):format("charset", "utf-8") - - return response - end, - - -} + end, --- The NTLM class handling NTLM challenge response authentication -NTLM = { - - --- Creates a new instance of the NTLM class - -- - -- @param chall string containing the challenge received from the server - -- @param username string containing the username - -- @param password string containing the password - -- @return new instance of NTML - new = function(self, chall, username, password) - local o = { nc = 0, - chall = chall, - username = username, - password = password} - setmetatable(o, self) - self.__index = self - o:parseChallenge() - return o - end, - - --- Converst str to "unicode" (adds null bytes for every other byte) - -- @param str containing string to convert - -- @return unicode string containing the unicoded str - to_unicode = function(str) - local unicode = "" - for i = 1, #str, 1 do - unicode = unicode .. bin.pack("CRAM-MD5 mechanism. -- -- @param username string. Index: nselib/smbauth.lua =================================================================== --- nselib/smbauth.lua (revision 29496) +++ nselib/smbauth.lua (working copy) @@ -82,13 +82,12 @@ local bin = require "bin" local nmap = require "nmap" -local openssl = require "openssl" local stdnse = require "stdnse" local string = require "string" local table = require "table" _ENV = stdnse.module("smbauth", stdnse.seeall) -have_ssl = (nmap.have_ssl() and pcall(require, "openssl")) +local openssl, have_ssl = pcall(require, "openssl") -- Constants local NTLMSSP_NEGOTIATE = 0x00000001 Index: nselib/mysql.lua =================================================================== --- nselib/mysql.lua (revision 29496) +++ nselib/mysql.lua (working copy) @@ -10,7 +10,6 @@ local bin = require "bin" local bit = require "bit" local nmap = require "nmap" -local openssl = require "openssl" local stdnse = require "stdnse" local string = require "string" local table = require "table" @@ -26,12 +25,8 @@ local tab = require('tab') -local HAVE_SSL = false +local HAVE_SSL, openssl = pcall(require,'openssl') -if pcall(require,'openssl') then - HAVE_SSL = true -end - Capabilities = { LongPassword = 0x1, Index: nselib/vnc.lua =================================================================== --- nselib/vnc.lua (revision 29496) +++ nselib/vnc.lua (working copy) @@ -31,18 +31,13 @@ local bin = require "bin" local nmap = require "nmap" -local openssl = require "openssl" local stdnse = require "stdnse" local string = require "string" local table = require "table" _ENV = stdnse.module("vnc", stdnse.seeall) -local HAVE_SSL = false +local HAVE_SSL, openssl = pcall(require,'openssl') -if pcall(require,'openssl') then - HAVE_SSL = true -end - VNC = { -- We currently support version 3.8 of the protocol only Index: nselib/bitcoin.lua =================================================================== --- nselib/bitcoin.lua (revision 29496) +++ nselib/bitcoin.lua (working copy) @@ -35,11 +35,10 @@ local bin = require "bin" local ipOps = require "ipOps" local nmap = require "nmap" -local openssl = require "openssl" local os = require "os" local stdnse = require "stdnse" local table = require "table" -stdnse.silent_require('openssl') +local openssl = stdnse.silent_require('openssl') _ENV = stdnse.module("bitcoin", stdnse.seeall) -- A class that supports the BitCoin network address structure Index: nselib/wsdd.lua =================================================================== --- nselib/wsdd.lua (revision 29496) +++ nselib/wsdd.lua (working copy) @@ -34,18 +34,13 @@ local bin = require "bin" local nmap = require "nmap" -local openssl = require "openssl" local stdnse = require "stdnse" local table = require "table" local target = require "target" _ENV = stdnse.module("wsdd", stdnse.seeall) -local HAVE_SSL = false +local HAVE_SSL, openssl = pcall(require,'openssl') -if pcall(require,'openssl') then - HAVE_SSL = true -end - -- The different probes local probes = { Index: nselib/iax2.lua =================================================================== --- nselib/iax2.lua (revision 29496) +++ nselib/iax2.lua (working copy) @@ -9,9 +9,9 @@ local bit = require "bit" local math = require "math" local nmap = require "nmap" -local openssl = require "openssl" local os = require "os" local stdnse = require "stdnse" +local openssl = stdnse.silent_require "openssl" local table = require "table" _ENV = stdnse.module("iax2", stdnse.seeall) Index: nselib/pgsql.lua =================================================================== --- nselib/pgsql.lua (revision 29496) +++ nselib/pgsql.lua (working copy) @@ -14,8 +14,8 @@ local bin = require "bin" local nmap = require "nmap" -local openssl = require "openssl" local stdnse = require "stdnse" +local openssl = stdnse.silent_require "openssl" local string = require "string" local table = require "table" _ENV = stdnse.module("pgsql", stdnse.seeall) Index: nselib/sip.lua =================================================================== --- nselib/sip.lua (revision 29496) +++ nselib/sip.lua (working copy) @@ -44,9 +44,9 @@ local bin = require "bin" local math = require "math" local nmap = require "nmap" -local openssl = require "openssl" local os = require "os" local stdnse = require "stdnse" +local openssl = stdnse.silent_require "openssl" local string = require "string" local table = require "table" _ENV = stdnse.module("sip", stdnse.seeall) Index: nse_main.lua =================================================================== --- nse_main.lua (revision 29496) +++ nse_main.lua (working copy) @@ -1114,13 +1114,15 @@ sort(scripts); for i, script in ipairs(scripts) do script = Script.new(script); - sort(script.categories); - db:write('Entry { filename = "', script.basename, '", '); - db:write('categories = {'); - for j, category in ipairs(script.categories) do - db:write(' "', lower(category), '",'); + if ( script ) then + sort(script.categories); + db:write('Entry { filename = "', script.basename, '", '); + db:write('categories = {'); + for j, category in ipairs(script.categories) do + db:write(' "', lower(category), '",'); + end + db:write(' } }\n'); end - db:write(' } }\n'); end db:close(); log_write("stdout", "Script Database updated successfully.");