Consistent naming of the address fields between IPv4 and IPv6.

All IP packet objects now have the following attributes:

  - ip_bin_src (binary src address)
  - ip_bin_dst (binary dst address)
  - ip_src (decimal-dotted string src address)
  - ip_dst (decimal-dotted string dst address)

The ip6_src and ip6_dst attributes have therefore been renamed (ip_bin_src and
ip_bin_dst).

This patch also updates the scripts accordingly.
This commit is contained in:
henri 2012-01-21 14:46:00 +00:00
parent 38c8615258
commit 1f431b953f
6 changed files with 44 additions and 40 deletions

View file

@ -189,10 +189,10 @@ local tcp_funcs_v4 = {
if port and scanner.ports.tcp[port] then
stdnse.print_debug("Marking port %d/tcp v4 as forwarded (reply from %s)", ip2.tcp_dport, toip(ip.ip_bin_src))
stdnse.print_debug("Marking port %d/tcp v4 as forwarded (reply from %s)", ip2.tcp_dport, ip.ip_src)
-- mark the gateway as forwarding the packet
scanner.ports.tcp[port].final_ttl = gateway_ttl(scanner.target.traceroute, toip(ip.ip_bin_src))
scanner.ports.tcp[port].final_ttl = gateway_ttl(scanner.target.traceroute, ip.ip_src)
scanner.ports.tcp[port].scanned = true
-- remove the related probe
@ -256,7 +256,7 @@ local udp_funcs_v4 = {
stdnse.print_debug("Marking port %d/udp v4 as forwarded", ip2.udp_dport)
-- mark the gateway as forwarding the packet
scanner.ports.udp[port].final_ttl = gateway_ttl(scanner.target.traceroute, toip(ip.ip_bin_src))
scanner.ports.udp[port].final_ttl = gateway_ttl(scanner.target.traceroute, ip.ip_src)
scanner.ports.udp[port].scanned = true
for i, probe in ipairs(scanner.active_probes) do
@ -316,10 +316,10 @@ local tcp_funcs_v6 = {
if port and scanner.ports.tcp[port] then
stdnse.print_debug("Marking port %d/tcp v6 as forwarded (reply from %s)", ip2.tcp_dport, toip(ip.ip6_src))
stdnse.print_debug("Marking port %d/tcp v6 as forwarded (reply from %s)", ip2.tcp_dport, ip.ip_src)
-- mark the gateway as forwarding the packet
scanner.ports.tcp[port].final_ttl = gateway_ttl(scanner.target.traceroute, toip(ip.ip6_src))
scanner.ports.tcp[port].final_ttl = gateway_ttl(scanner.target.traceroute, ip.ip_src)
scanner.ports.tcp[port].scanned = true
-- remove the related probe
@ -378,10 +378,10 @@ local udp_funcs_v6 = {
if port and scanner.ports.udp[port] then
stdnse.print_debug("Marking port %d/udp v6 as forwarded (reply from %s)", ip2.udp_dport, toip(ip2.ip6_src))
stdnse.print_debug("Marking port %d/udp v6 as forwarded (reply from %s)", ip2.udp_dport, ip2.ip_src)
-- mark the gateway as forwarding the packet
scanner.ports.udp[port].final_ttl = gateway_ttl(scanner.target.traceroute, toip(ip.ip6_src))
scanner.ports.udp[port].final_ttl = gateway_ttl(scanner.target.traceroute, ip.ip_src)
scanner.ports.udp[port].scanned = true
for i, probe in ipairs(scanner.active_probes) do
@ -440,7 +440,7 @@ local Firewalk_v4 = {
--- IPv4 initialization function. Open injection and reception sockets.
-- @param scanner the scanner handle
init = function(scanner)
local saddr = toip(scanner.target.bin_ip_src)
local saddr = packet.toip(scanner.target.bin_ip_src)
scanner.sock = nmap.new_dnet()
scanner.pcap = nmap.new_socket()
@ -506,7 +506,7 @@ local Firewalk_v6 = {
--- IPv6 initialization function. Open injection and reception sockets.
-- @param scanner the scanner handle
init = function(scanner)
local saddr = toip(scanner.target.bin_ip_src)
local saddr = packet.toipv6(scanner.target.bin_ip_src)
scanner.sock = nmap.new_dnet()
scanner.pcap = nmap.new_socket()
@ -531,7 +531,7 @@ local Firewalk_v6 = {
-- @return whether the packet seems to be a valid reply or not
check = function(src, layer3)
local ip = packet.Packet:new(layer3)
return ip.ip6_dst == src
return ip.ip_bin_dst == src
and ip.ip_p == packet.IPPROTO_ICMPV6
and ip.icmpv6_type == ICMP_TIME_EXCEEDEDv6
end,
@ -550,8 +550,8 @@ local Firewalk_v6 = {
local ip2 = packet.Packet:new(is)
-- check ICMP payload
if ip2.ip6_src == scanner.target.bin_ip_src and
ip2.ip6_dst == scanner.target.bin_ip then
if ip2.ip_bin_src == scanner.target.bin_ip_src and
ip2.ip_bin_dst == scanner.target.bin_ip then
-- layer 4 checks
local proto_func = proto_vtable[proto2str(ip2.ip_p)]

View file

@ -248,7 +248,7 @@ local function handle_received_packet(buf)
if not STRINGIFY[qtype] then
-- This is a not a qtype we sent or know about.
stdnse.print_debug(1, "Got NI reply with unknown qtype %d from %s", qtype, packet.toipv6(p.ip6_src))
stdnse.print_debug(1, "Got NI reply with unknown qtype %d from %s", qtype, p.ip6_src)
return
end

View file

@ -94,8 +94,8 @@ local function single_interface_broadcast(if_nfo, results)
local probe = packet.Frame:new()
probe.mac_src = src_mac
probe.mac_dst = dst_mac
probe.ip6_src = src_ip6
probe.ip6_dst = dst_ip6
probe.ip_bin_src = src_ip6
probe.ip_bin_dst = dst_ip6
probe.echo_id = 5
probe.echo_seq = 6
probe.echo_data = "Nmap host discovery."
@ -120,7 +120,7 @@ local function single_interface_broadcast(if_nfo, results)
else
local reply = packet.Frame:new(layer2..layer3)
if reply.mac_dst == src_mac then
local target_str = packet.toipv6(reply.ip6_src)
local target_str = reply.ip_src
if not results[target_str] then
if target.ALLOW_NEW_TARGETS then
target.add(target_str)

View file

@ -112,8 +112,8 @@ local function single_interface_broadcast(if_nfo, results)
local probe = packet.Frame:new()
probe.mac_src = src_mac
probe.mac_dst = dst_mac
probe.ip6_src = src_ip6
probe.ip6_dst = dst_ip6
probe.ip_bin_src = src_ip6
probe.ip_bin_dst = dst_ip6
-- In addition to setting an invalid option in
-- build_invalid_extension_header, we set an unknown ICMPv6 type of
@ -152,7 +152,7 @@ local function single_interface_broadcast(if_nfo, results)
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)
local target_str = reply.ip_src
if not results[target_str] then
if target.ALLOW_NEW_TARGETS then
target.add(target_str)

View file

@ -161,8 +161,8 @@ local function single_interface_broadcast(if_nfo, results)
local probe = packet.Frame:new()
probe.ip6_src = packet.mac_to_lladdr(src_mac)
probe.ip6_dst = dst_ip6
probe.ip_bin_src = packet.mac_to_lladdr(src_mac)
probe.ip_bin_dst = dst_ip6
probe.mac_src = src_mac
probe.mac_dst = packet.mactobin("33:33:00:00:00:01")
@ -192,8 +192,8 @@ local function single_interface_broadcast(if_nfo, results)
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
if reply.ip_bin_src == expected_ip6_src and
string.sub(expected_ip6_dst_prefix,1,12) == string.sub(reply.ip_bin_dst,1,12) then
local ula_target_addr_str = packet.toipv6(reply.ns_target)
local identifier = get_identifier(reply.ns_target)
--Filter out the reduplicative identifiers.