【问题标题】:Wireshark lua api: create new heuristic dissectors tableWireshark lua api:创建新的启发式解剖表
【发布时间】:2014-12-25 14:16:35
【问题描述】:

我发现了在 Lua 中使用启发式表的非常有用的示例。 a link 但它不包括我的情况。

我已经在 lua 中编写了自定义解析器。描述的自定义协议有很多子协议。所以我创建了新的 subdissectors 表 DissectorTable.new() 并注册了新的 subprotos。 但有些子协议没有标识号,必须动态找出它们的类型。

我希望用 proto:register_heuristic() 方法注册启发式解析器,但是 DissectorTable.heuristic_list() 列表中没有我的新表。

创建新的解析器表不会创建启发式解析器表。 有没有办法创建新的自己的启发式解剖表?

【问题讨论】:

    标签: lua wireshark


    【解决方案1】:

    在当前的 Lua API 中,无法为您的协议创建真正的启发式剖析表,但我不确定拥有这样的东西是否有意义。让一个协议为自己创建一个启发式解析器表的目的是让其他协议可以将他们的启发式解析器注册到其中 - 例如 UDP 协议创建一个名为“udp”的启发式解析器表,以便其他协议(如 RTP、STUN、 Skype 等都可以将他们的启发式解析器注册到其中,而 UDP 可以在事先不知道它们的情况下尝试所有这些。

    但是当您在 Lua 插件中创建新协议时,没有其他代码会知道您的新协议或您创建的任何启发式解析器表。只有你自己的 Lua 代码会知道它。显然,您的新协议可能具有需要启发式尝试的子协议,正如您似乎需要的那样,但您不需要启发式解析器表来执行此操作 - 只需在 Lua 中直接调用您的子协议的启发式解析器函数即可。

    例如:

    local myProto     = Proto("myproto",     "My Main Protocol")
    local mySubproto1 = Proto("mysubproto1", "My First Sub-Protocol")
    local mySubproto2 = Proto("mysubproto2", "My Second Sub-Protocol")
    
    -- the sub-prpotocol's heuristic function
    -- returns true if the packet is its protocol and it dissected it
    -- otherwise returns false
    function heur_dissect_mySubproto1(tvbuf, pktinfo, root)
        -- see if the passed in tvb is Subproto1 protocol
        -- and if so then add tree items and such or
        -- call mySubproto1's normal dissector function to do that stuff
        return is_Subproto1
    end
    
    function heur_dissect_mySubproto2(tvbuf, pktinfo, root)
        -- see if the passed in tvb is Subproto2 protocol
        return is_Subproto2
    end
    
    function myProto.dissector(tvbuf, pktinfo, root)
        -- do stuff for my main protocol
    
        -- create a new sub-tvb of what has not been processed by the main protocol
        local newTvb = tvbuf(bytes_parsed_by_myproto):tvb()
    
        -- call the heuristic dissector functions of my sub protocols
        -- with the portion of the tvb that belongs to them
        if heur_dissect_mySubproto1(newTvb, pktinfo, root) then
            -- do here anything you need to afterwards
        elseif heur_dissect_mySubproto2(newTvb, pktinfo, root) then
            -- do here anything you need to afterwards
        end
    end
    

    或者,如果您想变得更漂亮,请使用自己的桌子...

    local myProto     = Proto("myproto",     "My Main Protocol")
    local mySubproto1 = Proto("mysubproto1", "My First Sub-Protocol")
    local mySubproto2 = Proto("mysubproto2", "My Second Sub-Protocol")
    
    -- a heuristic dissector table for myProto
    local myProto_heuristic_table = {}
    
    -- a function to register into myProto's heuristic table
    local function register_heuristic(func)
        myProto_heuristic_table[#myProto_heuristic_table + 1] = func
    end
    
    function heur_dissect_mySubproto1(tvbuf, pktinfo, root)
        -- do stuff
        return is_Subproto1
    end
    
    -- "register" the above function
    register_heuristic(heur_dissect_mySubproto1)
    
    function heur_dissect_mySubproto2(tvbuf, pktinfo, root)
        -- do stuff
        return is_Subproto2
    end
    
    register_heuristic(heur_dissect_mySubproto2)
    
    function myProto.dissector(tvbuf, pktinfo, root)
        -- do stuff for my main protocol
    
        local newTvb = tvbuf(bytes_parsed_by_myproto):tvb()
    
        -- call the heuristic dissector functions of my sub protocols
        -- with the portion of the tvb that belongs to them
        for _, func in ipairs(myProto_heuristic_table) do
            -- call the heuristic
            if func(newTvb, pktinfo, root) then
                -- do here anything you need to afterwards
                return
            end
        end
    end
    

    【讨论】:

      猜你喜欢
      • 2012-05-11
      • 2015-05-25
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      • 1970-01-01
      • 2017-03-02
      相关资源
      最近更新 更多