add wireshark support for UDP
This commit is contained in:
parent
6824e1a39f
commit
8ee80fecc7
@ -24,65 +24,45 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
-- Create TP-Link Smart Home protocol and its fields
|
-- Create TP-Link Smart Home protocol and its fields
|
||||||
p_tplink = Proto ("TPLink-SmartHome","TP-Link Smart Home Protocol")
|
hs1x0_proto_TCP = Proto ("TPLink-SmartHome-TCP", "TP-Link Smart Home Protocol (TCP")
|
||||||
|
hs1x0_proto_UDP = Proto ("TPLink-SmartHome-UDP", "TP-Link Smart Home Protocol (UDP)")
|
||||||
|
|
||||||
-- Dissector function
|
-- Decrypt string Autokey XOR to ByteArray
|
||||||
function p_tplink.dissector (buf, pkt, root)
|
function tpdecode(buf, start)
|
||||||
-- Validate packet length
|
local key = 171
|
||||||
if buf:len() == 0 then return end
|
local size = buf:len()-1
|
||||||
pkt.cols.protocol = p_tplink.name
|
local decoded = ""
|
||||||
|
for i=start,size do
|
||||||
-- Decode data
|
local c = buf(i,1):uint()
|
||||||
local ascii = ""
|
decoded = decoded .. string.format("%x", bit.bxor(c,key))
|
||||||
local hex = ""
|
key = c
|
||||||
|
end
|
||||||
-- Skip first 4 bytes (header)
|
return ByteArray.new(decoded)
|
||||||
start = 4
|
end
|
||||||
endPosition = buf:len() - 1
|
|
||||||
|
|
||||||
-- Decryption key is -85 (256-85=171)
|
|
||||||
local key = 171
|
|
||||||
|
|
||||||
-- Decrypt Autokey XOR
|
function hs1x0_proto_TCP.dissector (buf, pkt, root)
|
||||||
-- Save results as ascii and hex
|
pkt.cols.protocol = "TPLink-SmartHome (TCP)"
|
||||||
for index = start, endPosition do
|
local subtree = root:add(hs1x0_proto_TCP, buf() ,"TPLink-SmartHome")
|
||||||
local c = buf(index,1):uint()
|
local decoded = tpdecode(buf, 4)
|
||||||
-- XOR first byte with key
|
subtree:add(decoded:raw())
|
||||||
d = bit32.bxor(c,key)
|
|
||||||
-- Use byte as next key
|
|
||||||
key = c
|
|
||||||
|
|
||||||
hex = hex .. string.format("%x", d)
|
|
||||||
-- Convert to printable characters
|
|
||||||
if d >= 0x20 and d <= 0x7E then
|
|
||||||
ascii = ascii .. string.format("%c", d)
|
|
||||||
else
|
|
||||||
-- Use dot for non-printable bytes
|
|
||||||
ascii = ascii .. "."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- Create subtree
|
|
||||||
subtree = root:add(p_tplink, buf(0))
|
|
||||||
|
|
||||||
-- Add data to subtree
|
|
||||||
subtree:add(ascii)
|
|
||||||
-- Description of payload
|
|
||||||
subtree:append_text(" (decrypted)")
|
subtree:append_text(" (decrypted)")
|
||||||
|
local tvb = ByteArray.tvb(decoded, "JSON TVB")
|
||||||
-- Call JSON Dissector with decrypted data
|
|
||||||
local b = ByteArray.new(hex)
|
|
||||||
local tvb = ByteArray.tvb(b, "JSON TVB")
|
|
||||||
Dissector.get("json"):call(tvb, pkt, root)
|
Dissector.get("json"):call(tvb, pkt, root)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Initialization routine
|
function hs1x0_proto_UDP.dissector (buf, pkt, root)
|
||||||
function p_tplink.init()
|
pkt.cols.protocol = "TPLink-SmartHome (UDP)"
|
||||||
|
local subtree = root:add(hs1x0_proto_UDP, buf() ,"TPLink-SmartHome")
|
||||||
|
local decoded = tpdecode(buf, 0)
|
||||||
|
subtree:add(decoded:raw())
|
||||||
|
subtree:append_text(" (decrypted)")
|
||||||
|
local tvb = ByteArray.tvb(decoded, "JSON TVB")
|
||||||
|
Dissector.get("json"):call(tvb, pkt, root)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Register a chained dissector for port 9999
|
tcp_table = DissectorTable.get ("tcp.port")
|
||||||
local tcp_dissector_table = DissectorTable.get("tcp.port")
|
udp_table = DissectorTable.get ("udp.port")
|
||||||
dissector = tcp_dissector_table:get_dissector(9999)
|
|
||||||
tcp_dissector_table:add(9999, p_tplink)
|
-- register the protocol to port 9999
|
||||||
|
tcp_table:add (9999, hs1x0_proto_TCP)
|
||||||
|
udp_table:add (9999, hs1x0_proto_UDP)
|
||||||
|
Loading…
Reference in New Issue
Block a user