Fortigate diag sniffer packet für Wireshark umwandeln

Auf der Fortigate gibt es den Befehl:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
diag sniffer packet [interface] '[filter]' [verbose level] [count] [tsformat]
diag sniffer packet [interface] '[filter]' [verbose level] [count] [tsformat]
diag sniffer packet [interface] '[filter]' [verbose level] [count] [tsformat]

Details dazu finden Sie ⇒hier.

Will man nur schnell prüfen, ob das Packet die Firewall passiert, reicht die Anwendung von

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
diag sniffer packet any '[filter]' 4
diag sniffer packet any '[filter]' 4
diag sniffer packet any '[filter]' 4

Man sieht dann das Paket auf dem eingehenden und auf dem ausgehenden Interface, sowie die Richtung.

Will man den Inhalt des Pakets anschauen, erhält man hexadezimale Informationen. Möchte ich die Pakete mit Wireshark analysieren, muss ich die Ausgabe zuerst formatieren.

Dazu muss die Ausgabe von diag sniffer packet in das hexdump Format gebracht werden.

Das Paket von diag sniffer Paket so so aus:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
2018-07-30 11:46:39.203676 802.1Q vlan#7 P0
0x0000 0100 0000 0000 02db e3b3 6515 8100 0007 ..........e.....
0x0010 0800 4500 003e 4743 0000 0211 8349 0a00 ..E..>GC.....I..
0x0020 0328 e000 00fb cc86 14e9 002a c5b0 5e7e .(.........*..^~
0x0030 0000 0001 0000 0000 0000 055f 7261 6f70 ..........._raop
0x0040 045f 7463 7005 6c6f 6361 6c00 000c 0001 ._tcp.local.....
2018-07-30 11:46:39.203676 802.1Q vlan#7 P0 0x0000 0100 0000 0000 02db e3b3 6515 8100 0007 ..........e..... 0x0010 0800 4500 003e 4743 0000 0211 8349 0a00 ..E..>GC.....I.. 0x0020 0328 e000 00fb cc86 14e9 002a c5b0 5e7e .(.........*..^~ 0x0030 0000 0001 0000 0000 0000 055f 7261 6f70 ..........._raop 0x0040 045f 7463 7005 6c6f 6361 6c00 000c 0001 ._tcp.local.....
2018-07-30 11:46:39.203676 802.1Q vlan#7 P0
0x0000   0100 0000 0000 02db e3b3 6515 8100 0007        ..........e.....
0x0010   0800 4500 003e 4743 0000 0211 8349 0a00        ..E..>GC.....I..
0x0020   0328 e000 00fb cc86 14e9 002a c5b0 5e7e        .(.........*..^~
0x0030   0000 0001 0000 0000 0000 055f 7261 6f70        ..........._raop
0x0040   045f 7463 7005 6c6f 6361 6c00 000c 0001        ._tcp.local.....

Ein Paket wird in hexdump so dargestellt:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
2018-07-30 11:46:39.203676
000000 01 00 00 00 00 00 02 db e3 b3 65 15 81 00 00 07
000010 08 00 45 00 00 3e 47 43 00 00 02 11 83 49 0a 00
000020 03 28 e0 00 00 fb cc 86 14 e9 00 2a c5 b0 5e 7e
000030 00 00 00 01 00 00 00 00 00 00 05 5f 72 61 6f 70
000040 04 5f 74 63 70 05 6c 6f 63 61 6c 00 00 0c 00 01
2018-07-30 11:46:39.203676 000000 01 00 00 00 00 00 02 db e3 b3 65 15 81 00 00 07 000010 08 00 45 00 00 3e 47 43 00 00 02 11 83 49 0a 00 000020 03 28 e0 00 00 fb cc 86 14 e9 00 2a c5 b0 5e 7e 000030 00 00 00 01 00 00 00 00 00 00 05 5f 72 61 6f 70 000040 04 5f 74 63 70 05 6c 6f 63 61 6c 00 00 0c 00 01
2018-07-30 11:46:39.203676
000000  01 00 00 00 00 00 02 db e3 b3 65 15 81 00 00 07
000010  08 00 45 00 00 3e 47 43 00 00 02 11 83 49 0a 00
000020  03 28 e0 00 00 fb cc 86 14 e9 00 2a c5 b0 5e 7e
000030  00 00 00 01 00 00 00 00 00 00 05 5f 72 61 6f 70
000040  04 5f 74 63 70 05 6c 6f 63 61 6c 00 00 0c 00 01

Um die Pakete richtig zu formatieren, haben wir ein Perl Script erstellt. Damit wird der Output richtig formatiert und kann danach in Wireshark eingelesen werden.

Auf MacOS oder unter Linux kann das in einem einzigen Befehl von der Kommando Zeile erfolgen:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ssh -l <user> <firewall addresse> "diag sniffer packet any '' 3 0 l" | hexdump.pl - | text2pcap - sniffer-out.pcap
ssh -l <user> <firewall addresse> "diag sniffer packet any '' 3 0 l" | hexdump.pl - | text2pcap - sniffer-out.pcap
ssh -l <user> <firewall addresse> "diag sniffer packet any '' 3 0 l" | hexdump.pl - | text2pcap - sniffer-out.pcap

Mit diesem Befehl wird via SSH der Sniffer auf der FortiGate gestartet, hexdump.pl liest den Output von STDIN, text2pcap formatiert hexdump Output in PCAP Format um.

Danach kann das File sniffer-out.pcap in Wireshark eingelesen und analysiert werden.

hexdump.pl verwendet als Input ein File. Wird – (Bindestrich) als Input angegeben, verwendet hexdump.pl <STDIN>.

Alternativ kann der Sniffer Output direkt via Pipe an Wireshark gesendet werden:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ssh -l <user> <firewall address> "diag sniffer packet any '' 3 0 l" | hexdump.pl - | text2pcap -t "%Y-%m-%d %H:%M:%S." - - | wireshark -k -i -
ssh -l <user> <firewall address> "diag sniffer packet any '' 3 0 l" | hexdump.pl - | text2pcap -t "%Y-%m-%d %H:%M:%S." - - | wireshark -k -i -
ssh -l <user> <firewall address> "diag sniffer packet any '' 3 0 l" | hexdump.pl - | text2pcap -t "%Y-%m-%d %H:%M:%S." - - | wireshark -k -i -

 

Verwendung innerhalb von VDOMs:

Wollen Sie dieses Script innerhalb einer VDOM ausführen, müssen Sie zuerst in die VDOM wechseln. Erstellen Sie ein File. In diesem Beispiel heisst es sniff.txt:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
config vdom
edit root
diag sniffer packet any 'not port 22' 3 0 l
config vdom edit root diag sniffer packet any 'not port 22' 3 0 l
config vdom
edit root
diag sniffer packet any 'not port 22' 3 0 l

Und nun führen Sie den Befehl wie folgt aus:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
ssh -l <user> <firewall address> < sniff.txt | hexdump.pl - | text2pcap -t "%Y-%m-%d %H:%M:%S." - - | wireshark -k -i -
ssh -l <user> <firewall address> < sniff.txt | hexdump.pl - | text2pcap -t "%Y-%m-%d %H:%M:%S." - - | wireshark -k -i -
ssh -l <user> <firewall address> < sniff.txt | hexdump.pl - | text2pcap -t "%Y-%m-%d %H:%M:%S." - - | wireshark -k -i -

 

hexdump
hexdump