diff --git a/scripts/targets-ipv6-multicast-echo.nse b/scripts/targets-ipv6-multicast-echo.nse index 081fdbf8c..08ddf519c 100644 --- a/scripts/targets-ipv6-multicast-echo.nse +++ b/scripts/targets-ipv6-multicast-echo.nse @@ -17,6 +17,7 @@ license = "Same as Nmap--See http://nmap.org/book/man-legal.html" categories = {"discovery","broadcast"} require 'nmap' +require 'tab' require 'target' require 'packet' local bit = require 'bit' @@ -56,6 +57,17 @@ local function get_interfaces() return interfaces end +local function format_mac(mac) + local octets + + octets = {} + for _, v in ipairs({ string.byte(mac, 1, #mac) }) do + octets[#octets + 1] = string.format("%02x", v) + end + + return stdnse.strjoin(":", octets) +end + local function single_interface_broadcast(if_nfo, results) stdnse.print_debug("Starting " .. SCRIPT_NAME .. " on " .. if_nfo.device) @@ -106,7 +118,7 @@ local function single_interface_broadcast(if_nfo, results) local target_str = packet.toipv6(reply.ip6_src) if not results[target_str] then target.add(target_str) - results[#results + 1] = target_str + results[#results + 1] = { address = target_str, mac = format_mac(reply.mac_src), iface = if_nfo.device } results[target_str] = true end end @@ -119,6 +131,21 @@ local function single_interface_broadcast(if_nfo, results) condvar("signal") end +local function format_output(results) + local output = tab.new() + + for _, record in ipairs(results) do + tab.addrow(output, "IP: " .. record.address, "MAC: " .. record.mac, "IFACE: " .. record.iface) + end + if #results > 0 then + output = { tab.dump(output) } + if not target.ALLOW_NEW_TARGETS then + output[#output + 1] = "Use --script-args=newtargets to add the results as targets" + end + return stdnse.format_output(true, output) + end +end + action = function() local threads = {} local results = {} @@ -137,7 +164,5 @@ action = function() end until next(threads) == nil - if #results > 0 then - return stdnse.format_output(true, results) - end + return format_output(results) end diff --git a/scripts/targets-ipv6-multicast-invalid-dst.nse b/scripts/targets-ipv6-multicast-invalid-dst.nse index 8f4d03cc4..db987941a 100644 --- a/scripts/targets-ipv6-multicast-invalid-dst.nse +++ b/scripts/targets-ipv6-multicast-invalid-dst.nse @@ -19,6 +19,7 @@ license = "Same as Nmap--See http://nmap.org/book/man-legal.html" categories = {"discovery","broadcast"} require 'nmap' +require 'tab' require 'target' require 'packet' local bit = require 'bit' @@ -74,6 +75,17 @@ local function get_interfaces() return interfaces end +local function format_mac(mac) + local octets + + octets = {} + for _, v in ipairs({ string.byte(mac, 1, #mac) }) do + octets[#octets + 1] = string.format("%02x", v) + end + + return stdnse.strjoin(":", octets) +end + local function single_interface_broadcast(if_nfo, results) stdnse.print_debug("Starting " .. SCRIPT_NAME .. " on " .. if_nfo.device) @@ -132,13 +144,13 @@ local function single_interface_broadcast(if_nfo, results) if not status then pcap_timeout_count = pcap_timeout_count + 1 else - local reply = packet.Frame:new(layer2) - if reply.mac_dst == src_mac then - reply = packet.Packet:new(layer3) + local l2reply = packet.Frame:new(layer2) + if l2reply.mac_dst == src_mac then + local reply = packet.Packet:new(layer3) local target_str = packet.toipv6(reply.ip6_src) if not results[target_str] then target.add(target_str) - results[#results + 1] = target_str + results[#results + 1] = { address = target_str, mac = format_mac(l2reply.mac_src), iface = if_nfo.device } results[target_str] = true end end @@ -151,6 +163,21 @@ local function single_interface_broadcast(if_nfo, results) condvar("signal") end +local function format_output(results) + local output = tab.new() + + for _, record in ipairs(results) do + tab.addrow(output, "IP: " .. record.address, "MAC: " .. record.mac, "IFACE: " .. record.iface) + end + if #results > 0 then + output = { tab.dump(output) } + if not target.ALLOW_NEW_TARGETS then + output[#output + 1] = "Use --script-args=newtargets to add the results as targets" + end + return stdnse.format_output(true, output) + end +end + action = function() local threads = {} local results = {} @@ -169,7 +196,5 @@ action = function() end until next(threads) == nil - if #results > 0 then - return stdnse.format_output(true, results) - end + return format_output(results) end diff --git a/scripts/targets-ipv6-multicast-slaac.nse b/scripts/targets-ipv6-multicast-slaac.nse index 02eed6593..1ce14fa8c 100644 --- a/scripts/targets-ipv6-multicast-slaac.nse +++ b/scripts/targets-ipv6-multicast-slaac.nse @@ -31,6 +31,7 @@ categories = {"discovery","broadcast"} require 'ipOps' require 'nmap' +require 'tab' require 'target' require 'packet' require "os" @@ -115,6 +116,17 @@ local function get_interfaces() return interfaces end +local function format_mac(mac) + local octets + + octets = {} + for _, v in ipairs({ string.byte(mac, 1, #mac) }) do + octets[#octets + 1] = string.format("%02x", v) + end + + return stdnse.strjoin(":", octets) +end + local function single_interface_broadcast(if_nfo, results) stdnse.print_debug("Starting " .. SCRIPT_NAME .. " on " .. if_nfo.device) @@ -172,9 +184,9 @@ local function single_interface_broadcast(if_nfo, results) if not status then pcap_timeout_count = pcap_timeout_count + 1 else - local reply = packet.Frame:new(layer2) - if string.sub(reply.mac_dst, 1, 3) == string.sub(expected_mac_dst_prefix, 1, 3) then - reply = packet.Packet:new(layer3) + local l2reply = packet.Frame:new(layer2) + if string.sub(l2reply.mac_dst, 1, 3) == string.sub(expected_mac_dst_prefix, 1, 3) then + local reply = packet.Packet:new(layer3) if reply.ip6_src == expected_ip6_src and string.sub(expected_ip6_dst_prefix,1,12) == string.sub(reply.ip6_dst,1,12) then local ula_target_addr_str = packet.toipv6(reply.ns_target) @@ -184,7 +196,7 @@ local function single_interface_broadcast(if_nfo, results) local actual_addr_str = packet.toipv6(actual_prefix .. identifier) if not results[actual_addr_str] then target.add(actual_addr_str) - results[#results + 1] = actual_addr_str + results[#results + 1] = { address = actual_addr_str, mac = format_mac(l2reply.mac_src), iface = if_nfo.device } results[actual_addr_str] = true end end @@ -198,6 +210,21 @@ local function single_interface_broadcast(if_nfo, results) condvar("signal") end +local function format_output(results) + local output = tab.new() + + for _, record in ipairs(results) do + tab.addrow(output, "IP: " .. record.address, "MAC: " .. record.mac, "IFACE: " .. record.iface) + end + if #results > 0 then + output = { tab.dump(output) } + if not target.ALLOW_NEW_TARGETS then + output[#output + 1] = "Use --script-args=newtargets to add the results as targets" + end + return stdnse.format_output(true, output) + end +end + action = function() local threads = {} local results = {} @@ -218,7 +245,5 @@ action = function() end until next(threads) == nil - if #results > 0 then - return stdnse.format_output(true, results) - end + return format_output(results) end