fixed lua errors in non-iec104 packets (#1209)
* Update iec.lua fixed lua errors in non iec 104 packets * Update iec.lua Co-authored-by: tinu <martin.scheu@switch.ch>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
--
|
||||
-- (C) 2021 - switch.ch
|
||||
-- IEC 60870-5-14 expert anlysis PoC for sharkfest Europe 2021
|
||||
-- Version 1.0
|
||||
--
|
||||
|
||||
|
||||
@@ -17,6 +19,10 @@ local f_cp56time_year = Field.new("iec60870_asdu.cp56time.year")
|
||||
|
||||
local f_tcplen = Field.new("tcp.len")
|
||||
local f_payload = Field.new("tcp.payload")
|
||||
local f_src_port = Field.new("tcp.srcport")
|
||||
local f_dst_port = Field.new("tcp.dstport")
|
||||
|
||||
local f_asdu_start = Field.new("iec60870_asdu.start")
|
||||
|
||||
|
||||
-- ###############################################
|
||||
@@ -88,12 +94,15 @@ function iec_analysis.dissector(tvb, pinfo, tree)
|
||||
|
||||
if (pinfo.visited == true) then
|
||||
|
||||
|
||||
-- get raw data
|
||||
local tcplenRaw = { f_tcplen() }
|
||||
local payloadRaw = { f_payload() }
|
||||
local dstportRaw = { f_dst_port() }
|
||||
local srcportRaw = { f_src_port() }
|
||||
local asdu_start = { f_asdu_start() }
|
||||
|
||||
|
||||
if ((tcplenRaw ~= nil) and (payloadRaw ~= nil )) then
|
||||
if ((tcplenRaw ~= nil) and (payloadRaw ~= nil )) and (dstportRaw ~= nil) and (srcportRaw ~= nil) and (asdu_start ~= nil) then
|
||||
|
||||
|
||||
local cp56time_min = { f_cp56time_min() }
|
||||
@@ -143,6 +152,8 @@ function iec_analysis.dissector(tvb, pinfo, tree)
|
||||
|
||||
|
||||
local tcplen = tonumber(getval(tcplenRaw[#tcplenRaw]))
|
||||
local srcport = tonumber(getval(srcportRaw[#srcportRaw]))
|
||||
local dstport = tonumber(getval(dstportRaw[#dstportRaw]))
|
||||
local payload = tostring(getval(payloadRaw[#payloadRaw]))
|
||||
|
||||
local APDU_type = {"Length", "Type", "Rx", "Tx", "TypeID", "TestFr", "StartPos", "CauseTx", "IOA", "NumIx"}
|
||||
@@ -158,8 +169,10 @@ function iec_analysis.dissector(tvb, pinfo, tree)
|
||||
local APDU_StartPos = {}
|
||||
|
||||
--read first APDU length and check wheater payload contains multiple APDUs or not
|
||||
if ((payload ~= nil) and (tcplen > 3 )) then
|
||||
--additional checks
|
||||
if ((payload ~= nil) and (tcplen ~= nil ) and (asdu_start ~= nil ) and ((srcport == 2404) or (dstport == 2404)) ) then
|
||||
|
||||
if ((tcplen > 3) and (tonumber(string.sub(payload,StartPos,StartPos + 1),16)==104)) then
|
||||
--define APDUs start positions, containing 0x68
|
||||
if ((tonumber(string.sub(payload,4,5),16) + 2) < tcplen) then
|
||||
--multiple APDUs
|
||||
@@ -213,7 +226,7 @@ function iec_analysis.dissector(tvb, pinfo, tree)
|
||||
end
|
||||
|
||||
if #APDU_StartPos > 8 then
|
||||
msg2 = "Payload contains more then 8 APDU objects (wireshark disects only 8 APDU objects). Number of APDU objects found: " .. #APDU_StartPos
|
||||
msg2 = "Payload contains more then 8 APDU objects. Number of APDU objects found: " .. #APDU_StartPos
|
||||
end
|
||||
|
||||
if (msg3 ~= "") then
|
||||
@@ -240,6 +253,7 @@ function iec_analysis.dissector(tvb, pinfo, tree)
|
||||
-- end of: if ((payload ~= nil) and (tcplen > 3 )) then
|
||||
end
|
||||
|
||||
end
|
||||
-- end of: if ((tcplenRaw ~= nil) and (payloadRaw ~= nil )) then
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user