wireshark插件开发 - Lua插件解析

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhujf21st/article/details/78043313
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")

 

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

结果展示

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

 

更多更完整的内容,请移步百度阅读:

https://yuedu.baidu.com/ebook/ca33e60d3a3567ec102de2bd960590c69ec3d89b

猜你喜欢

转载自blog.csdn.net/zhujf21st/article/details/78043313
今日推荐