sniffer 工具介绍
sniffer 工具介绍
FortiGate 具备完善的 sniffer 功能,可以基于指定接口或所有接口附带过滤条件进行抓包。
Sniffer 命令
diagnose sniffer packet <interface> <filter> <verbose> <count> <tsformat> <frame size><interface>:可以指定一个具体的 interface 名字,比如“port1”或所有接口“any”。<filter>:非常强大的过滤功能,可以过滤出想要过滤的流,过滤条件需要引号括起来'<filter>'或者"<filter>",与 tcpdump 语法基本相同。[[src|dst] host {<host1_ipv4>}] [and|or] [[src|dst] host <host2_ipv4>}] [and|or] [[arp|ip|gre|esp|udp|tcp] port <port1_int>] [and|or] [[arp|ip|gre|esp|udp|tcp] port <port2_int>]- 过滤单个 IP(该 IP 可以是源,也可以是目的):
'host 1.1.1.1' - 过滤源 IP 和目的 IP:
'host 1.1.1.1 and host 2.2.2.2' - 过滤目的 IP 和协议端口:
'dst 2.2.2.2 and tcp port 80' - 过滤源 IP 和协议:
'src 1.1.1.1 and icmp'
- 过滤单个 IP(该 IP 可以是源,也可以是目的):
<verbose>:不同级别的不同内容展示,按需定义 sniffer 级别。1:print header of packets(只输出报文头部内容)2:print header and data from ip of packets(输出从 ip 头部开始,包含数据内容)3:print header and data from ethernet of packets(输出从 ethernet 头部开始,包含数据内容)4:print header of packets with interface name(只输出报文头部和进出接口,使用最多)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(从 ethernet 头部开始,包含数据内容和进出接口,使用较多)
<count>:抓包个数,到达指定个数后停止 sniffer,如 100 表示抓 100 个包,填写为 0 表示不限制抓包的数量。<tsformat>:时间戳格式。a:UTC 绝对时间,格式为yyyy-mm-dd hh:mm:ss.msl:本地时间,yyyy-mm-dd hh:mm:ss.ms- 不填写:开始抓包后的相对时间,
ss.ms
<frame size>:设置截断前帧的大小,默认是接口 MTU。
Sniffer 示例
在 port1 上抓取源或目的 IP 为 172.16.1.100 的包,只输出报文头部内容。
diagnose sniffer packet port1 "host 172.16.1.100" 1在所有接口上抓取源或目的 IP 为 172.16.1.100 的 ICMP 报文,输出报文头部和进出接口。
diagnose sniffer packet any "host 172.16.1.100 and icmp" 4在所有接口上抓取源或目的 IP 为 172.16.1.100 的 TCP 报文,输出报文头部和进出接口。
diagnose sniffer packet any "host 172.16.1.100 and tcp" 4在所有接口上抓取源或目的 IP 为 172.16.1.100 的 UDP 报文,输出报文头部和进出接口。
diagnose sniffer packet any "host 172.16.1.100 and udp" 4在所有接口上抓取源或目的 IP 为 172.16.1.100,端口号为 443 的 TCP 报文,输出报文头部和进出接口。
diagnose sniffer packet any "host 172.16.1.100 and tcp port 443" 4在所有接口上抓取源或目的 IP 为 172.16.1.100 且 TCP 端口≠22 的报文, 输出报文头部和进出接口。
diagnose sniffer packet any "host 172.16.1.100 and !tcp port 22" 4在所有接口上抓取源或目的 IP 为 172.16.1.100 且 TCP/UDP 端口为 10000 的报文, 输出报文头部和进出接口。
diagnose sniffer packet any "host 172.16.1.100 and port 10000" 4在所有接口上抓取源或目的 IP 为 114.114.119.119 且协议为 ICMP 的报文,携带 0 表示不限制抓包个数,携带 a 表示携带抓包的时间戳,时间戳的格式为抓包开始后的相对时间。
diagnose sniffer packet any "host 114.114.119.119 and icmp" 4 0 a在所有接口上抓取目的 IP 为 114.114.119.119 且协议为 ICMP 的报文,携带 0 表示不限制抓包个数,携带 l 表示携带抓包的时间戳,时间戳格式为绝对时间,与设备上的时间一致。
diagnose sniffer packet any "dst 114.114.119.119 and icmp" 4 0 l在 port1 接口上抓取源 IP 为 10.1.1.1,源或目的端口号为 80,并携带 VLAN Tag 10 的报文。
diagnose sniffer packet port1 'vlan 10 and src 10.1.1.1 and port 80' 4在 port1 上抓取 VLAN tag 为 3001 且 IP host 为 192.168.1.1 的 VLAN trunk 报文,或 VLAN tag 为 3002 且 IP host 为 192.168.2.1 的 VLAN trunk 报文。
diagnose sniffer packet port1 "vlan and ((ether[14:2] == 3001 and host 192.168.1.1) or (ether[14:2] == 3002 and host 192.168.2.1))" 4 0 l在所有接口上抓取(源或目的 IP 为 172.16.1.100)或(源或目的 IP 为 172.16.1.101 且端口号为 1701)的报文。
diagnose sniffer packet any "host 172.16.1.100 or (host 172.16.1.101 and port 1701)" 4在 internal 接口上抓取 SYN 置位的 TCP 报文。
diagnose sniffer packet internal "tcp[13]&2!=0 and port 23" 4在 internal 接口上抓取 SYN - ACK 置位的 TCP 报文。
diagnose sniffer packet internal "tcp[13] = 18" 4在 internal 接口上抓取 RST 置位的 TCP 报文。
diagnose sniffer packet internal "tcp[13]&4!=0" 4在 wan1 接口上抓取 PPPoE 协商报文(其中 0x8863 发现阶段,0x8864 为会话阶段)。
diagnose sniffer packet wan1 "ether proto 0x8863 or ether proto 0x8864" 4在 internal 接口上抓取源或目 IP 属于网段为 4.2.2.0/24 的所有报文。
diagnose sniffer packet internal "net 4.2.2.0/24" 4在 internal 接口上抓取源 MAC 地址为 00:09:0f:89 的报文。
diagnose sniffer packet internal "(ether[6:4]=0x00090f89) and (ether[10:2]=0x10ea)" 4在所有接口上抓取 IP TTL 为 1 的报文。
diagnose sniffer packet any "ip[8:1] = 0x01" 4在 internal 接口上抓取特定 Payload 的报文。
Payload: 0x0040 8f48 8a0c 7468 6973 2069 7320 7069 6e67 .H..this.is.ping Filter: diagnose sniffer packet internal "ether[0x44:4]=0x74686973" 4在所有接口上抓取大于 1500 Bytes(除去二层头部长度)的报文。
diagnose sniffer packet any "ip[2:2] > 1500" 4抓取三层组播报文。
diagnose sniffer packet port1 'ip multicast' 6 0 l抓取二层组播报文。
diagnose sniffer packet port1 'ether multicast' 6 0 l抓取三层广播报文。
diagnose sniffer packet port1 'ip broadcast' 6 0 l抓取二层广播报文。
diagnose sniffer packet port1 'ether broadcast' 6 0 l抓取二层和三层组播。
diagnose sniffer packet port1 'multicast' 6 0 l
Sniffer 过程分析
ICMP
ICMP 的请求报文是 echo request,响应报文是 echo reply,in 表示 FortiGate 收到一个报文,out 表示 FortiGate 发出一个报文。在 FortiGate 上抓取 ICMP 报文。
FortiGate # diagnose sniffer packet any 'host 192.168.2.10 and icmp' 4 interfaces=[any] filters=[host 192.168.2.10 and icmp]FortiGate 从 port5 收到 192.168.1.10 发送给 192.168.2.10 ping 的请求报文 echo request。
7.074724 port5 in 192.168.1.10 -> 192.168.2.10: icmp: echo requestFortiGate 将 192.168.1.10 发送给 192.168.2.10 ping 的请求报文 echo request 从 port6 转发出去了。
7.074748 port6 out 192.168.1.10 -> 192.168.2.10: icmp: echo requestFortiGate 从 port6 收到 192.168.2.10 发送给 192.168.1.10 ping 的响应报文 echo reply。
7.075033 port6 in 192.168.2.10 -> 192.168.1.10: icmp: echo replyFortiGate 将 192.168.2.10 发送给 192.168.1.10 ping 的响应报文 echo reply 从 port5 转发出去了。
7.075042 port5 out 192.168.2.10 -> 192.168.1.10: icmp: echo reply从上面的抓包来看,FortiGate 成功转发了 192.168.1.10 和 192.168.2.10 之间 ping 的请求和响应报文。
TCP
TCP 报文交互之前都需要完成 3 次握手,in 表示 FortiGate 收到一个报文,out 表示 FortiGate 发出一个报文。在 FortiGate 上抓取 TCP 报文。
FortiGate # diagnose sniffer packet any 'host 192.168.2.10 and port 22' 4 interfaces=[any] filters=[host 192.168.2.10 and port 22]FortiGate 从 port5 收到 192.168.1.10 发送给 192.168.2.10 的 syn 报文。
12.009383 port5 in 192.168.1.10.46028 -> 192.168.2.10.22: syn 486804292FortiGate 将 192.168.1.10 发送给 192.168.2.10 的 syn 报文从 port6 转发出去了。
12.009752 port6 out 192.168.1.10.46028 -> 192.168.2.10.22: syn 486804292FortiGate 从 port6 收到 192.168.2.10 发送给 192.168.1.10 的 syn ack 报文。
12.009957 port6 in 192.168.2.10.22 -> 192.168.1.10.46028: syn 1279904517 ack 486804293FortiGate 将 192.168.2.10 发送给 192.168.1.10 的 syn ack 报文从 port5 转发出去了。
12.010120 port5 out 192.168.2.10.22 -> 192.168.1.10.46028: syn 1279904517 ack 486804293FortiGate 从 port5 收到 192.168.1.10 发送给 192.168.2.10 的 ack 报文。
12.010233 port5 in 192.168.1.10.46028 -> 192.168.2.10.22: ack 1279904518FortiGate 将 192.168.1.10 发送给 192.168.2.10 的 ack 报文从 port6 转发出去了。
12.010245 port6 out 192.168.1.10.46028 -> 192.168.2.10.22: ack 1279904518从上面的抓包来看,FortiGate 成功转发了 192.168.1.10 和 192.168.2.10 之间 tcp 三次握手的报文。