如何使用侦听器获取TCP流号?



我正在分析一个非常大的PCAP,其中包含许多HTTP事务,其中一些我很感兴趣。我将tshark与Lua脚本一起使用,本质上是查询与过滤器匹配的所有数据包。

tshark -X lua_script:filter.lua -r some.pcap  -q

目前为止,一切都好。但是,我正在专门寻找数据包的TCP流编号的值,该值在Wireshark中名为tcp.stream。谁能说我需要什么更改才能filter.lua打印它?

-- filter.lua
do
local function init_listener()
local tap = Listener.new("http","http contains someKeyValue && tcp.port eq 1234")
function tap.reset()
end
function tap.packet(pinfo,tvb,ip)
print("Found my packet ... now what?")
end
function tap.draw()
end
end
init_listener()
end

关于pinfotvbip的文件尚未公布。

您可以通过Field访问 TCP 流编号。

local tcp_stream = Field.new("tcp.stream").value

Field的值是当前数据包的值。您无需每次都创建新Field。这允许您使Field成为常量,并创建一个返回当前数据包的 TCP 流编号的函数。也可以调用Field值来获取可能包含其他有用信息的FieldInfo值。

您希望filter.lua如下所示:

-- filter.lua
do
local function init_listener()
local get_tcp_stream = Field.new("tcp.stream")
local tap = Listener.new("http","http contains someKeyValue && tcp.port eq 1234")
function tap.reset()
end
function tap.packet(pinfo,tvb,ip)
print(tostring(get_tcp_stream()))
end
function tap.draw()
end
end
init_listener()
end

https://www.wireshark.org/docs/wsdg_html_chunked/lua_module_Field.html#lua_class_Field

最新更新