【Lua】WireShark抓包

0.首先已管理员运行wireshark

1.打开wireshark-》关于-》选择文件夹,如下图

如果目录不存在,会提示创建,这也是为

2.在目录下新建lua脚本

3.添加协议,这个协议是TCP

lua 复制代码
-- 创建名为"TCP80"的新协议,在Wireshark中显示为"TCP Port 80 Protocol"
local tcp_protocol = Proto("TCP80", "TCP Port 80 Protocol")

-- 定义要显示的字段
local fields = {
    src_port = ProtoField.uint16("tcp80.src_port", "Source Port", base.DEC),
    dst_port = ProtoField.uint16("tcp80.dst_port", "Destination Port", base.DEC),
    seq_num = ProtoField.uint32("tcp80.seq", "Sequence Number", base.DEC),
    ack_num = ProtoField.uint32("tcp80.ack", "Acknowledgment Number", base.DEC),
    data_offset = ProtoField.uint8("tcp80.data_offset", "Data Offset", base.DEC),
    flags = ProtoField.uint8("tcp80.flags", "Flags", base.HEX),
    window = ProtoField.uint16("tcp80.window", "Window Size", base.DEC),
    checksum = ProtoField.uint16("tcp80.checksum", "Checksum", base.HEX),
    urg_ptr = ProtoField.uint16("tcp80.urg_ptr", "Urgent Pointer", base.DEC)
}

tcp_protocol.fields = fields

4.添加解析器

lua 复制代码
function tcp_protocol.dissector(buffer, pinfo, tree)
    -- 检查缓冲区长度是否足够(TCP头部最小20字节)
    local length = buffer:len()
    if length < 20 then 
        return  -- 数据包太小,不是完整的TCP头部
    end
    
    -- 解析TCP头部字段
    local offset = 0
    local src_port = buffer(offset, 2):uint()
    offset = offset + 2
    local dst_port = buffer(offset, 2):uint()
    offset = offset + 2
    
    if src_port ~= 80 and dst_port ~= 80 then
        return  -- 如果不是端口80的流量,不继续解析
    end
    -- 设置协议列显示为TCP80
    pinfo.cols.protocol:set("TCP80")

5.注册新协议到wireshark

lua 复制代码
-- 获取TCP端口解析器表
local tcp_port = DissectorTable.get("tcp.port")

-- 将我们的解析器注册到端口80
-- 当Wireshark遇到TCP端口80的流量时,会调用我们的解析函数
tcp_port:add(80, tcp_protocol)

-- 加载成功提示
print("TCP Port 80 dissector loaded successfully!")
相关推荐
努力努力再努力wz15 小时前
【Lua 进阶系列】从 C++ 对象到 Lua 变量:一文理解 userdata、Lua 栈与元表绑定机制
c++·junit·lua
曾令胜16 小时前
云服务器被攻击后分析恶意脚本修复漏洞
网络安全·安全威胁分析
阿卡好可爱18 小时前
Lua 热更新不生效:改完文件线上仍是旧逻辑,package.loaded 与 upvalue 重绑定详解
数据结构·分布式·后端·架构·lua
Joy T19 小时前
Redis Lua 原子限流:Lua 脚本、竞态条件与并发控制
数据库·redis·lua·限流·竞态条件·redis scripting
菩提小狗1 天前
每日安全情报报告 · 2026-11-09
网络安全·漏洞·cve·安全情报·每日安全
东姬AI2 天前
挖出948个内核漏洞、自动写补丁:GPT-6 Cyber把AI推进“实战岗“,内容行业还卡在哪一关?
人工智能·网络安全·openai·gpt-6
ppo_wu2 天前
解决夸克网盘自动修改PDF打开方式的方法
经验分享·安全·网络安全
hengdonghui2 天前
Writeup 4 Bugku - USB 流量截取
wireshark·ctf·流量分析·misc(杂项)
kingx33 天前
Bugku 逆向 MatrixHunter:黑盒 oracle + GF(2) 消元出唯一解
网络安全·矩阵·逆向·ctf
菩提小狗4 天前
每日安全情报报告 · 2026-11-07
网络安全·漏洞·cve·安全情报·每日安全