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