4
votes

I'm writting a lua script as wireshark(1.12.4) plugin to dissect my private protocols,I can get it work as normal dissector,which binding a certain port(such as 80) to DissectorTable "tcp.port".The pseudo-code as follows:

local my_pro = Proto("MyPro","My Protocol")
local my_pro_field_1 = ProtoField.uint16("MyPro.filed_1","Field 1",base.HEX)
local my_pro_field_2 = ProtoField.uint16("MyPro.filed_2","Field 2",base.HEX)
my_pro.fields = {my_pro_field_1,my_pro_field_2}

local data_dis = Dissector.get("data")

function my_pro.dissector(buf,pkt,root)
    if (buf(0,2):uint() ~= 1 or buf(2,2):uint() ~= 1) then
        data_dis:call(buf,pkt,root)
        return false
    end
    pkt.cols.protocol = "My Protocol"
    local tree = root:add(my_pro,buf(0,buf:len()))
    tree:add_le(my_pro_field_1,buf(0,2))
    tree:add_le(my_pro_field_2,buf(2,2))
    return true
end
local tcp_encap_table = DissectorTable.get("tcp.port")
tcp_encap_table:add(80,my_pro)

The problem is: What if My protocol is not running on a certain port,as I don't want to modify the port above every time,I actually want the dissector to be wise enough to dynamically identify some kind of pattern and do the right dissecting then. I've searched out there's a so called "heuristic" dissector,I add codes below to test but I could't get it work.

local function my_heur_dissector(buf,pkt,root)
    local ret = my_pro.dissector(buf,pkt,root)
    if (not ret) then
        return false
    end
    pkt.conversation = my_pro
    return true
end
my_pro:register_heuristic("tcp",my_heur_dissector)

When I change the port,the packets're not parsed as my protocol,so I have to use "Decode as" menu.

So,how can I get the heuristic dissector work base on my code?Have I missed something?

BTW,the answer with code is appreciated.

1

1 Answers

0
votes

Sadly, if you need a heuristic dissector (HD) it cannot be done in a plugin manner, and you need to write a new HD.

https://github.com/wireshark/wireshark/blob/master/doc/README.heuristic

(Yes, it has been over 2 years, but if some future-googler finds it...)