1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Resolves ether_type incompatibility in packet.Frame

Frame:new() was populating the value as a 16-bit integer while
Frame:build_ether_frame() was expectng a two-byte string
Ethertype constants from various locations have been migrated to packet.lua
This commit is contained in:
nnposter
2024-08-25 17:43:17 +00:00
parent 5e35bc0952
commit 2646596f0f
6 changed files with 18 additions and 19 deletions

View File

@@ -20,6 +20,9 @@ o [GH#2901, GH#2744, GH#2745] Arbitrary separator in stdnse.tohex() is now
supported. Script smb-protocols now reports SMB dialects correctly. supported. Script smb-protocols now reports SMB dialects correctly.
[nnposter] [nnposter]
o [NSE] ether_type inconsistency in packet.Frame has been resolved. Bothi
Frame:new() and Frame:build_ether_frame() now use an integer. [nnposter]
o [GH#2900, GH#2896, GH#2897] Nmap is now able to scan IP protocol 255. o [GH#2900, GH#2896, GH#2897] Nmap is now able to scan IP protocol 255.
[nnposter] [nnposter]

View File

@@ -41,8 +41,6 @@ _ENV = stdnse.module("eap", stdnse.seeall)
-- Created 02/23/2012 - v0.1 -- Created 02/23/2012 - v0.1
local ETHER_BROADCAST = "01:80:c2:00:00:03" local ETHER_BROADCAST = "01:80:c2:00:00:03"
local ETHER_TYPE_EAPOL_N = 0x888E
local ETHER_TYPE_EAPOL = string.pack(">I2",ETHER_TYPE_EAPOL_N)
local ETHER_HEADER_SIZE = 14 local ETHER_HEADER_SIZE = 14
local EAPOL_HEADER_SIZE = 4 local EAPOL_HEADER_SIZE = 4
local EAP_HEADER_SIZE = 5 local EAP_HEADER_SIZE = 5
@@ -162,7 +160,7 @@ local make_eapol = function (arg)
local p = packet.Frame:new() local p = packet.Frame:new()
p.mac_src = arg.src p.mac_src = arg.src
p.mac_dst = packet.mactobin(ETHER_BROADCAST) p.mac_dst = packet.mactobin(ETHER_BROADCAST)
p.ether_type = ETHER_TYPE_EAPOL p.ether_type = packet.ETHER_TYPE_EAPOL
p.buf = string.pack(">BBs2", arg.version, arg.type, arg.payload) p.buf = string.pack(">BBs2", arg.version, arg.type, arg.payload)
p:build_ether_frame() p:build_ether_frame()
@@ -202,7 +200,7 @@ parse = function (pkt)
stdnse.debug1("mac_src: %s, mac_dest: %s, ether_type: 0x%X", stdnse.debug1("mac_src: %s, mac_dest: %s, ether_type: 0x%X",
tb.mac_src_str, tb.mac_dst_str, tb.ether_type) tb.mac_src_str, tb.mac_dst_str, tb.ether_type)
if tb.ether_type ~= ETHER_TYPE_EAPOL_N then return nil, "not an eapol packet" end if tb.ether_type ~= packet.ETHER_TYPE_EAPOL then return nil, "not an eapol packet" end
stdnse.debug2("version: %X, type: %s, length: 0x%X", stdnse.debug2("version: %X, type: %s, length: 0x%X",
tb.version, eapol_str[tb.type] or "unknown", tb.version, eapol_str[tb.type] or "unknown",

View File

@@ -135,8 +135,12 @@ ND_OPT_MTU = 5
ND_OPT_RTR_ADV_INTERVAL = 7 ND_OPT_RTR_ADV_INTERVAL = 7
ND_OPT_HOME_AGENT_INFO = 8 ND_OPT_HOME_AGENT_INFO = 8
ETHER_TYPE_IPV4 = "\x08\x00" ETHER_TYPE_IPV4 = 0x0800
ETHER_TYPE_IPV6 = "\x86\xdd" ETHER_TYPE_IPV6 = 0x86dd
ETHER_TYPE_PPPOE_DISCOVERY = 0x8863
ETHER_TYPE_PPPOE_SESSION = 0x8864
ETHER_TYPE_EAPOL = 0x888e
ETHER_TYPE_ATAOE = 0x88a2
---------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------
-- Frame is a class -- Frame is a class
@@ -160,7 +164,7 @@ end
--- Build an Ethernet frame. --- Build an Ethernet frame.
-- @param mac_dst six-byte string of the destination MAC address. -- @param mac_dst six-byte string of the destination MAC address.
-- @param mac_src six-byte string of the source MAC address. -- @param mac_src six-byte string of the source MAC address.
-- @param ether_type two-byte string of the type. -- @param ether_type IEEE 802 ethertype as a 16-bit integer (0x0800 for IPv4)
-- @param packet string of the payload. -- @param packet string of the payload.
-- @return frame string of the Ether frame. -- @return frame string of the Ether frame.
function Frame:build_ether_frame(mac_dst, mac_src, ether_type, packet) function Frame:build_ether_frame(mac_dst, mac_src, ether_type, packet)
@@ -171,7 +175,7 @@ function Frame:build_ether_frame(mac_dst, mac_src, ether_type, packet)
if not self.ether_type then if not self.ether_type then
return nil, "Unknown packet type." return nil, "Unknown packet type."
end end
self.frame_buf = self.mac_dst..self.mac_src..self.ether_type..self.buf self.frame_buf = self.mac_dst..self.mac_src..(">I2"):pack(self.ether_type)..self.buf
end end
--- Parse an Ethernet frame. --- Parse an Ethernet frame.
-- @param frame string of the Ether frame. -- @param frame string of the Ether frame.

View File

@@ -30,11 +30,6 @@ local table = require "table"
_ENV = stdnse.module("pppoe", stdnse.seeall) _ENV = stdnse.module("pppoe", stdnse.seeall)
EtherType = {
PPPOE_DISCOVERY = 0x8863,
PPPOE_SESSION = 0x8864,
}
-- A Class to handle the Link Control Protocol LCP -- A Class to handle the Link Control Protocol LCP
LCP = { LCP = {
@@ -709,7 +704,7 @@ Comm = {
local p = packet.Frame:new(l2..l3) local p = packet.Frame:new(l2..l3)
-- there's probably a more elegant way of doing this -- there's probably a more elegant way of doing this
if ( EtherType.PPPOE_DISCOVERY == p.ether_type ) then if ( packet.ETHER_TYPE_PPPOE_DISCOVERY == p.ether_type ) then
if ( header.code == PPPoE.Code.PADO ) then if ( header.code == PPPoE.Code.PADO ) then
local pado = PPPoE.PADO.parse(l3) local pado = PPPoE.PADO.parse(l3)
pado.mac_srv = p.mac_src pado.mac_srv = p.mac_src
@@ -721,7 +716,7 @@ Comm = {
local pads = PPPoE.PADT.parse(l3) local pads = PPPoE.PADT.parse(l3)
return true, pads return true, pads
end end
elseif ( EtherType.PPPOE_SESSION == p.ether_type ) then elseif ( packet.ETHER_TYPE_PPPOE_SESSION == p.ether_type ) then
return true, PPPoE.SessionData.parse(l3) return true, PPPoE.SessionData.parse(l3)
end end
return false, ("Received unsupported response, can't decode code (%d)"):format(header.code) return false, ("Received unsupported response, can't decode code (%d)"):format(header.code)

View File

@@ -105,14 +105,14 @@ ATAoE = {
-- Send a Config Info Request to the ethernet broadcast address -- Send a Config Info Request to the ethernet broadcast address
-- @param iface table as returned by nmap.get_interface_info() -- @param iface table as returned by nmap.get_interface_info()
local function sendConfigInfoRequest(iface) local function sendConfigInfoRequest(iface)
local ETHER_BROADCAST, P_ATAOE = "ff:ff:ff:ff:ff:ff", 0x88a2 local ETHER_BROADCAST = "ff:ff:ff:ff:ff:ff"
local req = ATAoE.ConfigInfoRequest:new() local req = ATAoE.ConfigInfoRequest:new()
local tag = req.tag local tag = req.tag
local p = packet.Frame:new() local p = packet.Frame:new()
p.mac_src = iface.mac p.mac_src = iface.mac
p.mac_dst = packet.mactobin(ETHER_BROADCAST) p.mac_dst = packet.mactobin(ETHER_BROADCAST)
p.ether_type = string.pack(">I2", P_ATAOE) p.ether_type = packet.ETHER_TYPE_ATAOE
p.buf = tostring(req) p.buf = tostring(req)
p:build_ether_frame() p:build_ether_frame()

View File

@@ -147,8 +147,7 @@ local function dhcp_listener(sock, iface, macaddr, options, timeout, xid, result
-- Add the Ethernet header -- Add the Ethernet header
frame:build_ether_frame( frame:build_ether_frame(
"\xff\xff\xff\xff\xff\xff", "\xff\xff\xff\xff\xff\xff",
iface.mac, -- can't use macaddr or we won't see response iface.mac) -- can't use macaddr or we won't see response
packet.ETHER_TYPE_IPV4)
local dnet = nmap.new_dnet() local dnet = nmap.new_dnet()
dnet:ethernet_open(iface.device) dnet:ethernet_open(iface.device)