gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 15:11:25 27 4
gpt4 key购买 nike

我知道如何手动完成(通过查看十六进制转储)。我怎样才能自动获得相同的?我必须使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com