GOIM协议的Wireshark插件

最近接手新项目中的消息模块,使用了GoIM作为服务器。为了方便调试,写了这个GoIM协议的Wireshark插件。

安装后抓包效果如下图:

安装

只需拷贝 goim.lua to Wireshark 插件文件夹 ~/.config/wireshark/plugins/ 然后启动就可以了。
默认监听8071端口,可以根据你的需要,修改即可。

-- 可以修改这里的端口
tcp_encap_table:add(8071, go_proto)

源码

代码量非常小,直接上代码。

也可以到这里下载:
Github地址:goim-dissector

do
  -- GOIM Protocol
  local op_codes = {
    [0] = "OP_HANDSHAKE",
    [1] = "OP_HANDSHAKE_REPLY",
    [2] = "OP_HEARTBEAT",
    [3] = "OP_HEARTBEAT_REPLY",
    [4] = "OP_SEND_SMS",
    [5] = "OP_SEND_SMS_REPLY",
    [7] = "OP_AUTH",
    [8] = "OP_AUTH_REPLY",
   
    -- 私有OP。根据可以根据业务定制修改意义
    [100] = "OP_REPORT_VIEW_ID",
    [101] = "OP_REPORT_VIEW_ID_REPLY",
    [102] = "OP_CLIENT_CMD",
    [103] = "OP_CLIENT_CMD_REPLY"}

  local go_proto = Proto("GOIM-Bin", "GO IM Binary Protocol.");

  local p_len = ProtoField.uint32("Goim.length", "Package Length", base.DEC)
  local p_header_len = ProtoField.uint16("Goim.header_len", "Header Length", base.DEC)
  local p_version = ProtoField.uint16("Goim.version", "Version", base.DEC)
  local p_op = ProtoField.uint32("Goim.op", "Operation", base.DEC, op_codes)
  local p_seq = ProtoField.uint32("Goim.squence", "Sequence", base.DEC)
  local p_payload = ProtoField.string("Goim.payload","Payload")

  go_proto.fields = {p_len, p_header_len, p_version, p_op, p_seq, p_payload}


  -- 协议分析函数
  function go_proto.dissector(buf, pkt, root)
    -- 是否可以解析package_length
    local buf_len = buf:len();
    if buf_len < 4 then return false end

    -- 是否包是否完整
    local package_length = buf(0, 4):uint();
    if package_length < buf:len() then return false end

    local t = root:add(proto, buf(0,package_length), "GoIM Binary")
    pkt.cols.protocol = "GOIM"
    pkt.cols.info = "seq="..buf(12,4):uint()..", op=" .. op_codes[buf(8,4):uint()]

    -- 协议解析
    t:add(p_len, buf(0,4))
    t:add(p_header_len, buf(4,2))
    t:add(p_version, buf(6,2))
    t:add(p_op, buf(8,4))
    t:add(p_seq, buf(12,4))
    t:add(p_payload, buf(16, package_length - 16))

    return true
  end

  -- 注册协议
  local tcp_encap_table = DissectorTable.get("tcp.port")
  tcp_encap_table:add(8071, go_proto)
end

扩展阅读:
https://www.wireshark.org/docs/wsdg_html_chunked/index.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,923评论 18 139
  • 标签(空格分隔): Wireshark Lua 参考:http://yoursunny.com/t/2008/Wi...
    natsumi阅读 24,905评论 1 15
  • 2.1. 介绍 2.2. 获取源代码和二进制发行版 2.3. 在Windows下安装Wireshark 2.3.1...
    wwyyzz阅读 2,407评论 0 8
  • 有点懒得把图片传上来了,请移步这里看 Cocos官方论坛-wiki CocoaChina论坛帖子 上面两个是一样的...
    椒盐老蛏阅读 5,353评论 1 6
  • 文/临枝 清晨,我悄悄打开一页思绪 带着最初的憧憬 又一次对着时光,把爱恋轻许 河畔,总是在变幻相同的痕迹 拾起羞...
    摆渡人memory阅读 296评论 2 3