diff --git a/nselib/packet.lua b/nselib/packet.lua index aad588fa5..2d6e574cc 100644 --- a/nselib/packet.lua +++ b/nselib/packet.lua @@ -289,8 +289,8 @@ end function Packet:build_ipv6_packet(src, dst, nx_hdr, payload, h_limit, t_class, f_label) self.ether_type = ETHER_TYPE_IPV6 self.ip_v = 6 - self.ip6_src = src or self.ip6_src - self.ip6_dst = dst or self.ip6_dst + self.ip_bin_src = src or self.ip_bin_src + self.ip_bin_dst = dst or self.ip_bin_dst self.ip6_nhdr = nx_hdr or self.ip6_nhdr self.l4_packet = payload or self.l4_packet self.ip6_tc = t_class or self.ip6_tc or 1 @@ -302,8 +302,8 @@ function Packet:build_ipv6_packet(src, dst, nx_hdr, payload, h_limit, t_class, f numtostr16(self.ip6_plen) .. --payload length string.char(self.ip6_nhdr) .. --next header string.char(self.ip6_hlimit) .. --hop limit - self.ip6_src .. --Source - self.ip6_dst ..--dest + self.ip_bin_src .. --Source + self.ip_bin_dst ..--dest (self.exheader or "").. (self.l4_packet or "") end @@ -322,7 +322,7 @@ end --- Count IPv6 checksum. -- @return the checksum. function Packet:count_ipv6_pseudoheader_cksum() - local pseudoheader = self.ip6_src .. self.ip6_dst .. numtostr16(#self.l4_packet) .. string.char(0x0,0x0,0x0) .. string.char(self.ip6_nhdr) + local pseudoheader = self.ip_bin_src .. self.ip_bin_dst .. numtostr16(#self.l4_packet) .. string.char(0x0,0x0,0x0) .. string.char(self.ip6_nhdr) local ck_content = pseudoheader .. self.l4_packet return in_cksum(ck_content) end @@ -334,15 +334,15 @@ end -- @param icmpv6_type integer that represent ICMPv6 type. -- @param icmpv6_code integer that represent ICMPv6 code. -- @param icmpv6_payload string of the payload --- @param ip6_src 16-byte string of the source IPv6 address. --- @param ip6_dst 16-byte string of the destination IPv6 address. -function Packet:build_icmpv6_header(icmpv6_type, icmpv6_code, icmpv6_payload, ip6_src, ip6_dst) +-- @param ip_bin_src 16-byte string of the source IPv6 address. +-- @param ip_bin_dst 16-byte string of the destination IPv6 address. +function Packet:build_icmpv6_header(icmpv6_type, icmpv6_code, icmpv6_payload, ip_bin_src, ip_bin_dst) self.ip6_nhdr = IPPROTO_ICMPV6 self.icmpv6_type = icmpv6_type or self.icmpv6_type self.icmpv6_code = icmpv6_code or self.icmpv6_code self.icmpv6_payload = icmpv6_payload or self.icmpv6_payload - self.ip6_src = ip6_src or self.ip6_src - self.ip6_dst = ip6_dst or self.ip6_dst + self.ip_bin_src = ip_bin_src or self.ip_bin_src + self.ip_bin_dst = ip_bin_dst or self.ip_bin_dst self.l4_packet = string.char(self.icmpv6_type,self.icmpv6_code) .. @@ -354,20 +354,20 @@ end --- Build an ICMPv6 Echo Request frame. -- @param mac_src six-byte string of source MAC address. -- @param mac_dst sis-byte string of destination MAC address. --- @param ip6_src 16-byte string of source IPv6 address. --- @param ip6_dst 16-byte string of destinatiion IPv6 address. +-- @param ip_bin_src 16-byte string of source IPv6 address. +-- @param ip_bin_dst 16-byte string of destinatiion IPv6 address. -- @param id integer that represents Echo ID. -- @param sequence integer that represents Echo sequence. -- @param data string of Echo data. -- @param tc integer that represents traffic class of IPv6 packet. -- @param fl integer that represents flow label of IPv6 packet. -- @param hop-limit integer that represents hop limit of IPv6 packet. -function Packet:build_icmpv6_echo_request(id, sequence, data, mac_src, mac_dst, ip6_src, ip6_dst, tc, fl, hop_limit) +function Packet:build_icmpv6_echo_request(id, sequence, data, mac_src, mac_dst, ip_bin_src, ip_bin_dst, tc, fl, hop_limit) self.mac_src = mac_src or self.mac_src self.mac_dst = mac_dst or self.mac_dst - self.ip6_src = ip6_src or self.ip6_src - self.ip6_dst = ip6_dst or self.ip6_dst + self.ip_bin_src = ip_bin_src or self.ip_bin_src + self.ip_bin_dst = ip_bin_dst or self.ip_bin_dst self.traffic_class = tc or 1 self.flow_label = fl or 1 self.ip6_hlimit = hop_limit or 255 @@ -576,11 +576,13 @@ end function Packet:ip_parse(force_continue) self.ip_offset = 0 if #self.buf < 20 then -- too short + print("too short") return false end self.ip_v = bit.rshift(bit.band(self:u8(self.ip_offset + 0), 0xF0), 4) self.ip_hl = bit.band(self:u8(self.ip_offset + 0), 0x0F) -- header_length or data_offset if self.ip_v ~= 4 then -- not ip + print("not v4") return false end self.ip = true @@ -622,8 +624,10 @@ function Packet:ip6_parse(force_continue) self.ip6_plen = self:u16(self.ip6_offset + 4) self.ip6_nhdr = self:u8(self.ip6_offset + 6) self.ip6_hlimt = self:u8(self.ip6_offset + 7) - self.ip6_src = self:raw(self.ip6_offset + 8, 16) - self.ip6_dst = self:raw(self.ip6_offset + 24, 16) + self.ip_bin_src = self:raw(self.ip6_offset + 8, 16) + self.ip_bin_dst = self:raw(self.ip6_offset + 24, 16) + self.ip_src = toipv6(self.ip_bin_src) + self.ip_dst = toipv6(self.ip_bin_dst) self.ip6_data_offset = 40 return true end diff --git a/scripts/firewalk.nse b/scripts/firewalk.nse index ef3810ecc..bd5689a71 100644 --- a/scripts/firewalk.nse +++ b/scripts/firewalk.nse @@ -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)] diff --git a/scripts/ipv6-node-info.nse b/scripts/ipv6-node-info.nse index 0bf3e035f..8b7f69542 100644 --- a/scripts/ipv6-node-info.nse +++ b/scripts/ipv6-node-info.nse @@ -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 diff --git a/scripts/targets-ipv6-multicast-echo.nse b/scripts/targets-ipv6-multicast-echo.nse index 92aa8e201..20d864939 100644 --- a/scripts/targets-ipv6-multicast-echo.nse +++ b/scripts/targets-ipv6-multicast-echo.nse @@ -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) diff --git a/scripts/targets-ipv6-multicast-invalid-dst.nse b/scripts/targets-ipv6-multicast-invalid-dst.nse index 047475c7d..3ef584119 100644 --- a/scripts/targets-ipv6-multicast-invalid-dst.nse +++ b/scripts/targets-ipv6-multicast-invalid-dst.nse @@ -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) diff --git a/scripts/targets-ipv6-multicast-slaac.nse b/scripts/targets-ipv6-multicast-slaac.nse index 080e219ac..108987c45 100644 --- a/scripts/targets-ipv6-multicast-slaac.nse +++ b/scripts/targets-ipv6-multicast-slaac.nse @@ -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.