查看完整版本: [轉貼]FortiGate 用Sniffer 命令抓包分析

chun 2013-9-27 14:47

[轉貼]FortiGate 用Sniffer 命令抓包分析

<a href="http://support.fortinet.com.cn/index.php?m=content&amp;c=index&amp;a=show&amp;catid=27&amp;id=168">http://support.fortinet.com.cn/index.php?m=content&amp;c=index&amp;a=show&amp;catid=27&amp;id=168</a><div><p align="left" style="padding-top: 8px; padding-bottom: 8px; line-height: 23px; text-align: justify; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">说明:<br>本文档针对FortiGate 产品的后台抓包命令使用进行说明,相关详细命令参照<br>相关手册。<br>在使用后台抓包分析命令时,建议大家使用如SecureCRT 这样的远程管理工<br>具,通过telnet 或者ssh 的方式登陆到网关,由于UTM 本身不支持将抓包的结<br>果保存在设备自身的存储空间,因此需要借助SecureCRT 这样远程管理工具接收<br>文件。</p><h1 style="margin-bottom: 6px; padding-top: 16px; padding-bottom: 8px; font-size: 26px; line-height: 30px; font-family: 宋体, arial; text-align: center; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(229, 229, 229); background-color: rgb(238, 238, 238);">1.基本命令</h1><p align="left" style="padding-top: 8px; padding-bottom: 8px; line-height: 23px; text-align: justify; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">命令: diagnose sniffer packet.<br># diag sniffer packet &lt;interface&gt; &lt;'filter'&gt; &lt;verbose&gt; &lt;count&gt;</p><h1 style="margin-bottom: 6px; padding-top: 16px; padding-bottom: 8px; font-size: 26px; line-height: 30px; font-family: 宋体, arial; text-align: center; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(229, 229, 229); background-color: rgb(238, 238, 238);">2.参数说明</h1><h2 style="font-size: 26px; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">2.1 interface</h2><p align="left" style="padding-top: 8px; padding-bottom: 8px; line-height: 23px; text-align: justify; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">&lt;interface&gt; 指定实际的接口名称,可以是真实的物理接口名称,也可以是<br>VLAN 的逻辑接口名称,当使用“any”关键字时,表示抓全部接口的数据包。<br>例:<br>#diag sniffer packet port1 //表示抓物理接口为port1 的所有数据包<br>#diag sniffer packet any //表示抓所有接口的所有数据包<br>#diag sniffer packet port1-v10 //当在物理接口建立一个VLAN 子接口,其逻辑<br>接口名为port1-v10,此时表示抓port1-v10 接口的所有数据包,此处一定注意一个问题,<br>由于抓包命令中的空格使用来区分参数字段的,但是在逻辑接口创建时,接口名称支持空<br>格,考虑到今后抓包分析的方便,建议在创建逻辑接口时不要带有空格。</p><h2 style="font-size: 26px; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">2.2 verbose</h2><p align="left" style="padding-top: 8px; padding-bottom: 8px; line-height: 23px; text-align: justify; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">&lt;verbose&gt; 指控制抓取数据包的内容<br>1: print header of packets, //只抓取IP的原地址、源端口、目的地址、目的端口和数据包<br>的Sequence numbers 为系统缺省设置<br>2: print header and data from ip of packets, //抓取IP数据包的详细信息,包括IP数据的<br>payload。<br>3: print header and data from ethernet of packets) ,//抓取IP数据包的详细信息,包<br>括IP数据的payload,导出到文本文件可以使有专用的转换工具,转换为Ethereal支持文件<br>格式<br>例:<br>【例1】 抓所有接口(interface=any)的任何数据包(filter=none),级别1<br>(verbose=1)<br>FG-UTM # dia sni pa any none 1<br>interfaces=[any]<br>filters=[none]<br>nr=2048,fr=1584,b_nr=1024,pg=4096<br>3.710103 127.0.0.1.1029 -&gt; 127.0.0.1.53: udp 40<br>【例2】 抓所有接口(interface=any)的任何数据包(filter=none),级别2<br>(verbose=2),会显示数据包的payload信息。<br># diag sniffer packet internal none 2 1<br>192.168.0.1.22 -&gt; 192.168.0.30.1144: psh 2867817048 ack 1951061933<br>0x0000 4510 005c 8eb1 4000 4006 2a6b c0a8 0001 E..\..@.@.*k....<br>0x0010 c0a8 001e 0016 0478 aaef 6a58 744a d7ad .......x..jXtJ..<br>0x0020 5018 0b5c 8ab9 0000 9819 880b f465 62a8 P..\.........eb.<br>0x0030 3eaf 3804 3fee 2555 8deb 24da dd0d c684 &gt;.8.?.%U..$.....<br>0x0040 08a9 7907 202d 5898 a85c facb 8c0a f9e5 ..y..-X..\......<br>0x0050 bd9c b649 5318 7fc5 c415 5a59 ...IS.....ZY<br>【例3】 抓所有接口(interface=any)的任何数据包(filter=none),级别3<br>(verbose=3),会显示数据包的payload信息。<br>FG-UTM # dia sni pa any none 3<br>interfaces=[any]<br>filters=[none]<br>nr=2048,fr=1584,b_nr=1024,pg=4096<br>3.770099 127.0.0.1.1029 -&gt; 127.0.0.1.53: udp 40<br>0x0000 0004 0304 0000 0000 9200 0000 2a00 0800</p><h2 style="font-size: 26px; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">2.3 count</h2><p align="left" style="padding-top: 8px; padding-bottom: 8px; line-height: 23px; text-align: justify; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">&lt;count&gt; 指使有抓包命令抓取的数据包的数量<br>例:<br># diag sniffer packet internal none 1 3<br>192.168.0.30.1156 -&gt; 192.168.0.1.80: syn 2164883624<br>192.168.0.1.80 -&gt; 192.168.0.30.1156: syn 3792179542 ack 2164883625<br>192.168.0.30.1156 -&gt; 192.168.0.1.80: ack 3792179543<br>说明:抓取internal 接口,不使有任何过滤器(及none)级别为1,抓取3<br>个数据包。此处,注意“none”必须要,代表过滤器的类型;注意“1”必须要,<br>否则系统会自动识别为&lt;verbose&gt;参数。</p><h2 style="font-size: 26px; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">2.4 filter</h2><p align="left" style="padding-top: 8px; padding-bottom: 8px; line-height: 23px; text-align: justify; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">&lt;filter&gt; 抓包文件过滤器<br>语法: '[[src|dst] host&lt;host_name_or_IP1&gt;] [[src|dst]<br>host&lt;host_name_or_IP2&gt;] [[arp|ip|gre|esp|udp|tcp] [port_num]]<br>[[arp|ip|gre|esp|udp|tcp] [port_num]]'<br>此处一定注意任何过滤语法必须使用单引号包含,否则会有问题。<br>第二种简单语法,适用于主机的会话抓包,无源和目的地址之分<br>'udp and port 1812 and host client1 and \( client2 or client3 \)'<br>【例1】使用源地址和目的地址过滤抓包<br># diag sniffer packet internal 'src host 192.168.0.130 and dst<br>host 192.168.0.1' 1<br>192.168.0.130.3426 -&gt; 192.168.0.1.80: syn 1325244087<br>192.168.0.1.80 -&gt; 192.168.0.130.3426: syn 3483111189 ack 1325244088<br>192.168.0.130.3426 -&gt; 192.168.0.1.80: ack 3483111190<br>192.168.0.130.3426 -&gt; 192.168.0.1.80: psh 1325244088 ack 3483111190<br>192.168.0.1.80 -&gt; 192.168.0.130.3426: ack 1325244686<br>192.168.0.130.1035 -&gt; 192.168.0.1.53: udp 26<br>192.168.0.130.1035 -&gt; 192.168.0.1.53: udp 42<br>192.168.0.130.1035 -&gt; 192.168.0.1.53: udp 42<br>192.168.0.130 -&gt; 192.168.0.1: icmp: echo request<br>192.168.0.130.3426 -&gt; 192.168.0.1.80: psh 1325244686 ack 3483111190<br>192.168.0.1.80 -&gt; 192.168.0.130.3426: ack 1325244735<br>192.168.0.130 -&gt; 192.168.0.1: icmp: echo request<br>【例2】使用源地址和目的地址、以及TCP 关键词过滤抓两个地址间的TCP 流<br>量<br># diag sniffer packet internal 'src host 192.168.0.130 and dst host<br>192.168.0.1 and tcp' 1<br>192.168.0.130.3569 -&gt; 192.168.0.1.23: syn 1802541497<br>192.168.0.1.23 -&gt; 192.168.0.130.3569: syn 4238146022 ack 1802541498<br>192.168.0.130.3569 -&gt; 192.168.0.1.23: ack 4238146023<br>【例3】使用地址(含源地址和目的地址)、以及ICMP 关键词过滤抓某个地<br>址间的ICMP 流量<br># diag sniffer packet internal 'host 192.168.0.130 and icmp' 1<br>192.168.0.130 -&gt; 192.168.0.1: icmp: echo request<br>192.168.0.1 -&gt; 192.168.0.130: icmp: echo reply<br>【例4】使用ICMP 关键词抓所有地址间的ICMP 流量<br>FG-UTM # diagnose sniffer packet port8 'icmp'<br>0.340847 10.7.10.100 -&gt; 10.7.10.1: icmp: echo request<br>0.340869 10.7.10.1 -&gt; 10.7.10.100: icmp: echo reply<br>1.340982 10.7.10.100 -&gt; 10.7.10.1: icmp: echo request<br>1.340997 10.7.10.1 -&gt; 10.7.10.100: icmp: echo reply<br>【例5】使用地址(含源地址和目的地址)、以及TCP 的端口关键词过滤抓两<br>个地址间的TCP 对应端口流量<br># diag sniffer packet internal 'host 192.168.0.130 or host 192.168.0.1<br>and tcp and port 80' 1<br>192.168.0.130.3625 -&gt; 192.168.0.1.80: syn 2057246590<br>192.168.0.1.80 -&gt; 192.168.0.130.3625: syn 3291168205 ack 2057246591<br>192.168.0.130.3625 -&gt; 192.168.0.1.80: ack 3291168206<br>192.168.0.130.3625 -&gt; 192.168.0.1.80: psh 2057246591 ack 3291168206<br>192.168.0.1.80 -&gt; 192.168.0.130.3625: ack 2057247265<br>【例6】使用接口、以及TCP 的端口关键词过滤抓多个地址间的TCP 非对应端<br>口流量,下例为不抓取23 端口的TCP 流量<br>FG-UTM # diagnose sniffer packet any 'tcp and port !23'<br>interfaces=[any]<br>filters=[tcp and port !23]<br>nr=8192,fr=1680,b_nr=4096,pg=4096<br>9.323698 10.7.10.100.1853 -&gt; 10.7.10.1.443: syn 4042810565<br>9.323786 10.7.10.1.443 -&gt; 10.7.10.100.1853: syn 177080791 ack 4042810566<br>9.324070 10.7.10.100.1853 -&gt; 10.7.10.1.443: ack 177080792<br>9.326695 10.7.10.100.1853 -&gt; 10.7.10.1.443: psh 4042810566 ack 177080792<br>9.326765 10.7.10.1.443 -&gt; 10.7.10.100.1853: ack 4042810644<br>【例7】使用接口、以及IP 的协议端口proto 关键词过滤抓多个地址间的IP<br>层对应端口流量,下例为抓取IP 层协议号为 1 的及ICMP 的流量<br>FG-UTM # diagnose sniffer packet port8 'ip proto 1'<br>interfaces=[port8]<br>filters=[ip proto 1]<br>nr=8192,fr=1664,b_nr=4096,pg=4096<br>5.701978 10.7.10.100 -&gt; 10.7.10.1: icmp: echo request<br>5.702056 10.7.10.1 -&gt; 10.7.10.100: icmp: echo reply<br>6.694490 10.7.10.100 -&gt; 10.7.10.1: icmp: echo request</p><h1 style="margin-bottom: 6px; padding-top: 16px; padding-bottom: 8px; font-size: 26px; line-height: 30px; font-family: 宋体, arial; text-align: center; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(229, 229, 229); background-color: rgb(238, 238, 238);">3.使用转化工具的方法</h1><p align="left" style="padding-top: 8px; padding-bottom: 8px; line-height: 23px; text-align: justify; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">首先,由于UTM 自身不支持抓包信息的存储,必须使有其他工具进行抓包<br>信息的收集,本文档使有SecureCRT 进行文本收集。<br>其次,使用抓包命令的&lt;verbose&gt;级别为3,此时导出的文件才能被ethereal<br>识别。<br>第三,要获取大量信息时,使有SecureCRT 工具应该通过远程数据连接(telnet<br>或者时SSH 方式,使用主机串口工作在这种模式下,由于串口速率的问题,无<br>法获得大量数据。<br>第四,使用单独提供的文件进行转换,主机必须提前perl 的解释程序和<br>Ethereal 软件,并在提供的转换使用的脚本文件中做必要的路径指向。</p><h2 style="font-size: 26px; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">3.1 SecureCRT 的配置</h2><p align="left" style="padding-top: 8px; padding-bottom: 8px; line-height: 23px; text-align: justify; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">正常安装SecureCRT 软件,并通过远程方式登陆到UTM 网关。<br>1、配置:文件接收――工具栏――Transfer――Receive ASCII<br>2、选择配置文件存储的路径,文件格式为*.txt<br>执行抓包命令:<br>FG-UTM # diagnose sniffer packet any none 3<br>其中3 代表抓包的输出文件支持经过转换为Ethereal 格式文件。</p><h2 style="font-size: 26px; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">3.2 编辑使用的脚本文件</h2><p align="left" style="padding-top: 8px; padding-bottom: 8px; line-height: 23px; text-align: justify; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">编辑提供的转换文件脚本fgt2eth.pl,修改脚本的第59 行,此处需要指明<br>Ethereal 的安装路径,下例中Ethereal 抓包分析软件安装在D 分区的根目录的<br>Ethereal 目录下,只需要指明安装目录即可,注意使用\\<br>第65 行:my $text2pcapdirwin = "d:\\Ethereal";<br>转换文件脚本fgt2eth.pl 请参考本文档『附录』,注意一定要进行必要的编辑。</p><h2 style="font-size: 26px; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">3.3 转换操作</h2><p align="left" style="padding-top: 8px; padding-bottom: 8px; line-height: 23px; text-align: justify; color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; background-color: rgb(238, 238, 238);">1、首先正常安装Perl 解释器,本例使用的是ActivePerl 5.8.8 Build 819 版本的<br>perl 语言工具。(工具可以自己从网上下载)<br>2、在DOS 命令行执行<br>C:\&gt;perl D:\ fgt2eth.pl -in D:\packet<br>[转换脚本文件的路径和文件名] [输入参数] [输入抓包获取的文件名]<br>缺省的输出文件与输入的相同路径下。<br>C:\&gt;perl D:\fgt2eth.pl -in D:\packet<br>Conversion of file D:\packet phase 1 (FG verbose 3 conversion)<br>Output written to D:\packet.eth.<br>Conversion of file D:\packet phase 2 (windows text2pcap)<br>Ouput file to load in Ethereal is 'D:\packet.eth'<br>上例显示,转换成功,转化输出的文件在D 分区下,转换生成的文件为packet.eth'。<br>如果需要改变输出的文件名,执行命令:<br>C:\&gt;perl D:\ fgt2eth.pl -in D:\packet –out D:\[输出文件名]<br>3、使用Ethereal 打开生成的转换文件</p><span style="color: rgb(68, 68, 68); font-family: tahoma, arial, 宋体, sans-serif; line-height: 21px; background-color: rgb(238, 238, 238);">上图显示生成的文件可以正常打开,并使用Ethereal 工具分析。</span></div>
頁: [1]
查看完整版本: [轉貼]FortiGate 用Sniffer 命令抓包分析