一、图形界面抓包
1、通过web界面抓包(需要设备有硬盘)
进入 系统管理--网络--数据包捕获

如上图 数据包捕获界面,点击'新建'即可创建一个抓包过滤器,并进行抓包。

按上图填入需要抓取的过滤条件,ip、端口等,点击确认,添加好的数据捕获如下图。

选择添加好的数据捕获,点击"运行"开关抓包;抓取包后,可以点击"下载"将抓取的数据包保存的本地磁盘,可以用wireshark直接查看。

该方式的优点是方便,抓取的内容可以直接查看,缺点是过滤选项不够丰富。

二、抓包命令详解
Sniffer 介绍
FortiGate具备完善的sniffer功能,可以基于指定接口或所有接口附带过滤条件进行抓包,sniffer主要有3种信息级别(Levels1-3), Level-1显示较少的信息,Level-3显示最多的信息,剩下的Level-4, 5 and 6则相应地增加了出入接口详细信息。
Sniffing命令:
All Packet sniffing commands start like:
# diag sniffer packet <interface> <'filter'> <verbose-Levels> <count> a
# diag sniffer packet <interface> <'filter'> <verbose-Levels> <count> l
<interface> 可以指定一个具体的interface名字,比如“port1”或所有接口“any”
<‘filter’> 非常强大的过滤功能,可以过滤出你想要过滤的流,遵循tcpdump语法
<verbose-Levels> 不同级别的不同内容展示,按需定义sniffer级别
<count> 抓包个数,到达指定个数后停止sniffer
a absolute UTC time, yyyy-mm-dd hh:mm:ss.ms
l absolute UTC time, yyyy-mm-dd hh:mm:ss.ms
Verbose Levels级别:
1: print header of packets (只有IP头部)
2: print header and data from ip of packets (有ip头部和数据内容)
3: print header and data from ethernet of packets (if available) (用于转成wireshark可以打开的pacp格式)
4: print header of packets with interface name (只有IP头部和端口) (使用最多)
5: print header and data from ip of packets with interface name (有ip头部和数据内容以及端口)
6: print header and data from ethernet of packets (if available) with intf name
参数0的用处:输出个数,0表示不显示抓包数量
参数l的用处(用于输出时候显示的时间格式):
a:absolute UTC time, yyyy-mm-dd hh:mm:ss.ms
l:absolute UTC time, yyyy-mm-dd hh:mm:ss.ms
Sniffer 常用抓包命令
diagnose sniffer packet port1 "host 172.16.1.100" 1 //抓port1上172.16.1.100的包
diagnose sniffer packet any "host 172.16.1.100 and icmp" 4 //抓172.16.1.100的ICMP包
diagnose sniffer packet any "host 172.16.1.100 and tcp" 4 //抓172.16.1.100的TCP包
diagnose sniffer packet any "host 172.16.1.100 and udp" 4 //抓172.16.1.100的UDP包
diagnose sniffer packet any "host 172.16.1.100 and tcp port 443" 4 //抓172.16.1.100且https的包
diagnose sniffer packet any "host 172.16.1.100 and !tcp port 22" 4 //抓172.16.1.100且非ssh的包
diagnose sniffer packet any "host 172.16.1.100 and port 10000" 4 //抓172.16.1.100且TCP/UDP-Port=10000的包
diagnose sniffer packet any "host 114.114.119.119 and icmp" 4 0 a // 携带0表示不限制抓包个数,携带a表示携带抓包的时间戳,a 表示不携带是时区的绝对时间
diagnose sniffer packet any "host 114.114.119.119 and icmp" 4 0 l // 携带0表示不限制抓包个数,携带l表示携带抓包的时间戳,l 表示携带是时区的绝对时间,通常我们使用这个参数,和设备保持一致
diagnose sniffer packet any "host 172.16.1.100 or host 172.16.1.101 and port 1701" 4 //and和or组合
diagnose sniffer packet internal "tcp[13]&2!=0 and port 23" 4 //SYN置位包
diagnose sniffer packet internal "tcp[13]&4!=0" 4 //RST置位
diagnose sniffer packet internal "net 4.2.2.0/24" 4 //抓某一网段的包
diagnose sniffer packet internal "(ether[6:4]=0x00090f89) and (ether[10:2]=0x10ea)" 4 //根据MAC源地址抓包
diagnose sniffer packet any "ip[2:2] > 1500" 4 //观察大于1500的帧
如果以上命令都无法满足抓包过滤要求,可参考tcpdump命令的语法!
过滤条件应该如果设置?
sniffer抓包举例1:
sniffer抓包举例2:
sniffer抓包举例3:
sniffer抓包举例4:
Sniffer 应该抓取一条流的五元组不变的那个参数!
如源IP不变化就抓源IP
目的IP不变化就抓目的IP
目的端口不变化就抓目的端口
如果都变化则就需要使用or+and的组合来匹配出变化前和变化后的流,比如“变化前的源 or 变化后的源IP and 协议”这种方式抓取。
如何将Diagnose sniffer 3所抓的数据转成wireshark可以打开的pacp格式?
方法1(推荐):使用“ConvertPcap”工具实现“txt”到“pacp”的一键转换
1.安装“ConvertPcap-1.1.exe”
下载路径:http://pan.baidu.com/s/1mhGLILq或http://support.fortinet.com.cn/index.php?m=content&c=index&a=show&catid=36&id=419
2.通过diagnose sniffer packet any“xxxx” 3抓取报文内容保存为txt文本格式,右击“txt”文本格式的报文,选择Convert to PACP或Convert and OPEN,即完成数据格式的转换,无需安装或设置其他辅助工具,使用起来非常方便简洁