Wireshark的一些使用经验

在Wireshark可以使用wireshark支持的lua语言进行定制或扩充。
注:本文所测试脚本以Wireshar2.0.4为准
#
工作中经常会遇到需要将某些UDP报文固定解析为RTP协议,这个操作通过在init.lua中扩充分析器
local rtp_dissector  = Dissector.get("rtp")
DissectorTable.get("udp.port"):add(40002,rtp_dissector)
 
对于某些优先生效的解析协议,需要通过wireshar首选项里面的协议配置进行修改,以避免此段配置脚本不生效
 
如果固定将rtp协议中某些payload解析为某些协议,则可以进一步扩充DissectorTable.get("rtp.pt")
 
#监听器listner
在wireshark的帮助文档里面有如何使用lua写一个监听器的模板。监听器可以根据过滤报文采取某些动作。例如,将需要将报文流,写入到文件中,则可以依据此模板文件进行扩充
 
-- This program will register a menu that will open a window with a count of occurrences
-- of every address in the capture

local function menuable_tap()
        -- Declare the window we will use
        local tw = TextWindow.new("Address Counter")

        -- This will contain a hash of counters of appearances of a certain address
        local ips = {}

        --customized get the input filter content.取得和过滤显示报文一样的条件,以适应变化
        local filter = "rtp"
	if string.len(get_filter()) > 0 then   
	     filter  = get_filter()
	end  
 
        -- for get field info from each packet
      local udp_data  = Field.new("udp")
        -- this is our tap
        local tap = Listener.new("ip",filter);

        function remove()
                -- this way we remove the listener that otherwise will remain running indefinitely
                tap:remove();
        end

        -- we tell the window to call the remove() function when closed
        tw:set_atclose(remove)

        -- this function will be called once for each packet
        function tap.packet(pinfo,tvb)
                local src = ips[tostring(pinfo.src)] or 0
                local dst = ips[tostring(pinfo.dst)] or 0

                ips[tostring(pinfo.src)] = src + 1
                ips[tostring(pinfo.dst)] = dst + 1
                
                --customized each packet to write,get field data pinfo是包的一些信息 tvb是报文数据信息.获得udp信息域获得一些基础偏移量,以利于计算
		local udpFieldInfo      = udp_data() 
                local offset         = udpFieldInfo.offset
                --根据应用协议所需要的偏移进行偏移计算,以取到相应的数据
                local wirte_content      = tvb:raw(offset)            
                --根据某些规则写入
        end

        -- this function will be called once every few seconds to update our window
        function tap.draw(t)
                tw:clear()
                for ip,num in pairs(ips) do
                        tw:append(ip .. "\t" .. num .. "\n");
                end
        end

        -- this function will be called whenever a reset is needed
        -- e.g. when reloading the capture file
        function tap.reset()
                tw:clear()
                ips = {}
        end
end

-- using this function we register our function
-- to be called when the user selects the Tools->Test->Packets menu
register_menu("Test/Packets", menuable_tap, MENU_TOOLS_UNSORTED)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值