如何在 Wireshark Lua 解析器中访问数据包的 TLS 版本/校验和?

How to access TLS Version/ Checksum of packet in Wireshark Lua dissector?

我是 Wireshark 及其 Lua API 的新手。我需要编写一个解析器,可以捕获端口 443 上的数据包,修改一些内容,然后将它们发送到目的地。我找到了一个脚本here,我根据需要修改了它:

-- create myproto protocol and its fields
p_myproto = Proto ("myproto","My Protocol")
local f_command = ProtoField.uint16("myproto.command", "Command", base.HEX)
local f_data = ProtoField.string("myproto.data", "Data", FT_STRING)
 
p_myproto.fields = {f_command}
 
-- myproto dissector function
function p_myproto.dissector (buf, pkt, root)
    print ('packet captured')
  -- validate packet length is adequate, otherwise quit
  if buf:len() == 0 then return end
  pkt.cols.protocol = p_myproto.name
  local colss = pkt.cols

--pkt.cols.info:append(" " .. tostring(pkt.dst).." -> "..tostring(pkt.src))

print ("" .. tostring(pkt.dst))
print ("" .. tostring(pkt.src_port))
print ("" .. tostring(pkt.dst_port))

end
 
-- Initialization routine
function p_myproto.init()
end
 
-- register a chained dissector for port 8002
local tcp_dissector_table = DissectorTable.get("tcp.port")
dissector = tcp_dissector_table:get_dissector(443)
  -- you can call dissector from function p_myproto.dissector above
  -- so that the previous dissector gets called
tcp_dissector_table:add(443, p_myproto)

我可以访问 dst、src、dst_port 等字段。整个列表都可用 here。但是我无法在任何地方找到任何关于如何 access/modify 数据包校验和、所选密码套件等的参考资料。我知道它们存在于传输层上,但我找不到任何允许我 access/modify 这些值。

我做错了什么?在这方面的任何帮助将不胜感激!

谢谢!

您可以使用 Field Extractor, and the entire list is not available on the LuaAPI/Pinfo wiki page as you referenced, but on the Wireshark Display Filter Reference 页面访问 任何 字段。

例如,如果你想要TCP校验和,你可以使用:

fe_tcp_checksum = Field.new("tcp.checksum")

...

function p_myproto.dissector (buf, pkt, root)
    ...
    f_tcp_checksum = fe_tcp_checksum().value
    ...
end

Wireshark wiki 提供更多 Lua/Examples