wireshark如何在同一端口上使用两个lua解剖器进行正确解剖



我正在编写lua脚本作为wireshark(1.12.4)插件来剖析我的私有协议,我有两个协议,我为每个协议编写一个lua脚本,两个lua剧本似乎如下:

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)

问题是:这两个协议使用相同的端口,当我将这两个脚本添加到wireshark的init.loa中时,其中只有一个生效。那么,如何使这两个协议解析器同时正确工作呢?任何解决方案都很好,但端口无法更改。

如果端口肯定不能更改(这很奇怪,因为它似乎在端口80上运行,这是IANA为http分配的端口),那么您有两个真正的选择。

1) 从wireshark数据包列表中,使用"解码为"选项为每个tcp流手动选择所需的协议——尽管这可能会对捕获中的所有流进行修改。

2) 添加一个额外的解析器层,它从tcp.data获取有效负载,检测它是哪种协议,然后将数据传递给真正的解析器。

第三种选择,就是将单独的解剖器合并为一个。假设每个tcp流中只有一个或其他协议,那么在第一个数据包中找出它是哪个协议,然后按此进行解码。

最新更新