【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!")
相关推荐
汤愈韬9 小时前
防火墙地址转换技术NAT
网络安全·security·huawei
世界尽头与你10 小时前
CVE-2014-3566: OpenSSL 加密问题漏洞
网络·安全·网络安全·渗透测试
Hacker_Fuchen10 小时前
Postman最被低估的功能,自动化接口测试效率简直无敌
自动化测试·软件测试·自动化·lua·postman
wuletaotao10 小时前
Postman使用教程
测试工具·lua·postman
网安墨雨11 小时前
【软件测试】Postman中变量的使用
自动化测试·软件测试·测试工具·lua·postman
内心如初13 小时前
2025.11.29-威胁情报 | QQ Windows客户端跨站脚本漏洞(QVD-2025-45847)
网络安全·最新威胁情报
T***u33313 小时前
PHP在电商中的会员管理
开发语言·wireshark·php·ue4·jina
white-persist16 小时前
【攻防世界】reverse | IgniteMe 详细题解 WP
c语言·汇编·数据结构·c++·python·算法·网络安全
Whoami!21 小时前
❼⁄₁ ⟦ OSCP ⬖ 研记 ⟧ 查找漏洞的公共利用 ➱ 在线资源
网络安全·信息安全·漏洞利用