加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在Lua Wireshark解剖器中重新组装数据包

发布时间:2020-12-15 00:17:07 所属栏目:大数据 来源:网络整理
导读:我正在尝试为基于bplists的Safari远程调试协议编写一个解剖器并且已经相当成功(当前代码在这里: https://github.com/andydavies/bplist-dissector). 虽然我在重新组装数据包时遇到了困难. 通常,协议发送一个包含4个字节的数据包,其中包含下一个数据包的长度
我正在尝试为基于bplists的Safari远程调试协议编写一个解剖器并且已经相当成功(当前代码在这里: https://github.com/andydavies/bplist-dissector).

虽然我在重新组装数据包时遇到了困难.

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

不幸的是,来自iOS模拟器的一些数据包不符合此约定,并且四个字节或者标记在bplist数据包的前面,或者标记在前一个bplist数据包的末尾,或者数据是多个bplists.

我尝试使用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字节数据包.

我可以想到在前面管理额外的四个字节的其他方法,但协议包含一个查找表,该数据包从数据包的末尾开始是32个字节,因此需要一种方法将数据包准确地拼接到bplists中.

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

我这样做是对的吗(关于SO的其他问题,以及我似乎在网上的例子)还是有更好的方法?

解决方法

TCP Dissector 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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读