Wireshark Lua 解析器 - 如何使用 TAP?

发布于 2025-01-04 15:00:07 字数 1370 浏览 2 评论 0原文

我想在通过我的 lua 解析器解析的自定义协议之上进行一些分析。因此我尝试这样做

myproto_proto = Proto("myproto", "Myproto Protocol")
m_dest = ProtoField.uint16("myproto.dest", "Destination", base.HEX)
m_src = ProtoField.uint16("myproto.src", "Source", base.HEX)
myproto_proto.fields = { sm_dest, sm_src }

dofile(MYPROTO_PROTO_PATH.."parser.lua")

function myproto_proto.dissector(buffer, pinfo, tree)
   pinfo.cols.protocol = "MYPROTO"

   local subtree = tree:add(myproto_proto, buffer(), "Myproto Protocol Data")
   parse_msg(buffer, pinfo, subtree) -- does the actual parsing and sets the fields
end

udp_table = DissectorTable.get("udp.port")
udp_table:add(9000,myproto_proto)

-- LISTENER / TAP

f_test = Field.new("myproto.dest") -- fails because "field does not exist"
local function my_tap()
   local window = TextWindow.new("Myproto Tap")
   local tap = Listener.new(nil, "myproto")

   local counter = 0
   function remove()
      tap:remove()
   end

   window:set_atclose(remove)

   function tap.packet(pinfo, buffer)
      counter = counter + 1
   end

   function tap.draw(t)
      window:append("Counter: \t" .. counter .. "\n")
   end

   function tap.reset()
      window:clear()
      counter = 0
   end
   retap_packets()
end

register_menu("My Tap", my_tap, MENU_TOOLS_UNSORTED)

我的问题是,我无法使用字段提取器访问剖析的数据。那么我还能如何在我的 lua tap 中获取剖析的数据呢?

提前致谢。

I would like to do some analysis on top of my custom protocol that is dissected via my lua dissector. Therefore I tried to do this

myproto_proto = Proto("myproto", "Myproto Protocol")
m_dest = ProtoField.uint16("myproto.dest", "Destination", base.HEX)
m_src = ProtoField.uint16("myproto.src", "Source", base.HEX)
myproto_proto.fields = { sm_dest, sm_src }

dofile(MYPROTO_PROTO_PATH.."parser.lua")

function myproto_proto.dissector(buffer, pinfo, tree)
   pinfo.cols.protocol = "MYPROTO"

   local subtree = tree:add(myproto_proto, buffer(), "Myproto Protocol Data")
   parse_msg(buffer, pinfo, subtree) -- does the actual parsing and sets the fields
end

udp_table = DissectorTable.get("udp.port")
udp_table:add(9000,myproto_proto)

-- LISTENER / TAP

f_test = Field.new("myproto.dest") -- fails because "field does not exist"
local function my_tap()
   local window = TextWindow.new("Myproto Tap")
   local tap = Listener.new(nil, "myproto")

   local counter = 0
   function remove()
      tap:remove()
   end

   window:set_atclose(remove)

   function tap.packet(pinfo, buffer)
      counter = counter + 1
   end

   function tap.draw(t)
      window:append("Counter: \t" .. counter .. "\n")
   end

   function tap.reset()
      window:clear()
      counter = 0
   end
   retap_packets()
end

register_menu("My Tap", my_tap, MENU_TOOLS_UNSORTED)

My problem is, I'm unable to access the dissected data with a field extractor. So how else could I get the dissected data in my lua tap?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘逸的'云 2025-01-11 15:00:07

这是一个已知问题自定义 Lua Field 对象在 OSX 中不可用(它显然适用于 Windows XP,但不适用于 Windows 7)。

有几种方法可以将数据从解析器传递到水龙头。


选项 1:使用共享 Lua 表

  1. 创建一个由数据包编号(来自 pinfo.number,对解析器和 Tap 都可见)作为键控的全局字典。

    -- 我们省略 'local' 关键字以使 'dict' 成为全局变量
    字典 = {}
    
  2. 在解析器中,将数据包数据添加到字典中:

    dict[pinfo.number] = { dest = m_dest, src = m_src }
    
  3. 在您的水龙头中,您可以通过简单的查找来访问数据。

    print('dest', dict[pinfo.number].dest )
    

XXX:需要全局;复制已保存在协议树中的变量的存储(并且应该可以从 Tap 访问)。


选项 2:使用 pinfo.private

这个已添加到开发版本 (1.7.0) 中。它与上面的解决方案类似。 pinfo.private 是一个 PrivateTable,它是一个仅存储字符串的哈希表。

  1. 在解析器中,将数据添加到数据包的私有表中:

    pinfo.private["src"] = tostring(m_src)
    pinfo.private["dest"] = tostring(m_dest)
    
  2. 在点击中,访问 pinfo 对象中的数据:

    print('dest', pinfo.private["dest"] )
    

XXX: 只能存储字符串值


选项 3:重新解析缓冲区

  1. 在您的 Tap 中,调用您的解析器(即,来自parser.lua)重新解析buffer中的数据,并将其传递给tap。

XXX: 重复解剖器已经完成的工作(可以使超大捕获文件的处理时间加倍)

It's a known problem that custom Lua Field objects aren't usable in OSX (it apparently works in Windows XP but not Windows 7).

There are a few ways to pass data from your dissector to your tap.


Option 1: Use a shared Lua table

  1. Create a global dictionary that is keyed by the packet number (from pinfo.number, which is visible to both dissector and tap).

    -- we omit the 'local' keyword to make `dict` a global variable
    dict = {}
    
  2. In your dissector, add the packet data to the dictionary:

    dict[pinfo.number] = { dest = m_dest, src = m_src }
    
  3. In your tap, you can access the data by a simple lookup.

    print('dest', dict[pinfo.number].dest )
    

XXX: Requires a global; Duplicates storage for a variable that is already held in the protocol tree (and should be accessible from the tap).


Option 2: Use pinfo.private

This was added in the dev build (1.7.0). It's similar to the solution above. pinfo.private is a PrivateTable, which is a hash table that stores only strings.

  1. In your dissector, add your data to the packet's private table:

    pinfo.private["src"] = tostring(m_src)
    pinfo.private["dest"] = tostring(m_dest)
    
  2. In your tap, access the data from the pinfo object:

    print('dest', pinfo.private["dest"] )
    

XXX: Can only store string values


Option 3: Reparse the buffer

  1. In your tap, call your parser (i.e., from parser.lua) to reparse the data in buffer, which is passed to the tap.

XXX: Duplicates work already done by dissector (can double processing time for X-large capture files)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文