1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-12 10:49:02 +00:00

Moved EIGRP decoding in packetdecoders.lua to use eigrp.lua library.

This commit is contained in:
kroosec
2012-08-15 09:17:20 +00:00
parent 8d71da78de
commit 8ff4cebbf7

View File

@@ -187,8 +187,8 @@ Decoders = {
}, },
-- EIGRP Query & Update -- EIGRP Update
['020[13]....00000000'] = { ['0201....0000'] = {
new = function(self) new = function(self)
local o = { dups = {} } local o = { dups = {} }
@@ -205,95 +205,44 @@ Decoders = {
local data = layer3:sub(p.ip_data_offset + 1) local data = layer3:sub(p.ip_data_offset + 1)
local eigrp = require("eigrp")
local route_type, proto_name
-- Extract the EIGRP header -- Extract the EIGRP header
local pos, ver, opcode, checksum, flags, seq, ack, asnum = bin.unpack(">CCSiiii", data) local response = eigrp.EIGRP.parse(data)
local route_type, size, nexthop, delay, bandwidth, temp, mtu, orig_router, orig_as, arbtag if response then
local hop_count, reliability, load, reserved, mask -- Iterate over tlv tables
local destination for _, tlv in pairs(response.tlvs) do
if eigrp.EIGRP.isRoutingTLV(tlv.type) then
-- Iterate over the routes
while ( pos < #data ) do
-- Get the route type as the packet construction varies
pos,route_type = bin.unpack(">S", data, pos)
if ( route_type == 258 ) then
route_type = 'internal'
pos, size, nexthop, delay, bandwidth, temp, mtu = bin.unpack(">SiiiCS", data, pos)
pos, hop_count, reliability, load, reserved, mask = bin.unpack(">CCCSC", data, pos)
local oct1, oct2, oct3, oct4 = 0, 0, 0, 0
-- unneeded address octets are left out of the packets, lets fill in the gaps
if ( size == 29 ) then
-- mask 25 or above
pos, oct1, oct2, oct3, oct4 = bin.unpack(">CCCC", data, pos)
elseif ( size == 28 ) then
pos, oct1, oct2, oct3 = bin.unpack(">CCC", data, pos)
elseif ( size == 27 ) then
pos, oct1, oct2 = bin.unpack(">CC", data, pos)
elseif ( size == 26 ) then
pos, oct1 = bin.unpack(">C", data, pos)
end
destination = oct1 .. '.' .. oct2 .. '.' .. oct3 .. '.' .. oct4 .. "/" .. mask
orig_router = 'n/a'
elseif ( route_type == 259 ) then
-- external route, from a different routing protocol
pos, size, nexthop = bin.unpack(">Si", data, pos)
local orig_rtr_oct1, orig_rtr_oct2, orig_rtr_oct3, orig_rtr_oct4, ext_proto_id, ext_metric
pos, orig_rtr_oct1, orig_rtr_oct2, orig_rtr_oct3, orig_rtr_oct4 = bin.unpack(">CCCC", data, pos)
orig_router = orig_rtr_oct1 .. '.' .. orig_rtr_oct2 .. '.' .. orig_rtr_oct3 .. '.' .. orig_rtr_oct4
pos, orig_as, arbtag, ext_metric = bin.unpack(">iii", data, pos)
pos, reserved, ext_proto_id, flags, delay, bandwidth = bin.unpack(">SCCii", data, pos)
pos, temp, mtu, hop_count, reliability, load, reserved, mask = bin.unpack(">CSCCCSC", data, pos)
local oct1, oct2, oct3, oct4 = 0, 0, 0, 0
-- unneeded address octets are left out of the packets, lets fill in the gaps
if ( size == 49 ) then
-- mask 25 or above
pos, oct1, oct2, oct3, oct4 = bin.unpack(">CCCC", data, pos)
elseif ( size == 48 ) then
pos, oct1, oct2, oct3 = bin.unpack(">CCC", data, pos)
elseif ( size == 47 ) then
pos, oct1, oct2 = bin.unpack(">CC", data, pos)
elseif ( size == 46 ) then
pos, oct1 = bin.unpack(">C", data, pos)
end
destination = oct1 .. '.' .. oct2 .. '.' .. oct3 .. '.' .. oct4 .. "/" .. mask
local Proto_Types = {
[1] = 'external (IGRP)',
[2] = 'external (EIGRP)',
[3] = 'external (static)',
[4] = 'external (RIP)',
[6] = 'external (OSPF)',
[9] = 'external (RIP)'
}
route_type = Proto_Types[ext_proto_id]
end
if ( not(self.results) ) then if ( not(self.results) ) then
self.results = tab.new(9) self.results = tab.new(7)
tab.addrow(self.results, 'sender ip', 'AS#', 'route type', 'destination', 'hop', 'bandwidth', 'delay', 'seq','orig router') tab.addrow(self.results, 'Sender IP', 'AS#', 'Route Type', 'Destination', 'Next hop', 'Ext Protocol', 'Orig Router ID')
end end
if tlv.type == 0x102 then
route_type = "Internal"
if (delay == -1) then delay = 'unreachable' end elseif tlv.type == 0x103 then
route_type = "External"
if ( not(self.dups[("%s:%s:s:%s"):format(p.ip_src,asnum,destination,seq)]) ) then for name, value in pairs(eigrp.EXT_PROTO) do
if value == tlv.eproto then
proto_name = name
break
end
end
end
if ( not(self.dups[("%s:%s:s:%s"):format(p.ip_src, response.as, tlv.type, tlv.dst)]) ) then
if ( target.ALLOW_NEW_TARGETS ) then target.add(p.ip_src) end if ( target.ALLOW_NEW_TARGETS ) then target.add(p.ip_src) end
self.dups[("%s:%s:%s:%s"):format(p.ip_src,asnum,destination,seq)] = true self.dups[("%s:%s:%s:%s"):format(p.ip_src, response.as, tlv.type, tlv.dst)] = true
tab.addrow( self.results, p.ip_src, asnum, route_type, destination, hop_count, bandwidth, delay, seq, orig_router ) tab.addrow( self.results, p.ip_src, response.as, route_type, tlv.dst, tlv.nexth, proto_name or 'X', tlv.orouterid or 'X')
end
end
end end
end end
end, end,
getResults = function(self) return { name = "EIGRP Update", (self.results and tab.dump(self.results) or "") } end,
getResults = function(self) return { name = "EIGRP Query", (self.results and tab.dump(self.results) or "") } end,
}, },
['0205....00000000'] = { ['0205....0000'] = {
new = function(self) new = function(self)
local o = { dups = {} } local o = { dups = {} }
@@ -309,33 +258,36 @@ Decoders = {
if ( p.ip_p ~= 88 ) then return end if ( p.ip_p ~= 88 ) then return end
local data = layer3:sub(p.ip_data_offset + 1) local data = layer3:sub(p.ip_data_offset + 1)
local eigrp = require("eigrp")
-- Extract the EIGRP header -- Extract the EIGRP header
local pos, ver, opcode, checksum, flags, seq, ack, asnum = bin.unpack(">CCSiiii", data) local response = eigrp.EIGRP.parse(data)
-- See if Software version TLV is included
-- Skip the parameters for now. local swvertlv
pos = pos + 10 for num, tlv in pairs(response.tlvs) do
if tlv.type == eigrp.TLV.SWVER then
local holdtime, software, size, ios_major, ios_minor, eigrp_major, eigrp_minor swvertlv = num
pos, holdtime, software, size, ios_major, ios_minor, eigrp_major, eigrp_minor = bin.unpack(">SSSCCCC", data, pos) end
end
if swvertlv then
if ( not(self.results) ) then if ( not(self.results) ) then
self.results = tab.new(5) self.results = tab.new(5)
tab.addrow(self.results, 'sender ip', 'AS number', 'hold time', 'EIGRP version', 'IOS version') tab.addrow(self.results, 'Sender IP', 'AS number', 'EIGRP version', 'IOS version')
end end
if ( not(self.dups[("%s:%s"):format(p.ip_src,asnum)]) ) then if ( not(self.dups[("%s:%s"):format(p.ip_src,response.as)]) ) then
if ( target.ALLOW_NEW_TARGETS ) then target.add(p.ip_src) end if ( target.ALLOW_NEW_TARGETS ) then target.add(p.ip_src) end
self.dups[("%s:%s"):format(p.ip_src,asnum)] = true self.dups[("%s:%s"):format(p.ip_src,response.as)] = true
tab.addrow( self.results, p.ip_src, asnum, holdtime, eigrp_major .. '.' .. eigrp_minor, ios_major .. '.' .. ios_minor ) tab.addrow( self.results, p.ip_src, response.as, response.tlvs[swvertlv].majv .. '.' .. response.tlvs[swvertlv].minv, response.tlvs[swvertlv].majtlv .. '.' .. response.tlvs[swvertlv].mintlv)
end
end end
end, end,
getResults = function(self) return { name = "EIGRP Hello", (self.results and tab.dump(self.results) or "") } end, getResults = function(self) return { name = "EIGRP Hello", (self.results and tab.dump(self.results) or "") } end,
}, },
-- OSPF -- OSPF
['0201'] = { -- OSPFv2 Hello packet ['02010'] = { -- OSPFv2 Hello packet
new = function(self) new = function(self)
local o = { dups = {} } local o = { dups = {} }
@@ -748,4 +700,4 @@ Decoders = {
} }
} }
} }