开源usb sniffer的包文件导入usb packet viewer进行USB协议解析
A佬的抓包器是用wireshark的,整个过程就是,在wireshark导出pcapng数据文件,然后把这个文件导入到usb packet viewer解析。我做的事情只有,增加了一个pcapng的支持脚本。1. 下载usb packet viewer,用github上的scripts文件夹替换掉usbpv文件夹scripts.lua文件。有能力的兄弟们可以支持一下XToolbox大佬,我是穷学生
usb sniffer是指ataradov大佬做的USB硬件抓包器
GitHub - ataradov/usb-sniffer: Low-cost LS/FS/HS USB sniffer with Wireshark interface
usb packet viewer是XToolbox大佬开发用于配套usb packet viewer抓包器的软件
有能力的兄弟们可以支持一下XToolbox大佬,我是穷学生,所以才有了这个文章。
另外想说就是,代码仅供参考,给有需要的兄弟。
直奔主题---------------------------------------------------------------
A佬的抓包器是用wireshark的,整个过程就是,在wireshark导出pcapng数据文件,然后把这个文件导入到usb packet viewer解析。我做的事情只有,增加了一个pcapng的支持脚本。
先看效果(使用的A佬官网的捕获文件):
步骤
1. 下载usb packet viewer,用github上的scripts文件夹替换掉usbpv文件夹scripts.lua文件。
2.在scripts文件夹里增加file_alex_pcapng.lua文件,内容如下:
-- file_pcap.lua
-- encoding: utf-8
require("file_base")
local unpack = string.unpack
local pack = string.pack
local fmt = string.format
local LINKTYPE_20FS_USBLL = 294
local PCAPNG_SHB_TYPE = 0x0A0D0D0A
local PCAPNG_MAGIC = 0x1A2B3C4D
local PCAP_NANO_MAGIC = 0xa1b23c4d
local DLT_USBLL = 288
local alex_pcapng_handler = {
name = "alex_pcapng",
description = "opensouce sniffer pcapng file",
extension = "*.pcapng",
init_read = function(self, file)
local header = file:read(12)
if not header then return false end
if #header ~= 12 then return false end
local shb_type = unpack("I4", header)
local magic = unpack("I4", header, 9)
if magic == PCAPNG_MAGIC and shb_type == PCAPNG_SHB_TYPE then
file:seek("set", 200) --The value of 200 is obtained by observing the output pcapng file
return true
end
return false
end,
read_packet = function(self, file)
local t = file:read(28)
if not t then return nil end
if #t < 20 then return nil end
local epb_type, block_len, idb_id, ts, nano, act_len, org_len = unpack("I4I4I4I4I4I4I4", t)
if epb_type ~= 0x00000006 then return nil end
local pkt = file:read(act_len)
if not pkt then return nil end
if #pkt ~= act_len then return nil end
file:seek("cur", block_len-28-act_len)
return ts, nano, pkt, 0
end
}
register_file_handler(alex_pcapng_handler)
package.loaded["file_alex_pcapng"] = "file_alex_pcapng"
3.在init.lua文件增加
require("file_alex_pcapng")
懒得弄的兄弟们可以直接拿,附上下载链接

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐
所有评论(0)