http - 如何找出数据包的 HTTP header 长度?

标签 http wireshark netmon

我知道如何手动完成(通过查看十六进制转储)。我怎样才能自动获得相同的?我必须使用 API 吗?我有 wireshark 和 Microsoft 网络监视器。

最佳答案

这可以简单地通过 Lua dissector 来实现将 HTTP header 字段添加到数据包树中,允许您对其进行过滤,如以下屏幕截图所示:

enter image description here

将此 Lua 脚本复制到您的插件目录(例如,${WIRESHARK_HOME}/plugins/1.4.6/http_extra.lua),然后重新启动 Wireshark(如果已经运行)。

do
        local http_wrapper_proto = Proto("http_extra", "Extra analysis of the HTTP protocol");
        http_wrapper_proto.fields.hdr_len = ProtoField.uint32("http.hdr_len", "Header length (bytes)")

        -- HTTP frames that contain a header usually include the HTTP
        -- request method or HTTP response code, so declare those here
        -- so we can check for them later in the dissector.
        local f_req_meth    = Field.new("http.request.method")
        local f_resp_code   = Field.new("http.response.code")

        local original_http_dissector
        function http_wrapper_proto.dissector(tvbuffer, pinfo, treeitem)
                -- We've replaced the original http dissector in the dissector table,
                -- but we still want the original to run, especially because we need 
                -- to read its data. Let's wrap the call in a pcall in order to catch
                -- any unhandled exceptions. We'll ignore those errors.
                pcall(
                    function()
                        original_http_dissector:call(tvbuffer, pinfo, treeitem)
                    end
                )

                -- if the request method or response code is present,
                -- the header must be in this frame
                if f_req_meth() or f_resp_code() then

                        -- find the position of the header terminator (two new lines),
                        -- which indicates the length of the HTTP header, and then add
                        -- the field to the tree (allowing us to filter for it)
                        local hdr_str = tvbuffer():string()
                        local hdr_len = string.find(hdr_str, "\r\n\r\n") or string.find(hdr_str, "\n\n\n\n")
                        if hdr_len ~= nil then
                            treeitem:add(http_wrapper_proto.fields.hdr_len, hdr_len):set_generated()
                        end
                end
        end

        local tcp_dissector_table = DissectorTable.get("tcp.port")
        original_http_dissector = tcp_dissector_table:get_dissector(80) -- save the original dissector so we can still get to it
        tcp_dissector_table:add(80, http_wrapper_proto)                 -- and take its place in the dissector table
end

关于http - 如何找出数据包的 HTTP header 长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5705435/

相关文章:

wireshark - 在 Wireshark 中统计数据包

python - 使用 Python 解析 .pcap 文件中的 SSL 流量

java 如何在十六进制转换中转义无法识别的字符

sql-server - 如果 channel 受 SSL 保护,为什么会显示 tcp?

java - 如何获取准确的请求(路径/参数)以便能够重定向回同一位置

http - 榆树 0.19 : How to obtain request body when receiving BadStatus with elm/http 2. 0.0

java - 将 HTTP 请求重定向到不同的服务器

java - 具有网络操作的 Asynctask 和另一个 Asynctask 任务问题