如何使用监听器获取TCP流数量?

我正在分析一个非常大的PCAP文件,其中包含许多HTTP事务,其中一些很有趣。我正在使用带有Lua脚本的tshark,从而查询与筛选器匹配的所有数据包。

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("发现我的数据包...现在怎么办?")
        end
        function tap.draw()
        end
    end
    init_listener()
end

关于pinfotvbip是什么的文档不太好理解。

点赞
用户6081776
用户6081776

你可以通过 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

2017-03-09 13:26:23