gpt4 book ai didi

lua - 在 Lua Wireshark Dissector 中重新组装数据包

转载 作者:行者123 更新时间:2023-12-04 12:22:41 25 4
gpt4 key购买 nike

我正在尝试为基于 bplist 的 Safari 远程调试协议(protocol)编写一个解析器,并且相当成功(当前代码在这里:https://github.com/andydavies/bplist-dissector)。

不过,我在重新组装数据包时遇到了困难。

通常,协议(protocol)会发送一个包含 4 个字节的数据包,其中包含下一个数据包的长度,然后是包含 bplist 的数据包。

不幸的是,来自 iOS 模拟器的一些数据包不遵循此约定,这四个字节要么被标记到 bplist 数据包的前面,要么被标记到前一个 bplist 数据包的末尾,或者数据是多个 bplist。

我尝试使用 desegment_len 重新组装它们和 desegment_offset如下:

  function p_bplist.dissector(buf, pkt, root)  

-- length of data packet
local dataPacketLength = tonumber(buf(0, 4):uint())
local desiredPacketLength = dataPacketLength + 4

-- if not enough data indicate how much more we need
if desiredPacketLen > buf:len() then
pkt.desegment_len = dataPacketLength
pkt.desegment_offset = 0
return
end

-- have more than needed so set offset for next dissection
if buf:len() > desiredPacketLength then
pkt.desegment_len = DESEGMENT_ONE_MORE_SEGMENT
pkt.desegment_offset = desiredPacketLength
end

-- copy data needed
buffer = buf:range(4, dataPacketLen)

...

我在这里尝试做的总是强制将大小字节作为要剖析的数据包的前四个字节,但它不起作用我仍然看到一个 4 字节的数据包,然后是一个 x 字节的数据包。

我可以想到其他管理前面额外四个字节的方法,但是该协议(protocol)包含一个查找表,该表距数据包末尾 32 个字节,因此需要一种将数据包准确拼接到 bplist 中的方法。

这是一个示例上限: http://www.cloudshark.org/captures/2a826ee6045b #338 是一个数据包的示例,其中 bplist 大小位于数据的开头,并且数据中有多个 plist。

我这样做是否正确(查看其他关于 SO 的问题,以及我似乎在网络上的示例)还是有更好的方法?

最佳答案

TCP 解析器 packet-tcp.c有 tcp_dissect_pdus(),它

Loop for dissecting PDUs within a TCP stream; assumes that a PDU consists of a fixed-length chunk of data that contains enough information to determine the length of the PDU, followed by rest of the PDU.



lua api 中没有这样的功能,但它是一个很好的例子。

再举一个例子。一年前我用它进行测试:
local slicer = Proto("slicer","Slicer")
function slicer.dissector(tvb, pinfo, tree)
local offset = pinfo.desegment_offset or 0

local len = get_len() -- for tests i used a constant, but can be taken from tvb

while true do
local nxtpdu = offset + len

if nxtpdu > tvb:len() then
pinfo.desegment_len = nxtpdu - tvb:len()
pinfo.desegment_offset = offset
return
end

tree:add(slicer, tvb(offset, len))

offset = nxtpdu

if nxtpdu == tvb:len() then
return
end
end
end
local tcp_table = DissectorTable.get("tcp.port")
tcp_table:add(2506, slicer)

关于lua - 在 Lua Wireshark Dissector 中重新组装数据包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14387426/

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