每次我跟精英说:糟了,Fiddler抓不到包,怎么办?
精英总是狠狠地吸了一口烟,再慢慢地吐出来:用Wireshark !!!
我很迷茫:什么是Wireshark ?
精英的脸隐藏在烟雾之后,悠悠的说:神器一样存在的东西。
于是开始接触Wireshark的一些功能,深深的被它的强大所折服,不得不写一篇博客来纪念一下。
Wireshark(前称Ethereal)是一个网络封包分析软件。网络封包分析软件的功能是撷取网络封包,并尽可能显示出最为详细的网络封包资料。Wireshark使用WinPCAP作为接口,直接与网卡进行数据报文交换。
目前我们所用的到两个重要的功能是:
第一,过滤数据包,只显示自己感兴趣的数据包进行查看,这样就会非常有利于排除干扰,顺利推图。
目前我所知道的过滤的规则如下:
1.过滤IP,如来源IP或者目标IP等于某个IP
例子:
ip.src eq 192.168.1.107 or ip.dst eq 192.168.1.107
或者
ip.addr eq 192.168.1.107 // 都能显示来源IP和目标IP
2.过滤端口
例子:
tcp.port eq 80 // 不管端口是来源的还是目标的都显示
tcp.port == 80
tcp.port eq 2722
tcp.port eq 80 or udp.port eq 80
tcp.dstport == 80 // 只显tcp协议的目标端口80
tcp.srcport == 80 // 只显tcp协议的来源端口80
udp.port eq 15000
过滤端口范围
tcp.port >= 1 and tcp.port <= 80
5.包长度过滤
例子:
udp.length == 26 这个长度是指udp本身固定长度8加上udp下面那块数据包之和
tcp.len >= 7 指的是ip数据包(tcp下面那块数据),不包括tcp本身
ip.len == 94 除了以太网头固定长度14,其它都算是ip.len,即从ip本身到最后
frame.len == 119 整个数据包长度,从eth开始到最后
eth —> ip or arp —> tcp or udp —> data
7.TCP参数过滤
tcp.flags 显示包含TCP标志的封包。
tcp.flags.syn == 0x02 显示包含TCP SYN标志的封包。
tcp.window_size == 0 && tcp.flags.reset != 1
8.包内容过滤
-----------------------------------------------
tcp[20]表示从20开始,取1个字符
tcp[20:]表示从20开始,取1个字符以上
第二,插件,插件可以让我们在上面做二次开发,尤其是可以显示游戏中的包的名字,这对推图非常的有利
do
cmds = {}
--[[
Proto.new(name, desc)
name: displayed in the column of “Protocol” in the packet list
desc: displayed as the dissection tree root in the packet details
--]]
local Hero = Proto("Hero", "Hero Packet")
--[[
ProtoField:
to be used when adding items to the dissection tree
--]]
--[[
(1)BH Packet Header
--]]
local f_bh_packlen = ProtoField.uint32("BH.PacketLen", "Length", base.DEC)
-- rtp over http interleaved channel(1 byte)
local f_bh_cmd = ProtoField.string("BH.Cmd", "CMD", base.DEC)
local f_bh_cmd_string = ProtoField.string("BH.CmdString", "CMD String", base.DEC)
-- define the fields table of this dissector(as a protoField array)
Hero.fields = {f_bh_packlen, f_bh_cmd, f_bh_cmd_string}
--[[
Data Section
--]]
local data_dis = Dissector.get("data")
function string2hex (s)
local hex = ""
for i=1, #s, 1 do
hex = hex .. string.format("%x", s:byte(i))
end
return hex
end
--[[
bh Dissector Function
--]]
local function bh_dissector(buf, pkt, root)
-- check buffer length
local buf_len = buf:len()
--[[
packet list columns
--]]
pkt.cols.protocol = "Hero"
pkt.cols.info = "Hero Packet"
--[[
dissection tree in packet details
--]]
-- tree root
local t = root:add(Hero, buf(0,buf:len()))
--local header = t:add(f_bh_cmd, buf(0,buf:len()))
-- child items
-- bh Header
local packlen = buf(0,4):uint()
pkt.cols.info = cmds[buf(4,4):uint()]
--data:add("content:", string2hex(buf(38, buf:len()-38)))
return true
end
--[[
Dissect Process
--]]
function Hero.dissector(buf, pkt, root)
if bh_dissector(buf, pkt, root)
then
-- valid bh diagram
else
data_dis:call(buf, pkt, root)
end
end
--[[
Specify Protocol Port
--]]
local tcp_encap_table = DissectorTable.get("tcp.port")
tcp_encap_table:add(11324, Hero)
tcp_encap_table:add(11311, Hero)
end
1. 找到wireshark 安装目录
2. 打开 init.lua (D:\Program Files\Wireshark\init.lua),用 — 注释disable_lua或者改为disable_lua=false。这样 wireshark 就会支持 Lua 了
-- Set disable_lua to true to disable Lua support.
disable_lua = false
if disable_lua then
return
end
3. 在 init.lua 结尾,添加 dofile(”1.lua”) ,wireshark 在每次启动时会自动载入1.lua