使用Wireshark捕获数据帧和IP数据包教程

来源:互联网 发布:php is numeric 编辑:程序博客网 时间:2024/06/08 01:33
使用Wireshark捕获数据帧和IP数据包教程
2007-04-02 10:39

About Wireshark

  Wireshark is one of the world's foremost network protocol analyzers, and is the standard in many parts of the industry.

   It is the continuation of a project that started in 1998. Hundreds of developers around the world have contributed to it, and it it still under active development.

   Wireshark's powerful features make it the tool of choice for network troubleshooting, protocol development, and education worldwide.

   Wireshark was written by an international group of networking experts, and is an example of the power of open source. It runs on Windows, Linux, UNIX, and other platforms.

Features
Wireshark has a rich feature set which includes the following:
  • Standard three-pane packet browser
  • Multi-platform: Runs on Windows, Linux, OS X, Solaris, FreeBSD, NetBSD, and many others
  • Multi-interface: Along with a standard GUI, Wireshark includes TShark, a text-mode analyzer which is useful for remote capture, analysis, and scripting
  • The most powerful display filters in the industry
  • VoIP analysis
  • Live capture and offline analysis are supported
  • Read/write many different capture file formats: tcpdump (libpcap), NAI's Sniffer™ (compressed and uncompressed), Sniffer™ Pro, NetXray™, Sun snoop and atmsnoop, Shomiti/Finisar Surveyor, AIX's iptrace, Microsoft's Network Monitor, Novell's LANalyzer, RADCOM's WAN/LAN Analyzer, HP-UX nettl, i4btrace from the ISDN4BSD project, Cisco Secure IDS iplog, the pppd log (pppdump-format), the AG Group's/WildPacket's EtherPeek/TokenPeek/AiroPeek, Visual Networks' Visual UpTime and many others
  • Capture files compressed with gzip can be decompressed on the fly
  • Hundreds of protocols are supported, with more being added all the time
  • Coloring rules can be applied to the packet list, which eases analysis
  打开Wireshark的界面如下图:
  
  单击工具栏中左边第一个按钮,弹出如下图的窗口:
  
  选择NDIS5.0 driver,点击Start起动Wireshark,界面如下图所示:
  现在我们就可以捕获网络上的数据帧了。现在我们可以做如下操作:
(一)运行->cmd->ping swfc.edu.cn
(二)用IE打开网页:http://cs2.swfc.edu.cn  
(三)登录一个FTP服务器
      
   至此,可以点Stop按钮停止Wireshark的抓捕工作。得到如下图所示的结束,刚才被捕获的数据帧全部在这了。。。
  
  以下来分析数据帧和数据包
  捕 获的数据含义如下:第一列是捕获数据的编号;第二列是捕获数据的相对时间,从开始捕获算为0.000秒;第三列是源地址,第四列是目的地址;第五列是协议 信息;第六列是数据包的信息。为了避免因操作失误导致数据丢失,我们可以先将捕获的数据保存起来(选择file->save命令)。
  以太网的帧格式:
  ARP协议封装在以太网中的格式:
  分析ARP封装在以太网数据帧中
  在下图中Filter后面的编辑框中输入:arp(注意是小写),然后回车或者点击“Apply”按钮。如下图:
  现在只有ARP协议了。其他的协议数据包都被过滤掉了。选中一个数据帧,然后从整体上Wireshark的窗口,主要被分成三部分:上面部分是所有数据帧的列表;中间部分是数据帧的描述信息;下面部分是帧里面的数据。
  中间部分的三行前面都有一个“+”,点击它,这一行就会被展开。现在展开第一行。看到的结果如下:
  在上图中我们看到这个帧的一些基本信息:
          帧的编号:336(捕获时的编号)
帧的大小:60字节。(以太网的帧最小64个字节,而这里只有60个字节,应该是没有把四个字节的CRC计算在里面,加上它就刚好。)
帧被捕获的日期和时间:NOV   30,2006……
帧距离前一个帧的捕获时间差:0.13469……
帧距离第一个帧的捕获时间差:79.8821……
帧装载的协议:ARP
  
  下面看第二行:
  在上图中,我们在上面一栏每选到一部分,在下面一栏就会显示对应的数据部分。我们可以看到:
目的地址(Destination):ff:ff:ff:ff:ff:ff (这是个MAC地址,这个MAC地址是一个广播地址,就是局域网中的所有计算机都会接收这个数据帧)
源地址(Source):Draytek_31:54:ab (00:50:7f:31:54:ab),那么我们知道,00:50:7f是以太网网卡厂商Draytek拥有的一个以太网地址块。
帧中封装的协议类型:0x0806,(这个是ARP协议的类型编号。)
Trailer:是协议中填充的数据,为了保证帧最少有64字节。
接下来展开第三行,结果如下:
  在上图中,我们可以看到如下信息:
   硬件类型(Hardware type):Ethernet(0X0001)
   协议类型(Protocol type): IP(0X0800)
   硬件信息在帧中占的字节数(Hardware size):6
   协议信息在帧中占的字节数(Protocol size):4
   操作码(opcode):requset(0X0001)
   发送方的MAC地址(Sender MAC address):Draytek_31:54:ab (00:50:7f:31:54:ab)
   发送方的IP地址(Sender IP address):192.168.128.1(192.168.128.1)
   目标的MAC地址(Sender MAC address):Draytek_31:54:ab (00:50:7f:31:54:ab)
   目标的IP地址(Sender IP address):192.168.128.1(192.168.128.1)
  类似的,我们也可以看FTP及HTTP封装在以太网数据帧中。(见下面的图示)仔细看一看,居然能在数据帧里看到你登录FTP服务器的用户名和密码(jkxjxxz swfcxs)。原来,这个也是窃取密码的一个途径!(现在你知道你的QQ密码为什么会丢失了吧?!)。
图: FTP封装在以太网数据帧中