首页 > 其他 > 详细

wireshark插件开发 - Lua插件解析

时间:2017-08-20 09:18:29      阅读:291      评论:0      收藏:0      [点我收藏+]

wireshark支持C语言和Lua语言开发插件,本部分内先介绍Lua插件部分开发。Lua语言相对C语言开发有一个巨大的优势,就是不需要编译代码,因为Lua语言是脚本语言,只需要编写相关协议解析的脚本内容,然后由wireshark加载即可(Wireshark自带Lua解析器),wireshark封装丰富的接口给Lua使用,

实现代码

 1 -----------------------------------------------------------------
 2 -- wireshark分析udp sample协议插件
 3 -- 将自定义协议以可读的方式展示在wireshark中
 4 -----------------------------------------------------------------
 5 --基于UDP协议
 6 local udp_table = DissectorTable.get("udp.port")
 7 local my_proto = Proto("udp-sample", "udp sample protocol", "udp sample protocol")
 8 --协议端口号
 9 local my_port = 11110
10 
11 --定义协议字段内容
12 local versionField = ProtoField.uint16("Version", "Version", base.DEC)
13 local idField = ProtoField.uint32("ID", "ID", base.DEC)
14 local stringField = ProtoField.string("Buffer", "Buffer")
15 
16 my_proto.fields = {versionField, idField, stringField}
17 
18 --协议分析器
19 function my_proto.dissector(buffer, pinfo, tree)
20 pinfo.cols.protocol:set("udp-sample")
21 
22 local len = buffer:len()
23 local myProtoTree = tree:add(my_proto, buffer(0, len), "udp sample protocol")
24 local offset = 0
25 myProtoTree:add(versionField, buffer(offset, 2))
26 offset = offset + 2
27 
28 myProtoTree:add(idField, buffer(offset, 4))
29 offset = offset + 4
30 
31 myProtoTree:add(stringField, buffer(offset, 1024))
32 end
33 
34 --增加协议到Wireshark中
35 udp_table:add(my_port, my_proto)

 

 技术分享

 

 加载

修改wireshark根目录下面的init.lua文件

在文件尾部追加下面一行代码,假设Lua解析文件名为udp-sample

dofile("udp-sample.lua")

 技术分享

 

解析成功会出现上图红线所标注内容

结果展示

通过客户端程序连接服务端程序,并抓包,过滤结果展示如下:

 技术分享

 

wireshark插件开发 - Lua插件解析

原文:http://www.cnblogs.com/99code/p/7398834.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!