我正在尝试编写一个 lua Proto 来解析我们在 http 上的私有协议。但是当 media_type 为“application/octet-stream”时,Wireshark 没有进入我的解析器函数。当 media_type 设置为“text/html”时,一切看起来都很好。对应用程序/八位字节流有特殊处理吗?搞了快一天了,能帮帮我吗?多谢
我的wireshark版本是mac osx 10.8.5上的1.10.2
这是我的代码
do
local myproto= Proto("myprotoProtocol","myproto Protocol")
local f_version= ProtoField.uint32("Version","Version",base.DEC)
myproto.fields = {f_version}
local data_dis = Dissector.get("data")
local function myproto_dissector(tvb,pkt,root)
print("enter myproto_dissector, tvb.len:"..tostring(tvb:len()))
if tvb:len() < 17 then return false end
pkt.cols.protocol = "myproto"
local t =root:add(myproto,tvb)
t:add(f_version,tvb(0,2))
local version = tvb(0,2).uint()
print("version:"..tostring(version))
return true
end
function myproto.dissector(tvb,pkt,root)
print("enter myproto.dissector")
if not myproto_dissector(tvb,pkt,root) then
data_dis:call(tvb,pkt,root)
end
end
local tbl= DissectorTable.get("media_type")
tbl:add("application/octet-stream",myproto)
--tbl:add("text/html",myproto) --text/html looks fine
print("adding myproto into DissectorTable")
end
我使用 tshark 调试 application/octet-stream
$tshark -r test.pcapng |grep application/octet-stream
108 40.536817000 10.8.0.14 -> 10.130.142.72 HTTP 418 POST /protocol?uid=101225&uid=101225&_t=1382115502 HTTP/1.1 (application/octet-stream)
111 40.596037000 10.130.142.72 -> 10.8.0.14 HTTP 63 HTTP/1.1 200 OK (application/octet-stream)
120 40.657143000 10.8.0.14 -> 10.130.142.72 HTTP 445 POST /protocol?uid=101225&uid=101225&_t=1382115502 HTTP/1.1 (application/octet-stream)
124 40.729645000 10.130.142.72 -> 10.8.0.14 HTTP 63 HTTP/1.1 200 OK (application/octet-stream)
219 41.810493000 10.8.0.14 -> 10.130.142.72 HTTP 488 POST /protocol?uid=101225&uid=101225&_t=1382115503 HTTP/1.1 (application/octet-stream)
226 41.919401000 10.130.142.72 -> 10.8.0.14 HTTP 63 HTTP/1.1 200 OK (application/octet-stream)
$tshark -r test.pcapng -X lua_script:canon.lua | grep myproto
adding myproto into DissectorTable
对于文本/html
$tshark -r test.pcapng -X lua_script:canon.lua | grep myproto
adding myproto into DissectorTable
enter myproto.dissector
enter myproto_dissector, tvb.len:2
enter myproto.dissector
enter myproto_dissector, tvb.len:6
enter myproto.dissector
enter myproto_dissector, tvb.len:6
当解析器表中没有列出 media_type 时,可能是wireshark的错误。'application/octet-stream' 尚未列在表中。在 Wireshark 中使用 Lua->evaluate 后,解析器表显示我的协议是这样的,'application/octet-stream' 在混乱代码中。
当我在 tshark 中使用 'print(tbl:get_dissector("application/octet-stream"))' 时,它会显示 "MYPROTO"。看起来是正确的。