1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-16 04:39:03 +00:00

Allow targets-sniffer.nse to sniff IPv6 addresses.

Patch by Daniel Miller.
This commit is contained in:
david
2012-04-17 21:47:30 +00:00
parent 9a9cf1fa7d
commit 870aed3393
2 changed files with 30 additions and 7 deletions

View File

@@ -1,5 +1,8 @@
# Nmap Changelog ($Id$); -*-text-*- # Nmap Changelog ($Id$); -*-text-*-
o [NSE] targets-sniffer now is capable of sniffing IPv6 addresses.
[Daniel Miller]
o [NSE] Added the script traceroute-geolocation that queries geographic o [NSE] Added the script traceroute-geolocation that queries geographic
locations of each traceroute hop and allows to export the results to KLM, locations of each traceroute hop and allows to export the results to KLM,
allowing the hops to be plotted on a map. [Patrik Karlsson] allowing the hops to be plotted on a map. [Patrik Karlsson]

View File

@@ -41,13 +41,17 @@ require("bin")
local interface_info local interface_info
local all_addresses= {} local all_addresses= {}
local unique_addresses = {} local unique_addresses = {}
local INVALID_ADDRESS = "????"
--Make sure the IP is not a broadcast or the local address --Make sure the IP is not a broadcast or the local address
local function check_if_valid(address) local function check_if_valid(address)
local broadcast = interface_info.broadcast local broadcast = interface_info.broadcast
local local_address = interface_info.address local local_address = interface_info.address
if address == local_address or address == broadcast or address == "255.255.255.255" then if address == local_address
or address == broadcast or address == "255.255.255.255"
or address:match('^ff') --IPv6 Multicast addrs
or address == INVALID_ADDRESS then
return false return false
else else
return true end return true end
@@ -55,7 +59,13 @@ end
local function get_ip_addresses(layer3) local function get_ip_addresses(layer3)
local ip = packet.Packet:new(layer3, layer3:len()) local ip = packet.Packet:new(layer3, layer3:len())
return packet.toip(ip.ip_bin_src),packet.toip(ip.ip_bin_dst) if ip.ip_v == 4 then
return packet.toip(ip.ip_bin_src),packet.toip(ip.ip_bin_dst)
elseif ip.ip_v == 6 then
return packet.toipv6(ip.ip_bin_src),packet.toipv6(ip.ip_bin_dst)
else
return INVALID_ADDRESS,INVALID_ADDRESS
end
end end
prerule = function() prerule = function()
@@ -86,7 +96,7 @@ action = function()
stdnse.print_debug(1,"Error - unable to open socket using interface %s",interface) stdnse.print_debug(1,"Error - unable to open socket using interface %s",interface)
return return
else else
sock:pcap_open(interface, 104, true, "ip") sock:pcap_open(interface, 104, true, "ip or ip6")
stdnse.print_debug(1, "Will sniff for %s seconds on interface %s.", (timeout/1000),interface) stdnse.print_debug(1, "Will sniff for %s seconds on interface %s.", (timeout/1000),interface)
repeat repeat
@@ -126,11 +136,21 @@ action = function()
end end
if target.ALLOW_NEW_TARGETS == true then if target.ALLOW_NEW_TARGETS == true then
for _,v in pairs(all_addresses) do if nmap.address_family() == 'inet6' then
target.add(v) for _,v in pairs(all_addresses) do
end if v:match(':') then
target.add(v)
end
end
else else
stdnse.print_debug(1,"Not adding targets to newtargets. If you want to do that use the 'newtargets' script argument.") for _,v in pairs(all_addresses) do
if not v:match(':') then
target.add(v)
end
end
end
else
stdnse.print_debug(1,"Not adding targets to newtargets. If you want to do that use the 'newtargets' script argument.")
end end
if #all_addresses>0 then if #all_addresses>0 then