Lua 如何让wireshark启发式解剖器工作?
我正在编写一个lua脚本作为wireshark(1.12.4)插件来解析我的私有协议,我可以让它像普通的解析器一样工作,将某个端口(如80)绑定到可解析的“tcp.port”。伪代码如下:Lua 如何让wireshark启发式解剖器工作?,lua,wireshark,Lua,Wireshark,我正在编写一个lua脚本作为wireshark(1.12.4)插件来解析我的私有协议,我可以让它像普通的解析器一样工作,将某个端口(如80)绑定到可解析的“tcp.port”。伪代码如下: 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.
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)
问题是:
如果我的协议没有在某个端口上运行,因为我不想每次都修改上面的端口,我实际上希望解析器足够聪明,能够动态地识别某种模式,然后进行正确的解析。
我已经找到了一个所谓的“启发式”剖析器,我在下面添加了代码进行测试,但我无法让它工作
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)
当我更改端口时,数据包不会被解析为我的协议,因此我必须使用“解码为”菜单
那么,如何根据我的代码获得启发式解析器的工作?我是否遗漏了什么
顺便说一句,代码的答案很好。遗憾的是,如果你需要一个启发式剖析器(HD),它不能以插件的方式完成,你需要编写一个新的HD (是的,已经两年多了,但如果未来的谷歌发现了它……)