mirror of
https://github.com/nmap/nmap.git
synced 2025-12-19 22:19:02 +00:00
Simplify ARP packet decoder
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
local bin = require "bin"
|
local bin = require "bin"
|
||||||
|
local ipOps = require "ipOps"
|
||||||
local packet = require "packet"
|
local packet = require "packet"
|
||||||
local stdnse = require "stdnse"
|
local stdnse = require "stdnse"
|
||||||
|
local string = require "string"
|
||||||
local tab = require "tab"
|
local tab = require "tab"
|
||||||
local table = require "table"
|
local table = require "table"
|
||||||
local target = require "target"
|
local target = require "target"
|
||||||
@@ -76,32 +78,32 @@ Decoders = {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
process = function(self, data)
|
process = function(self, data)
|
||||||
local ipOps = require("ipOps")
|
stdnse.debug1("Process ARP")
|
||||||
local pos, hw, proto, hwsize, protosize, opcode = bin.unpack(">SSCCS", data)
|
local hw, proto, hwsize, protosize, opcode, pos = string.unpack(">I2 I2 BB I2", data)
|
||||||
|
stdnse.debug1("hwsize = %d; opcode = %d", hwsize, opcode)
|
||||||
|
|
||||||
-- this shouldn't ever happen, given our filter
|
-- this shouldn't ever happen, given our filter
|
||||||
if ( hwsize ~= 6 ) then return end
|
if ( hwsize ~= 6 ) then return end
|
||||||
local sender, target = {}, {}
|
|
||||||
|
|
||||||
-- if this isn't an ARP request, abort
|
-- if this isn't an ARP request, abort
|
||||||
if ( opcode ~= 1 ) then return end
|
if ( opcode ~= 1 ) then return end
|
||||||
|
|
||||||
pos, sender.mac,
|
local src_mac, src_ip, dst_mac, dst_ip, pos = string.unpack(">c6 c4 c6 c4", data, pos)
|
||||||
sender.ip,
|
stdnse.debug1("unpacked addresses")
|
||||||
target.mac,
|
|
||||||
target.ip = bin.unpack(">H" .. hwsize .. "IH" .. hwsize .. "I", data, pos)
|
|
||||||
|
|
||||||
if ( not(self.results) ) then
|
if ( not(self.results) ) then
|
||||||
self.results = tab.new(3)
|
self.results = tab.new(3)
|
||||||
tab.addrow(self.results, 'sender ip', 'sender mac', 'target ip')
|
tab.addrow(self.results, 'sender ip', 'sender mac', 'target ip')
|
||||||
end
|
end
|
||||||
|
|
||||||
local mac = sender.mac:gsub("(..)(..)(..)(..)(..)(..)","%1:%2:%3:%4:%5:%6")
|
src_mac = stdnse.format_mac(src_mac)
|
||||||
stdnse.debug1("Decoded ARP: %s, %s, %s", ipOps.fromdword(sender.ip), mac, ipOps.fromdword(target.ip))
|
--dst_mac = stdnse.format_mac(dst_mac)
|
||||||
if ( not(self.dups[("%u:%s"):format(sender.ip,sender.mac)]) ) then
|
src_ip = ipOps.str_to_ip(src_ip)
|
||||||
if ( target.ALLOW_NEW_TARGETS ) then target.add(sender.ip) end
|
dst_ip = ipOps.str_to_ip(dst_ip)
|
||||||
self.dups[("%u:%s"):format(sender.ip,sender.mac)] = true
|
stdnse.debug1("Decoded ARP: %s, %s, %s", src_ip, src_mac, dst_ip)
|
||||||
tab.addrow(self.results, ipOps.fromdword(sender.ip), mac, ipOps.fromdword(target.ip))
|
if not self.dups[src_ip .. src_mac] then
|
||||||
|
if target.ALLOW_NEW_TARGETS then target.add(src_ip) end
|
||||||
|
self.dups[src_ip .. src_mac] = true
|
||||||
|
tab.addrow(self.results, src_ip, src_mac, dst_ip)
|
||||||
end
|
end
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|||||||
Reference in New Issue
Block a user