【发布时间】:2015-05-25 12:04:46
【问题描述】:
我正在编写一个 lua 脚本作为 wireshark(1.12.4) 插件来剖析我的私有协议,我可以让它像普通剖析器一样工作,它将某个端口(例如 80)绑定到 DissectorTable“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.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)
当我更改端口时,数据包没有被解析为我的协议,所以我必须使用“解码为”菜单。
那么,我怎样才能让启发式解析器基于我的代码工作?我错过了什么吗?
顺便说一句,感谢代码的答案。
【问题讨论】: