LoginSignup
5
8

More than 3 years have passed since last update.

LANスイッチでパケットキャプチャ

Last updated at Posted at 2020-05-27

はじめに

ちょっと、パケットキャプチャしたいじゃないですか。PythonとかYANGモデルとかに疲れてきたときに、Wireshark開いてホッとするクラスターです。最近の Cisco Catalystスイッチでは、8つまでパケットキャプチャの設定ができ(キャプチャポイント)、同時に走らせるのは一つまでという仕様になっているそうです(最近ってどの辺?という質問は各自調べてくださいませ)。

そんなに日常的にやるわけではないし、もっとがっつりやる場合はスイッチではやらなかったりして、すぐ設定と手順を忘れてしまうので、自分用にメモしておきます。というか、LANスイッチでキャプチャ?ハァ?という方にはお役に立てるかもしれませんので、参考にされてくださいませ。

設定の確認と流れ

設定

edge1#sho ver | i bin
System image file is "flash:cat9k_iosxe.16.12.02.SPA.bin"

キャプチャポイントとその状態を確認するコマンドです。

edge1#show monitor capture ?
  WORD  Name of the Capture Point
  file  Display captured file
  |     Output modifiers
  <cr>  <cr>

自分のキャプチャポイントに名前を付けて(mycap)、そのあとに色々と設定を決めたり、開始や停止もここから行います。

edge1#monitor capture mycap ?
  access-list    access-list to be attached 
  buffer         Buffer options
  class-map      class name to attached 
  clear          Clear Buffer
  control-plane  Control Plane 
  export         Export Buffer
  file           Associated file attributes
  interface      Interface
  limit          Limit Packets Captured
  match          Describe filters inline
  start          Enable Capture
  stop           Disable Capture 
  stop_export    Disable Capture and Export Buffer
  vlan           Vlan

ざっくりですが、Gi1/0/24のインターフェースのIn/Outを通過するUDPパケットをキャプチャすることにした設定です。ファイルをフラッシュに置くこととし、名前を付けます。

monitor capture mycap interface GigabitEthernet1/0/24 BOTH
monitor capture mycap match ipv4  protocol udp any any
monitor capture mycap file location flash:mycap.pcap size 100

バッファタイプは、リニア型とサーキュラー型の二種類があり、デフォルトはリニア型です。容量の上限に達すると停止するのがリニア型で、新しいもので上書きして動き続けるのがサーキュラー型です。コマンドオプションで変更できます。(この例では変更してません)

edge1#show monitor capture mycap 

Status Information for Capture mycap
  Target Type: 
 Interface: GigabitEthernet1/0/24, Direction: BOTH
   Status : Inactive
  Filter Details: 
   IPv4 
    Source IP:  any
    Destination IP:  any
   Protocol: udp
  Buffer Details: 
   Buffer Type: LINEAR (default) <--- リニアバッファになっています。
  File Details: 
   Associated file name: flash:mycap.pcap
   Total size of files(in MB): 100
  Limit Details: 
   Number of Packets to capture: 0 (no limit)
   Packet Capture duration: 0 (no limit)
   Packet Size to capture: 0 (no limit)
   Packet sampling rate: 0 (no sampling)

それでは、フラッシュにキャプチャファイルが存在していないことを確認し、キャプチャ開始します。

edge1#sh flash: | i mycap.pcap
edge1#
edge1#monitor capture mycap start <--- キャプチャ開始!
Started capture point : mycap
edge1#

キャプチャを停止し、そのままファイルに出力します(stopだけの指定だと、バッファ上にキャプチャデータが保存され、ファイル書き出しは行われません)。先ほどは存在していなかった mycap.pcapファイルが確認できました。

edge1#monitor capture mycap stop_export
Capture statistics collected at software:
    Capture duration - 49 seconds
    Packets received - 87
    Packets dropped - 0
    Packets oversized - 0

Bytes dropped in asic - 0

edge1#
edge1#sh flash: | i mycap.pcap         
117      17076 May 27 2020 04:47:42.0000000000 +00:00 mycap.pcap

確認

IOS XEのターミナル上から、pcapファイルの中身をデコードできます。

edge1#show monitor capture file flash:mycap.pcap ?
  brief           brief display
  detailed        detailed disaply
  display-filter  Display filter
  dump            for dump
  packet-count    Display packet count
  packet-number   Display specified packet
  statistics      Display cap file statistics
  |               Output modifiers
  <cr>            <cr>
edge1#show monitor capture file flash:mycap.pcap 
Starting the packet display ........ Press Ctrl + Shift + 6 to exit

  1   0.000000 192.168.1.102 -> 10.172.2.101 Syslog 130 LOCAL7.INFO: 8761: *May 27 2020 04:46:54.031 UTC: %BUFCAP-6-ENABLE: Capture Point mycap enabled.
  2   1.074669 10.172.2.101 -> 192.168.200.5 SNMP 85 get-request 1.3.6.1.2.1.1.3.0
  3   1.075414 192.168.200.5 -> 10.172.2.101 SNMP 89 get-response 1.3.6.1.2.1.1.3.0
  4   4.281646 bc:16:65:13:a4:20 -> bc:16:65:13:a4:20 WLCCP 628 U, func=UI; SNAP, OUI 0x004096 (Cisco Wireless (Aironet) L2), PID 0x0000
  5   4.941556 00:00:00:00:00:00 -> bc:16:65:13:a4:20 802.11 209 Probe Request, SN=0, FN=0, Flags=........
  6   5.099391 10.172.3.220 -> 172.16.14.2  ICMP 444 Destination unreachable (Host administratively prohibited)
  7   5.100384 10.172.3.220 -> 172.16.14.2  DHCP 392 DHCP ACK      - Transaction ID 0x226f
  8   5.281619 bc:16:65:13:a4:20 -> bc:16:65:13:a4:20 WLCCP 292 U, func=UI; SNAP, OUI 0x004096 (Cisco Wireless (Aironet) L2), PID 0x0000
  9   7.937510 00:00:00:00:00:00 -> bc:16:65:13:a4:20 802.11 122 Probe Request, SN=0, FN=0, Flags=........
 10   9.937449 00:00:00:00:00:00 -> bc:16:65:13:a4:20 802.11 122 Probe Request, SN=0, FN=0, Flags=........
 11  10.409798 bc:16:65:13:a4:20 -> bc:16:65:13:a4:20 WLCCP 132 U, func=UI; SNAP, OUI 0x000000 (Encapsulated Ethernet), PID 0x872D
 12  12.437442 00:00:00:00:00:00 -> bc:16:65:13:a4:20 802.11 122 Probe Request, SN=0, FN=0, Flags=........
 13  13.437427 00:00:00:00:00:00 -> bc:16:65:13:a4:20 802.11 122 Probe Request, SN=0, FN=0, Flags=........
 14  14.437384 00:00:00:00:00:00 -> bc:16:65:13:a4:20 802.11 151 Probe Request, SN=0, FN=0, Flags=........
 15  14.525682  172.16.14.2 -> 10.172.4.5   DTLSv1.0 139 Application Data
 16  14.526790   10.172.4.5 -> 172.16.14.2  DTLSv1.0 173 Application Data
 17  14.527259  172.16.14.2 -> 10.172.4.5   DTLSv1.0 139 Application Data
 18  14.527920   10.172.4.5 -> 172.16.14.2  DTLSv1.0 173 Application Data
 19  14.937373 00:00:00:00:00:00 -> bc:16:65:13:a4:20 802.11 122 Probe Request, SN=0, FN=0, Flags=........
 20  17.263991 192.168.200.3 -> 192.168.200.5 LISP 96 Map-Reply for [8189] (null)/48
 21  17.395194 192.168.200.6 -> 192.168.200.5 LISP 96 Map-Reply (RLOC-probe reply) for [8189] (null)/48
 22  18.137466  172.16.11.2 -> 172.16.11.100 TCP 116 49929 b^F^R 80 [SYN] Seq=0 Win=65535 Len=0 MSS=1460 WS=256 SACK_PERM=1
 23  18.397367 192.168.200.6 -> 192.168.200.5 LISP 84 Map-Request (RLOC-probe) for [8189] (null)/48
 24  19.339138 172.16.11.100 -> 172.16.11.2  TCP 116 80 b^F^R 49929 [SYN, ACK] Seq=0 Ack=1 Win=29200 Len=0 MSS=1460 SACK_PERM=1 WS=128
 25  19.339396  172.16.11.2 -> 172.16.11.100 TCP 110 49929 b^F^R 80 [ACK] Seq=1 Ack=1 Win=262144 Len=0
 26  19.340620  172.16.11.2 -> 172.16.11.100 HTTP 442 GET / HTTP/1.1 
 27  19.340773 172.16.11.100 -> 172.16.11.2  TCP 110 80 b^F^R 49929 [ACK] Seq=1 Ack=339 Win=30336 Len=0
<snip>

フィルタの仕方にも色々ですが、IOSコマンドなので...

edge1#show monitor capture file flash:mycap.pcap | i HTTP                 
 26  19.340620  172.16.11.2 -> 172.16.11.100 HTTP 442 GET / HTTP/1.1 
 28  19.341673 172.16.11.100 -> 172.16.11.2  HTTP 723 HTTP/1.1 200 OK  (text/html)

フィルターしたかったのは、クライアントからサーバへのHTTP GETでした(という想定)。この中身を詳しく表示してみます。いい感じですね!ホッとしますね。

edge1#show monitor capture file flash:mycap.pcap packet-number 26 detailed 
Starting the packet display ........ Press Ctrl + Shift + 6 to exit

Frame 26: 442 bytes on wire (3536 bits), 442 bytes captured (3536 bits) on interface 0
    Interface id: 0 (/tmp/epc_ws/wif_to_ts_pipe)
    Encapsulation type: Ethernet (1)
    Arrival Time: May 27, 2020 04:47:14.373329000 UTC
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1590554834.373329000 seconds
    [Time delta from previous captured frame: 0.001224000 seconds]
    [Time delta from previous displayed frame: 0.000000000 seconds]
    [Time since reference or first frame: 19.340620000 seconds]
    Frame Number: 26
    Frame Length: 442 bytes (3536 bits)
    Capture Length: 442 bytes (3536 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:ip:udp:vxlan:eth:ethertype:ip:tcp:http]
Ethernet II, Src: 00:00:00:00:00:00 (00:00:00:00:00:00), Dst: 00:00:00:00:00:00 (00:00:00:00:00:00)
    Destination: 00:00:00:00:00:00 (00:00:00:00:00:00)
        Address: 00:00:00:00:00:00 (00:00:00:00:00:00)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Source: 00:00:00:00:00:00 (00:00:00:00:00:00)
        Address: 00:00:00:00:00:00 (00:00:00:00:00:00)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: IPv4 (0x0800)
Internet Protocol Version 4, Src: 192.168.200.5, Dst: 192.168.200.6
    0100 .... = Version: 4
    .... 0101 = Header Length: 20 bytes (5)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
        0000 00.. = Differentiated Services Codepoint: Default (0)
        .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0)
    Total Length: 428
    Identification: 0x2421 (9249)
    Flags: 0x02 (Don't Fragment)
        0... .... = Reserved bit: Not set
        .1.. .... = Don't fragment: Set
        ..0. .... = More fragments: Not set
    Fragment offset: 0
    Time to live: 255
    Protocol: UDP (17)
    Header checksum: 0x44c2 [validation disabled]
        [Good: False]
        [Bad: False]
    Source: 192.168.200.5
    Destination: 192.168.200.6
User Datagram Protocol, Src Port: 65485 (65485), Dst Port: 4789 (4789)
    Source Port: 65485
    Destination Port: 4789
    Length: 408
    Checksum: 0x0000 (none)
        [Good Checksum: False]
        [Bad Checksum: False]
    [Stream index: 8]
Virtual eXtensible Local Area Network
    Flags: 0x8800, GBP Extension, VXLAN Network ID (VNI)
        1... .... .... .... = GBP Extension: Defined
        .... .... .0.. .... = Don't Learn: False
        .... 1... .... .... = VXLAN Network ID (VNI): True
        .... .... .... 0... = Policy Applied: False
        .000 .000 0.00 .000 = Reserved(R): False
    Group Policy ID: 20
    VXLAN Network Identifier (VNI): 8189
    Reserved: 0
Ethernet II, Src: 00:50:56:af:90:07 (00:50:56:af:90:07), Dst: 00:50:56:a9:88:29 (00:50:56:a9:88:29)
    Destination: 00:50:56:a9:88:29 (00:50:56:a9:88:29)
        Address: 00:50:56:a9:88:29 (00:50:56:a9:88:29)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Source: 00:50:56:af:90:07 (00:50:56:af:90:07)
        Address: 00:50:56:af:90:07 (00:50:56:af:90:07)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: IPv4 (0x0800)
Internet Protocol Version 4, Src: 172.16.11.2, Dst: 172.16.11.100
    0100 .... = Version: 4
    .... 0101 = Header Length: 20 bytes (5)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
        0000 00.. = Differentiated Services Codepoint: Default (0)
        .... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0)
    Total Length: 378
    Identification: 0x5d60 (23904)
    Flags: 0x02 (Don't Fragment)
        0... .... = Reserved bit: Not set
        .1.. .... = Don't fragment: Set
        ..0. .... = More fragments: Not set
    Fragment offset: 0
    Time to live: 128
    Protocol: TCP (6)
    Header checksum: 0x2d97 [validation disabled]
        [Good: False]
        [Bad: False]
    Source: 172.16.11.2
    Destination: 172.16.11.100
Transmission Control Protocol, Src Port: 49929 (49929), Dst Port: 80 (80), Seq: 1, Ack: 1, Len: 338
    Source Port: 49929
    Destination Port: 80
    [Stream index: 0]
    [TCP Segment Len: 338]
    Sequence number: 1    (relative sequence number)
    [Next sequence number: 339    (relative sequence number)]
    Acknowledgment number: 1    (relative ack number)
    Header Length: 20 bytes
    Flags: 0x018 (PSH, ACK)
        000. .... .... = Reserved: Not set
        ...0 .... .... = Nonce: Not set
        .... 0... .... = Congestion Window Reduced (CWR): Not set
        .... .0.. .... = ECN-Echo: Not set
        .... ..0. .... = Urgent: Not set
        .... ...1 .... = Acknowledgment: Set
        .... .... 1... = Push: Set
        .... .... .0.. = Reset: Not set
        .... .... ..0. = Syn: Not set
        .... .... ...0 = Fin: Not set
        [TCP Flags: *******AP***]
    Window size value: 1024
    [Calculated window size: 262144]
    [Window size scaling factor: 256]
    Checksum: 0xa684 [validation disabled]
        [Good Checksum: False]
        [Bad Checksum: False]
    Urgent pointer: 0
    [SEQ/ACK analysis]
        [iRTT: 1.201930000 seconds]
        [Bytes in flight: 338]
Hypertext Transfer Protocol
    GET / HTTP/1.1\r\n
        [Expert Info (Chat/Sequence): GET / HTTP/1.1\r\n]
            [GET / HTTP/1.1\r\n]
            [Severity level: Chat]
            [Group: Sequence]
        Request Method: GET
        Request URI: /
        Request Version: HTTP/1.1
    Accept: text/html, application/xhtml+xml, image/jxr, */*\r\n
    Accept-Language: ja,en-US;q=0.7,en;q=0.3\r\n
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299\r\n
    Accept-Encoding: gzip, deflate\r\n
    Host: 172.16.11.100\r\n
    Connection: Keep-Alive\r\n
    \r\n
    [Full request URI: http://172.16.11.100/]
    [HTTP request 1/1]

さらにIOS的にパイプしてみます。クライアントPCから出て行くHTTP GETが、Catalyst9300から出て行くときのパケットに、VXLANでカプセル化されており、VNID(仮想ネットワークID;いわゆるマクロなセグメンテーション)、Group Policy ID(グループポリシーID;いわゆるマイクロなセグメンテーション)が割り当てられていることが目視できました。

edge1#show monitor capture file flash:mycap.pcap packet-number 26 detailed | i Group Policy|VXLAN 
    Flags: 0x8800, GBP Extension, VXLAN Network ID (VNI)
        .... 1... .... .... = VXLAN Network ID (VNI): True
    Group Policy ID: 20
    VXLAN Network Identifier (VNI): 8189

ダウンロード

さて、コマンドラインで確認した後は、ローカルに保存してWiresharkで開いてみたくなります。手順は色々ありますが、一例をメモしておきます。いろいろアプリケーションを自分のパソコンに入れたくないので、スイッチのflash上にあるPCAPファイルを、自分のTFTPクライアントからダウンロードできるように設定します。

edge1(config)#tftp-server flash:mycap.pcap ?
  <1-99>       IP access list of requesting hosts
  <1300-1999>  IP expanded access list of requesting hosts
  alias        file alias
  <cr>         <cr>

パケットついでに、TFTPもデバッグして目視しておきます。

edge1#terminal monitor
edge1#
edge1#debug tftp ?
  events   TFTP events
  packets  TFTP packets

edge1#debug tftp events
TFTP Event debugging is on
edge1#debug tftp packets
TFTP Packet debugging is on
edge1#
edge1#show debug
DHCP server packet debugging is on.
Packet Infra debugs:

Ip Address                                               Port
------------------------------------------------------|----------

TFTP:
  TFTP Event debugging is on
  TFTP Packet debugging is on
edge1#
edge1#

ここからは自分のMacのターミナルでの操作です。TFTPクライアントでホームディレクトリにパケットを取得し、Wiresharkで開くまでの操作です。

~ $pwd
/Users/kikuta
~ $
~ $ls | grep .pcap
~ $ 
~ $tftp
tftp> connect 10.71.154.103
tftp> mode binary
tftp> get mycap.pcap
Received 17076 bytes in 0.3 seconds
tftp>
~ $
~ $
~ $ls | grep .pcap
mycap.pcap
~ $
~ $wireshark mycap.pcap 

見慣れた画面が出てきました。(Wiresharkはインストール済みの前提です)
スクリーンショット 2020-05-27 14.25.14.png

Command+Gで、当該パケットにたどり着けますので、先ほど調べた26番さんでフィルターします。
スクリーンショット 2020-05-27 14.26.51.png

「表示」メニューで「パケットの一覧を表示」のチェックを外すと、当該パケットだけになります。

スクリーンショット 2020-05-27 14.28.34.png

IOSコマンドで確認したのと同じ内容にたどり着きました。お疲れ様でした。

スクリーンショット 2020-05-27 14.23.20.png

投入したデバッグは、必ずオフにしておきましょう。

edge1#undebug all 
All possible debugging has been turned off
edge1#

スイッチの管理GUIからパケットキャプチャ

さて、ここまで書いておいてアレなんですが、最近のIOS XEの管理GUIにアクセスすると、一連の操作が全部GUIでできるようです。便利になりましたね〜。管理GUIが使えるかどうかは、インストール時の設定やセキュリティポリシーにも依存しますが、もし可能であれば直感的に使えるし役に立つ場合もあるかもしれません。

スクリーンショット 2020-05-27 14.34.14.png

スクリーンショット 2020-05-27 14.34.43.png

スクリーンショット 2020-05-27 14.35.04.png

おわりに

CLI(コマンドラインインターフェース)、GUI(グラフィカルユーザーインターフェース)、API(アプリケーションプログラミングインターフェース)と、それぞれ特徴があって面白いですね。APIやプログラミングもいいですが、たまにはパケットをキャプチャして気分転換もいいですね。

リファレンス

Network Management Configuration Guide, Cisco IOS XE Gibraltar 16.12.x (Catalyst 9300 Switches)

5
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
8