【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!")
相关推荐
网安INF16 小时前
SSL/TLS密钥派生机制与安全攻防体系深度解析
网络·安全·网络安全·密码学·ssl
一岁天才饺子18 小时前
Redis漏洞复现
redis·web安全·网络安全
脆皮瞎19 小时前
内网横向移动 ?
网络安全·php·内网穿透
网安_秋刀鱼21 小时前
【java安全】shiro反序列化1(shiro550)
java·开发语言·安全·web安全·网络安全·1024程序员节
世界尽头与你21 小时前
CVE-2022-21697_ Jupyter Server 代码问题漏洞
网络安全·jupyter·渗透测试
阿恩.7701 天前
材料工程科技期刊征稿:快速发表,知网、维普检索!
经验分享·笔记·考研·网络安全·数学建模·能源·制造
zfj3211 天前
“昨晚快手被黑直播平台出现大量违规内容“技术解析
网络·网络安全·系统防护
_庄@雅@丽1 天前
(抓包测试)第一篇:测试全攻略,从 HTTP 到 HTTPS,从新手到高阶测试(必看)
fiddler·wireshark·burp·reqable·抓包测试·https 抓包·http 原理
中科固源1 天前
Wisdom Lens:基于智能体的自动化漏洞挖掘系统
安全·网络安全·模糊测试·智能体
网安INF1 天前
SSL/TLS协议深度解析:记录、警报与握手
网络·网络协议·安全·网络安全·密码学·ssl