in packet sniffer

来源 https://kb.fortinet.com/kb/microsites/search.do?cmd=displayKC&docType=kc&externalId=11186&sliceId=1&docTypeID=DT_KCARTICLE_1_1&dialogID=56212880&stateId=1%200%2056214119

Introduction

All FortiGate units have a powerful packet sniffer on board. If you know tcpdump you should feel comfortable using the FortiGate Sniffer.

See the related article "Packet capture (sniffer) tips" for additional sniffer tips.

Scope : All FortiOS
Note :   Other Fortinet appliances also providing a CLI sniffer : FortiAnalyzer - FortiMail - FortiManager

DMZ

|

|

+-----------+

----internal----| FortiGate |---external-----

+-----------+

Sniffer Basics

The packet sniffer "sits" in the FortiGate and can sniff traffic on a specific Interface or on all Interfaces. There are 3 different Level of Information, also known as Verbose Levels 1 to 3, where verbose 1 shows less information and verbose 3 shows the most information. Verbose 4, 5 and 6 would additionally provide the interface details

Verbose levels in detail:

1: print header of packets
2: print header and data from IP of packets
3: print header and data from Ethernet of packets
4: print header of packets with interface name
5: print header and data from IP of packets with interface name
6: print header and data from Ethernet of packets with interface name

This article walks through some examples and different levels of verbosity to show the different possibilities for debugging.

Basic sniffing command

All Packet sniffing commands start like:

# diag sniffer packet <interface> <'filter'> <verbose> <count> a

Where...

<interface> can be an Interface name or "any" for all Interfaces.
<'filter'> is a very powerful filter functionality which will be described in more detail.<verbose> means the level of verbosity as described already.
<count> the number of packets the sniffer reads before stopping.
a introduced in release 3.0 MR6, this setting allows display of absolute time stamp

Example 1: Simple Trace

Sniff 3 packets of all traffic with verbose Level 4 on internal Interface

# diag sniffer packet internal none 4 3
internal in 192.168.0.1.22 -> 192.168.0.30.1144: psh 2859918764 ack 1949135261
internal in 192.168.0.1.22 -> 192.168.0.30.1144: psh 2859918816 ack 1949135261
internal out 192.168.0.30.1144 -> 192.168.0.1.22: ack 2859918884

As you can see we caught some Packets in the middle of a communication. Because the 192.168.0.1 IP Address uses Port 22 (192.168.0.1.22) we can assume that we've caught some Packets from a running SSH Session. The "none" variable means 'no filter applies', "4" means 'verbose 4' and "3" means 'catch 3 packets and stop'.

Example 2: Simple Trace

Sniff 3 packets of all traffic with verbose Level 4 on Internal interface

# diag sniffer packet internal none 4 3
internal out 192.168.0.30.1156 -> 192.168.0.1.80: syn 2164883624
internal in 192.168.0.1.80 -> 192.168.0.30.1156: syn 3792179542 ack 2164883625
internal out 192.168.0.30.1156 -> 192.168.0.1.80: ack 3792179543

Apparently we caught some more interesting information, just when a TCP session was being set up. 192.168.0.30 tries to connect to 192.168.0.1 on Port 80 with a syn and gets a syn ack back. Finally the session is acknowledged and established after the 3-way TCP handshake.

With information level set to Verbose 4, we see a summary of Source and Destination IP Address, as well as Source and Destination Port. We can also see the corresponding TCP Sequence numbers.

If you don't enter a <count> value, the Sniffer runs forever until you stop it with <CTRL C>

Hint: For further investigation it's always a good idea to log to a file. If you're using Putty (a free SSH client for Windows) you can easily log all Output to a file which you can search/sort/process.

Verbose 5 and Verbose 6 levels:

Verbose 5 contains much more information

1. The IP Header as we've already seen in Verbose 4
2. The Payload of the IP packet itself

An Output of Verbose 5 looks like this:

# diag sniffer packet internal none 5 1
internal in 192.168.0.1.22 -> 192.168.0.30.1144: psh 2867817048 ack 1951061933

0x0000 4510 005c 8eb1 4000 4006 2a6b c0a8 0001 E..\..@.@.*k....
0x0010 c0a8 001e 0016 0478 aaef 6a58 744a d7ad .......x..jXtJ..
0x0020 5018 0b5c 8ab9 0000 9819 880b f465 62a8 P..\.........eb.
0x0030 3eaf 3804 3fee 2555 8deb 24da dd0d c684 >.8.?.%U..$.....
0x0040 08a9 7907 202d 5898 a85c facb 8c0a f9e5 ..y..-X..\......
0x0050 bd9c b649 5318 7fc5 c415 5a59 ...IS.....ZY

Notice the in/ out parameter after internal interface that will confirm the direction of the packet entering or leaving the interface.

Verbose 6, finally, even includes Ethernet (Ether Frame) Information. A script is available (fgt2eth.pl), which will convert a captured verbose 6 output, into a file that can be read and decoded by Ethereal/Wireshark. See the end of this article for details.

Use of absolute time stamp in sniffer trace will report the absolute system time (no time zone) in packet summary:

# diag sniffer packet internal none 4 2 a

2010-06-02 10:23:17.170751 port1 out arp who-has 192.168.1.110 tell 192.168.1.103
2010-06-02 10:23:19.077409 port1 in arp who-has 192.168.1.120 tell 192.168.1.2

Hint: Below is the format that Technical Support will usually request when attempting to analyze a problem as it includes full packet content, as well as absolute time stamp, in order to correlate packets with other system events.

# diag sniffer packet any <'filter'> 6 0 a

Filter Functionality

As already mentioned: diag sniffer includes a powerful filter functionality that will be described here.

FortiOS tells us:

<filter> filter for sniffer
Syntax: '[[src|dst] host<IP1>] [[src|dst] host<IP2>] [[arp|ip|gre|esp|udp|tcp] [port_no]] [[arp|ip|gre|esp|udp|tcp] [port_no]]'

If a second host is specified, only the traffic between the 2 hosts will be displayed.

<filter> flexible logical filters for sniffer (or "none").
For example: To print udp 1812 traffic between forti1 and either forti2 or forti3
'udp and port 1812 and host forti1 and (forti2 or forti3)'

Imagine you only want to sniff the traffic from one PC to another PC. Without Filter the sniffer will display all packets which is far too much and painful to debug.

Example 3: Trace with Filters

To see what's going on between two PCs (or a PC and a FortiGate),(Don't forget to put your filter expressions in single quotes ' ' ):

# diag sniffer packet internal 'src host 192.168.0.130 and dst host 192.168.0.1' 1

192.168.0.130.3426 -> 192.168.0.1.80: syn 1325244087
192.168.0.130.3426 -> 192.168.0.1.80: ack 3483111190
192.168.0.130.3426 -> 192.168.0.1.80: psh 1325244088 ack 3483111190
192.168.0.130.1035 -> 192.168.0.1.53: udp 26
192.168.0.130.1035 -> 192.168.0.1.53: udp 42
192.168.0.130.1035 -> 192.168.0.1.53: udp 42
192.168.0.130 -> 192.168.0.1: icmp: echo request
192.168.0.130.3426 -> 192.168.0.1.80: psh 1325244686 ack 3483111190
192.168.0.130 -> 192.168.0.1: icmp: echo request

Assuming there is a lot of traffic on the wire, this filter command will only display traffic (but all traffic) from Source 192.168.0.130 to Destination 192.168.0.1. It will NOT show traffic to 192.168.0.130 (for example the ICMP reply) because we said ' src host 192.168.0.130 and dst host 192.168.0.1'

As you can see we also captured some other things like ICMP or DNS queries from a PC. If we're just interested in a specific type of traffic (let's say TCP Traffic only) we need to change our filter command slightly like this:

# diag sniffer packet internal 'src host 192.168.0.130 and dst host 192.168.0.1 and tcp' 1

192.168.0.130.3569 -> 192.168.0.1.23: syn 1802541497
192.168.0.1.23 -> 192.168.0.130.3569: syn 4238146022 ack 1802541498
192.168.0.130.3569 -> 192.168.0.1.23: ack 4238146023

Though ICMP (ping) was also running, the trace only shows the TCP part. As we can see the Destination is: 192.168.0.1.23 which is IP 192.168.0.1 on Port 23. Apparently we found a Telnet Session to 192.168.0.1 right during initial setup.

The same the other way around:

# diag sniffer packet internal 'host 192.168.0.130 and icmp' 1

192.168.0.130 -> 192.168.0.1: icmp: echo request
192.168.0.1 -> 192.168.0.130: icmp: echo reply

In this example we're sniffing for ICMP only, to and from 192.168.0.130

Another useful feature is logical combination. Let us assume you want to sniff for ICMP and TCP only (but not for UDP, ARP, etc). You can combine protocols in the following manner:

# diag sniffer packet internal 'host 192.168.0.130 and (icmp or tcp)' 1

This sniff will display all tcp or icmp traffic to and from host 192.168.0.30, in verbose 1 level.

Now we are going to limit the sniffer even more:

We want to sniff traffic between 2 hosts, but only TCP and only port 80.

# diag sniffer packet internal 'host 192.168.0.130 and 192.168.0.1 and tcp port 80' 1

192.168.0.130.3625 -> 192.168.0.1.80: syn 2057246590
192.168.0.1.80 -> 192.168.0.130.3625: syn 3291168205 ack 2057246591
192.168.0.130.3625 -> 192.168.0.1.80: ack 3291168206
192.168.0.130.3625 -> 192.168.0.1.80: psh 2057246591 ack 3291168206
192.168.0.1.80 -> 192.168.0.130.3625: ack 2057247265

A logical "and" is used in this command between 192.168.0.130 and 192.168.0.1 so that only packets containing both these host addresses will be seen.

Even if telnet and ssh is running between the two hosts, we only see port 80 TCP traffic.

Filtered can be used to display packets based on their content, using hexadecimal byte position.

Match TTL = 1
# diagnose sniffer packet port2 "ip[8:1] = 0x01"

Match Source IP address = 192.168.1.2:
# diagnose sniffer packet internal "(ether[26:4]=0xc0a80102)"

Match Source MAC = 00:09:0f:89:10:ea
# diagnose sniffer packet internal "(ether[6:4]=0x00090f89) and (ether[10:2]=0x10ea)"

Match Destination MAC = 00:09:0f:89:10:ea
# diagnose sniffer packet internal "(ether[0:4]=0x00090f89) and (ether[4:2]=0x10ea)"

Match ARP packets only
# diagnose sniffer packet internal "ether proto 0x0806"

TCP or UDP flags can be addressed using the following:

Match packets with RST flag set:
# diagnose sniffer packet internal "tcp[13] & 4 != 0"

Match packets with SYN flag set:
# diagnose sniffer packet internal "tcp[13] & 2 != 0"

Match packets with SYN-ACK flag set:
# diagnose sniffer packet internal "tcp[13] = 18"

Also attached is the fgt2eth.pl script that will convert a verbose level 3 or 6 sniffer output, into a file readable and decodable by Ethereal/Wireshark.

The fgt2eth.exe file is also attached to this article, this file is outdated and is not supported but may provide some guidance.


Note:
 The attached script is provided "as is", it is not supported by Technical Support.

$ ./fgt2eth.pl 
Version : Dec 19 2014
Usage : fgt2eth.pl -in <input_file_name>

Mandatory argument are :
    -in  <input_file>     Specify the file to convert (FGT verbose 3 text file)

Optional arguments are :
    -help                 Display help only
    -version              Display script version and date
    -out <output_file>    Specify the output file (Ethereal readable)
                By default <input_file>.pcap is used
                - will start wireshark for realtime follow-up
    -lines <lines>        Only convert the first <lines> lines
    -demux            Create one pcap file per interface (verbose 6 only)
    -debug                Turns on debug mode

Related Articles
Attachments

======================= End

in packet sniffer的更多相关文章

  1. 【转】蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet Sniffer 抓取数据方法--不错

    原文网址:http://blog.csdn.net/mzy202/article/details/32408223 蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet ...

  2. 蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet Sniffer 抓取数据方法

    蓝牙4.0的开发, 现在真热火的很, 但是很多朋友买了我们出品的cc2540 usb-dongle后, 都反馈说不知道如何抓包, 并且, 即使很多朋友到TI官网论坛去找信息,不少朋友依然是无功而返,实 ...

  3. Develop a Packet Sniffer with libpcap

    Develop a Packet Sniffer with libpcap: http://vichargrave.com/develop-a-packet-sniffer-with-libpcap/

  4. 浅谈原始套接字 SOCK_RAW 的内幕及其应用(port scan, packet sniffer, syn flood, icmp flood)

    一.SOCK_RAW 内幕 首先在讲SOCK_RAW 之前,先来看创建socket 的函数: int socket(int domain, int type, int protocol); domai ...

  5. 蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet Sniffer 抓取数据方法 【原创,多图】

    蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet Sniffer 抓取数据方法 [原创,多图] spm=a1z10.1.w4004-5319414070.11.Zd ...

  6. Python Ethical Hacking - Packet Sniffer(1)

    PACKET_SNIFFER Capture data flowing through an interface. Filter this data. Display Interesting info ...

  7. Python Ethical Hacking - Packet Sniffer(2)

     Capturing passwords from any computer connected to the same network.  ARP_SPOOF + PACKET_SNIFFER Ta ...

  8. 使用Packet Sniffer抓包和分析(z-stack协议)

    以下内容仅是自己学习总结,可能会有错误,有发现问题的欢迎指正(图片可以自己放大,还是比较清晰的). 1.协调器上电,其他设备均不上电,抓包如下: 通过观察可以发现,协调器建立网络成功后,会以15秒为周 ...

  9. 抓包软件Packet Sniffer的使用

    1. 要用专门的一块zigbee插到底板上,仿真器连到CC Debug接口. 2. 打开软件,按下仿真器的复位键,可以识别到设备. 3. 进行抓包(抓到的是网络中其他节点的信息)

随机推荐

  1. Docker容器运行GUI程序的配置方法

    0.环境说明 Ubuntu 16.04 docker 1.35 1.Docker的“可视化” Docker本身的工作模式是命令行的,因为主要的使用场景可能是做服务器后端方面的比较多. 但有时候我们会有 ...

  2. python中安装Tensorflow

    执行命令:pip install --upgrade tensorflow 即可.

  3. HUE配置hadoop

    HDFS配置 参考文档:http://archive.cloudera.com/cdh5/cdh/5/hue-3.9.0-cdh5.5.0/manual.html Hadoop配置文件修改 hdfs- ...

  4. storm报错:Exception in thread "main" java.lang.RuntimeException: InvalidTopologyException(msg:Component: [mybolt] subscribes from non-existent stream: [default] of component [kafka_spout])

    问题描述: storm版本:1.2.2,kafka版本:2.11.   在使用storm去消费kafka中的数据时,发生了如下错误. [root@node01 jars]# /opt/storm-1. ...

  5. Web安全基础实践

    Web安全基础实践 标签(空格分隔): <> 目录 基础问题回答 WebGoat下载安装 SQL注入攻击 - SQL字符串注入(String SQL Injection) - 数字型SQL ...

  6. 20155338课程设计个人报告——基于ARM实验箱的Android交友软件的设计与实现

    课程设计个人报告--基于ARM实验箱的Android交友软件的设计与实现 个人贡献 实验环境的搭建 代码调试 在电脑上成功运行 研究程序代码撰写小组报告 一.实验环境 1.Eclipse软件开发环境: ...

  7. Spring-data-jpa 学习笔记(一)

    Spring家族越来越强大,作为一名javaWeb开发人员,学习Spring家族的东西是必须的.在此记录学习Spring-data-jpa的相关知识,方便后续查阅. 一.spring-data-jpa ...

  8. idea 中全局查找不到文件 (两shift),单页搜索不到关键字的原因

    全局查找不到文件是因为把要找的目录的本级或者上级设置为了额外的,所以自然找不到 而单页搜索不到内容是因为设置了words关键字,这个要全部都输入完才能找到(也就是整个关键字进行匹配,匹配到了整体才会查 ...

  9. jQuery .attr() vs. .prop()

    Property vs. Attribute 在开始正式比较prop()和attr()两个jQuery方法之前,我们有必要先弄清一下Property和Attribute两个单词的意思.在中文里面,它们 ...

  10. Css_*^$

    #search_condition [class*=search_submit] 表示class name里面的值包含search_submit $("#search_condition [ ...