diff --git a/nselib/eigrp.lua b/nselib/eigrp.lua index 058b37f23..c71c6fc2f 100644 --- a/nselib/eigrp.lua +++ b/nselib/eigrp.lua @@ -5,6 +5,8 @@ -- Version 0.1 -- 19/07/2012 - First version. +local bin = require "bin" +local table = require "table" local stdnse = require "stdnse" local ipOps = require "ipOps" local packet = require "packet" diff --git a/scripts/broadcast-eigrp-discovery.nse b/scripts/broadcast-eigrp-discovery.nse index 16c769833..30130f375 100644 --- a/scripts/broadcast-eigrp-discovery.nse +++ b/scripts/broadcast-eigrp-discovery.nse @@ -7,6 +7,8 @@ local bin = require "bin" local packet = require "packet" local ipOps = require "ipOps" local target = require "target" +local coroutine = require "coroutine" +local string = require "string" description = [[ Network discovery and routing information gathering through Cisco's EIGRP. @@ -114,7 +116,7 @@ end local eigrpListener = function(interface, timeout, responses) local condvar = nmap.condvar(responses) local routers = {} - local status, l3data, response, p, eigrp_raw + local status, l3data, response, p, eigrp_raw, _ local start = nmap.clock_ms() -- Filter for EIGRP packets that are sent either to us or to multicast local filter = "ip proto 88 and (ip dst host " .. interface.address .. " or 224.0.0.10)" @@ -162,7 +164,7 @@ end --@param astab Table to put result into. local asListener = function(interface, timeout, astab) local condvar = nmap.condvar(astab) - local status, l3data, p, eigrp_raw, eigrp_hello + local status, l3data, p, eigrp_raw, eigrp_hello, _ local start = nmap.clock_ms() local filter = "ip proto 88 and ip dst host 224.0.0.10" local listener = nmap.new_socket() diff --git a/scripts/broadcast-igmp-discovery.nse b/scripts/broadcast-igmp-discovery.nse index 27796fc0f..cf8b3be07 100644 --- a/scripts/broadcast-igmp-discovery.nse +++ b/scripts/broadcast-igmp-discovery.nse @@ -5,6 +5,8 @@ local bin = require "bin" local packet = require "packet" local ipOps = require "ipOps" local target = require "target" +local coroutine = require "coroutine" +local string = require "string" description = [[ Discovers targets that have IGMP Multicast memberships and grabs interesting information. @@ -142,7 +144,7 @@ local igmpListener = function(interface, timeout, responses) local condvar = nmap.condvar(responses) local start = nmap.clock_ms() local listener = nmap.new_socket() - local p, igmp_raw, status, l3data, response + local p, igmp_raw, status, l3data, response, _ local devices = {} listener:set_timeout(100) listener:pcap_open(interface.device, 1024, true, 'ip proto 2') diff --git a/scripts/broadcast-pim-discovery.nse b/scripts/broadcast-pim-discovery.nse index 30e3c6910..f86006199 100644 --- a/scripts/broadcast-pim-discovery.nse +++ b/scripts/broadcast-pim-discovery.nse @@ -5,6 +5,8 @@ local bin = require "bin" local stdnse = require "stdnse" local target = require "target" local table = require "table" +local math = require "math" +local string = require "string" description = [[ Discovers routers that are running PIM (Protocol Independant Multicast). @@ -104,7 +106,7 @@ local helloListen = function(interface, timeout, responses) local condvar = nmap.condvar(responses) local start = nmap.clock_ms() local listener = nmap.new_socket() - local p, hello_raw, status, l3data + local p, hello_raw, status, l3data, _ -- PIM packets that are sent to 224.0.0.13 and not coming from our host local filter = 'ip proto 103 and dst host 224.0.0.13 and src host not ' .. interface.address diff --git a/scripts/http-title.nse b/scripts/http-title.nse index 3cc81df90..6a5854562 100644 --- a/scripts/http-title.nse +++ b/scripts/http-title.nse @@ -5,6 +5,7 @@ local nmap = require "nmap" local shortport = require "shortport" local stdnse = require "stdnse" local string = require "string" +local table = require "table" local url = require "url" description = [[ @@ -38,11 +39,9 @@ categories = {"default", "discovery", "safe"} portrule = shortport.http -action = function(host, port) - local resp, redirect_url, title - - resp = http.get( host, port, '/' ) - +local function getTitle(host, port, path) + local resp = http.get( host, port, path ) + local redirect_url -- check for a redirect if resp.location then redirect_url = resp.location[#resp.location] @@ -52,10 +51,14 @@ action = function(host, port) end -- try and match title tags - title = string.match(resp.body, "<[Tt][Ii][Tt][Ll][Ee][^>]*>([^<]*)") + local title + if ( resp.body ) then + title = string.match(resp.body, "<[Tt][Ii][Tt][Ll][Ee][^>]*>([^<]*)") + else + title = "No reponse received from server" + end local display_title = title - if display_title and display_title ~= "" then display_title = string.gsub(display_title , "[\n\r\t]", "") if #display_title > 65 then @@ -70,14 +73,25 @@ action = function(host, port) end end - local output_tab = stdnse.output_table() - output_tab.title = title - output_tab.redirect_url = redirect_url + return title, display_title, redirect_url +end - local output_str = display_title - if redirect_url then - output_str = output_str .. "\n" .. ("Requested resource was %s"):format( redirect_url ) +action = function(host, port) + local path = stdnse.get_script_args(SCRIPT_NAME .. ".path") or "/" + local str_res, xml_res = {}, stdnse.output_table() + + for _, p in ipairs(stdnse.strsplit(",", path)) do + local title, display_title, redirect_url = getTitle(host, port, p) + + local result_part = { ("%s: %s"):format(p, display_title) } + if redirect_url then + table.insert(result_part, { ("Requested resource was %s"):format( redirect_url ) }) + end + table.insert(str_res, result_part) + + xml_res.urls = xml_res.urls or {} + table.insert(xml_res.urls, { path = p, title = title, redirect_url = redirect_url }) end - return output_tab, output_str + return xml_res, stdnse.format_output(true, str_res) end diff --git a/scripts/llmnr-resolve.nse b/scripts/llmnr-resolve.nse index d125bbc27..3a45999eb 100644 --- a/scripts/llmnr-resolve.nse +++ b/scripts/llmnr-resolve.nse @@ -6,6 +6,8 @@ local bit = require "bit" local packet = require "packet" local ipOps = require "ipOps" local target = require "target" +local math = require "math" +local string = require "string" description = [[ Resolves a hostname by using the LLMNR (Link-Local Multicast Name Resolution) protocol. @@ -88,7 +90,7 @@ local llmnrListen = function(interface, timeout, result) local condvar = nmap.condvar(result) local start = nmap.clock_ms() local listener = nmap.new_socket() - local status, l3data + local status, l3data, _ -- packets that are sent to our UDP port number 5355 local filter = 'dst host ' .. interface.address .. ' and udp src port 5355' @@ -200,14 +202,15 @@ action = function() -- Check responses if #result > 0 then - for _, response in pairs(result) do - table.insert(output, response.hostname.. " : " .. response.address) - end - if target.ALLOW_NEW_TARGETS then - target.add(response.address) - else - table.insert(output,"Use the newtargets script-arg to add the results as targets") - end - return stdnse.format_output(true, output) + for _, response in pairs(result) do + table.insert(output, response.hostname.. " : " .. response.address) + if target.ALLOW_NEW_TARGETS then + target.add(response.address) + end + end + if ( not(target.ALLOW_NEW_TARGETS) ) then + table.insert(output,"Use the newtargets script-arg to add the results as targets") + end + return stdnse.format_output(true, output) end end diff --git a/scripts/mtrace.nse b/scripts/mtrace.nse index f4e8a126e..8e9c00567 100644 --- a/scripts/mtrace.nse +++ b/scripts/mtrace.nse @@ -4,6 +4,8 @@ local ipOps = require "ipOps" local bin = require "bin" local stdnse = require "stdnse" local table = require "table" +local math = require "math" +local string = require "string" description = [[ Queries for the multicast path from a source to a destination host. @@ -155,7 +157,7 @@ local traceSend = function(interface, destination, trace_raw) if destination == "224.0.0.2" then sock:ethernet_open(interface.device) -- Ethernet IPv4 multicast, our ethernet address and packet type IP - eth_hdr = bin.pack("HAH", "01 00 5e 00 00 02", interface.mac, "08 00") + local eth_hdr = bin.pack("HAH", "01 00 5e 00 00 02", interface.mac, "08 00") sock:ethernet_send(eth_hdr .. trace_packet.buf) sock:ethernet_close() else @@ -266,7 +268,7 @@ local traceListener = function(interface, timeout, responses) local condvar = nmap.condvar(responses) local start = nmap.clock_ms() local listener = nmap.new_socket() - local p, trace_raw, status, l3data, response + local p, trace_raw, status, l3data, response, _ -- IGMP packets that are sent to our host local filter = 'ip proto 2 and dst host ' .. interface.address diff --git a/scripts/smb-os-discovery.nse b/scripts/smb-os-discovery.nse index a75b7cab2..96629cd76 100644 --- a/scripts/smb-os-discovery.nse +++ b/scripts/smb-os-discovery.nse @@ -2,6 +2,8 @@ local smb = require "smb" local stdnse = require "stdnse" local string = require "string" local table = require "table" +local math = require "math" +local os = require "os" description = [[ Attempts to determine the operating system, computer name, domain, workgroup, and current diff --git a/scripts/ssl-known-key.nse b/scripts/ssl-known-key.nse index 77d9f1ecc..0f75fff03 100644 --- a/scripts/ssl-known-key.nse +++ b/scripts/ssl-known-key.nse @@ -3,6 +3,7 @@ local nmap = require "nmap" local shortport = require "shortport" local stdnse = require "stdnse" local sslcert = require "sslcert" +local bin = require "bin" -- -*- mode: lua -*- -- vim: set filetype=lua :