Wireshark Lua插件入门

摘要

开发中经常通过抓包分析协议,对于常见的协议如 DNS wireshark 支持自动解析,便于人类的理解,对于一些私有协议,wireshark 提供了插件的方式自定义解析逻辑。

1 动手

废话少说,直接上手。

  1. 第一步当然是装上wireshark
  2. Win+R 输入 %APPDATA%\Wireshark,在打开的文件夹中新建插件文件夹:plugins
  3. 在 plugins 下创建 xxx.lua,直接开始编辑即可
Lua 复制代码
local my_proto = Proto("my_proto", "My Protocol")

local p_type = ProtoField.uint8("my_proto.p_type", "Type", base.DEC);
local p_val = ProtoField.uint16("my_proto.p_val", "Val", base.HEX);
local p_byte = ProtoField.new("Bytes", "my_proto.bytes", ftypes.BYTES)
local p_str = ProtoField.new("Str", "my_proto.str", ftypes.STRING)

my_proto.fields = {
	p_type,
	p_flag,
	p_val,
	p_byte,
	p_str
}

--[[
	tvb: 待解析数据
	pinfo: 协议解析树信息,包括UI上的显示
	treeitem: 上一级解析树
--]]
function process(tvb, length, tree)
	local offset = 0
	
	tree:add(p_type, tvb:range(offset, 1))
	offset = offset + 1
	tree:add(p_val, tvb:range(offset, 2))
	offset = offset + 2
	tree:add(p_byte, tvb:range(offset, 10))
	offset = offset + 10
	tree:add(p_str, tvb:range(offset, 13))
	offset = offset + 13
	
	local left = length - offset
	tree:add(p_byte, tvb:range(offset, left))
end

function my_proto.dissector(tvb, pinfo, treeitem)
	pinfo.cols.protocol:set("MY_PROTO")
	pinfo.cols.info:set("MY_PROTO info")
	
	local tree = treeitem:add(my_proto, tvb:range(0))
	process(tvb, tvb:len(), tree)
end

-- 绑定UDP端口号57754, 凡是匹配的报文都会调用my_proto.dissector解析
local udp_table = DissectorTable.get("udp.port")
udp_table:add(57754, my_proto)

2 打完收工

Ctrl + Shift + L 刷新插件,查看解析后的报文:

3 进阶

其它骚操作参考官方文档:Chapter 10. Lua Support in Wireshark

相关推荐
猿小路1 天前
抓包工具-Wireshark
网络·测试工具·wireshark
Rabbit_QL1 天前
【网络设置】Docker 自定义网络深度解析:从踩坑到工程实践
网络·docker·容器
智航GIS1 天前
10.4 Selenium:Web 自动化测试框架
前端·python·selenium·测试工具
浩子智控1 天前
电子产品三防设计
网络·系统安全
我要升天!1 天前
Linux中《网络基础》
linux·运维·网络
安科瑞刘鸿鹏171 天前
工业自动化系统中抗晃电保护的协同控制研究
运维·网络·嵌入式硬件·物联网
廖圣平1 天前
从零开始,福袋直播间脚本研究【三】《多进程执行selenium》
python·selenium·测试工具
ZStack开发者社区1 天前
ZStack Cloud 5.5.0正式发布
运维·服务器·网络
2501_945837431 天前
云服务器的防护体系构建之道
网络·安全
徐*红1 天前
物理层-传输介质:双绞线,同轴电缆,光纤,无线传输介质
网络