1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

パケットキャプチャ 4 dumpcap 使用

Last updated at Posted at 2020-12-08

dumpcap.exe -Dでインターフェースを確認

c:\Program Files\Wireshark>dumpcap.exe -D
1. \Device\NPF_{63B4AEC0-1BD3-481B-B9AB-A0687CB6624E} (繧、繝シ繧オ繝阪ャ繝・
2. \Device\NPF_Loopback (Adapter for loopback traffic capture)

番号でIFを指定できる
#3を指定するとno interfaceでエラーが返ってくる

c:\Program Files\Wireshark>dumpcap.exe -D
1. \Device\NPF_{63B4AEC0-1BD3-481B-B9AB-A0687CB6624E} (繧、繝シ繧オ繝阪ャ繝・
2. \Device\NPF_Loopback (Adapter for loopback traffic capture)

c:\Program Files\Wireshark>dumpcap.exe -w C:\tmp\capture.pcap -b filesize:10 -i 1
Capturing on '繧、繝シ繧オ繝阪ャ繝・
File: C:\tmp\capture_00001_20201208180643.pcap
Packets captured: 13
Packets received/dropped on interface '繧、繝シ繧オ繝阪ャ繝・: 13/0 (pcap:0/dumpcap:0/flushed:0/ps_ifdrop:0) (100.0%)

c:\Program Files\Wireshark>dumpcap.exe -w C:\tmp\capture.pcap -b filesize:10 -i 2
Capturing on 'Adapter for loopback traffic capture'
File: C:\tmp\capture_00001_20201208180650.pcap
Packets captured: 0
Packets received/dropped on interface 'Adapter for loopback traffic capture': 0/0 (pcap:0/dumpcap:0/flushed:0/ps_ifdrop:0) (0.0%)

c:\Program Files\Wireshark>dumpcap.exe -w C:\tmp\capture.pcap -b filesize:10 -i 3
dumpcap: There is no interface with that adapter index

ちなipconfig

c:\Program Files\Wireshark>netsh interface show interface

Admin State    State          Type             Interface Name
-------------------------------------------------------------------------
有効             接続             専用               イーサネット


c:\Program Files\Wireshark>ipconfig

Windows IP 構成


イーサネット アダプター イーサネット:

   接続固有の DNS サフィックス . . . . .: ap-northeast-1.compute.internal
   リンクローカル IPv6 アドレス. . . . .: fe80::65ad:f686:x:x
   IPv4 アドレス . . . . . . . . . . . .: 192.168.x.x
   サブネット マスク . . . . . . . . . .: 255.255.255.224
   デフォルト ゲートウェイ . . . . . . .: 192.168.x.1

Tunnel adapter isatap.ap-northeast-1.compute.internal:

   メディアの状態. . . . . . . . . . . .: メディアは接続されていません
   接続固有の DNS サフィックス . . . . .: ap-northeast-1.compute.internal

Tunnel adapter ローカル エリア接続* 2:

   接続固有の DNS サフィックス . . . . .:
   IPv6 アドレス . . . . . . . . . . . .: 2001:0:348b:fb58:3c62:3b2a:x:x
   リンクローカル IPv6 アドレス. . . . .: fe80::3c62:3b2a:x:x
   デフォルト ゲートウェイ . . . . . . .: ::

-aで実行時間/ローテファイル数/ファイルサイズで自動停止を組める

-a|--autostop
Specify a criterion that specifies when Dumpcap is to stop writing to a capture file. The criterion is of the form test:value, where test is one of:

duration:value Stop writing to a capture file after value seconds have elapsed. Floating point values (e.g. 0.5) are allowed.

files:value Stop writing to capture files after value number of files were written.

filesize:value Stop writing to a capture file after it reaches a size of value kB. If this option is used together with the -b option, dumpcap will stop writing to the current capture file and switch to the next one if filesize is reached. Note that the filesize is limited to a maximum value of 2 GiB.

検証
-a duration:5 指定でちゃんと5秒で止まる
使える場面ありそう

c:\Program Files\Wireshark>dumpcap.exe -w C:\tmp\capture.pcap -b filesize:10 -i 1 -a duration:5
Capturing on '繧、繝シ繧オ繝阪ャ繝・
File: C:\tmp\capture_00001_20201208181300.pcap
Packets captured: 38
Packets received/dropped on interface '繧、繝シ繧オ繝阪ャ繝・: 38/0 (pcap:0/dumpcap:0/flushed:0/ps_ifdrop:0) (100.0%)

キャプチャフィルタを使う
https://wiki.wireshark.org/CaptureFilters#CaptureFilters-1

-iは明示的に指定しない方がいいかな..?
(NICが1個なら自動で認識してくれた方が楽だ)
リファレンスに インターフェイスが指定されていない場合、Dumpcapはインターフェイスのリストを検索し、非ループバックインターフェイスがある場合は最初の非ループバックインターフェイスを選択 って書いてある

-i|--interface |rpcap://:/|TCP@:|-
Set the name of the network interface or pipe to use for live packet capture.

Network interface names should match one of the names listed in "dumpcap -D" (described above); a number, as reported by "dumpcap -D", can also be used. If you're using UNIX, "netstat -i", "ifconfig -a" or "ip link" might also work to list interface names, although not all versions of UNIX support the -a option to ifconfig.

If no interface is specified, Dumpcap searches the list of interfaces, choosing the first non-loopback interface if there are any non-loopback interfaces, and choosing the first loopback interface if there are no non-loopback interfaces. If there are no interfaces at all, Dumpcap reports an error and doesn't start the capture.

Pipe names should be either the name of a FIFO (named pipe) or "-" to read data from the standard input. On Windows systems, pipe names must be of the form "\pipe.\pipename". Data read from pipes must be in standard pcapng or pcap format. Pcapng data must have the same endianness as the capturing host.

This option can occur multiple times. When capturing from multiple interfaces, the capture file will be saved in pcapng format.

....

-i | --interface | rpcap:// : / | TCP @ : |-
ライブパケットキャプチャに使用するネットワークインターフェイスまたはパイプの名前を設定します。

ネットワークインターフェイス名は、「dumpcap-D」(上記)にリストされている名前の1つと一致する必要があります。 「dumpcap-D」で報告されている番号も使用できます。 UNIXを使用している場合、「netstat -i」、「ifconfig -a」、または「ip link」もインターフェイス名を一覧表示するために機能する可能性がありますが、UNIXのすべてのバージョンがifconfigの-aオプションをサポートしているわけではありません。

インターフェイスが指定されていない場合、Dumpcapはインターフェイスのリストを検索し、非ループバックインターフェイスがある場合は最初の非ループバックインターフェイスを選択し、非ループバックインターフェイスがない場合は最初のループバックインターフェイスを選択します。インターフェイスがまったくない場合、Dumpcapはエラーを報告し、キャプチャを開始しません。

パイプ名は、FIFO(名前付きパイプ)の名前か、標準入力からデータを読み取るための「-」のいずれかである必要があります。 Windowsシステムでは、パイプ名は「\ pipe \。\ pipename」の形式である必要があります。パイプから読み取られるデータは、標準のpcapngまたはpcap形式である必要があります。 Pcapngデータは、キャプチャホストと同じエンディアンである必要があります。

このオプションは複数回発生する可能性があります。複数のインターフェースからキャプチャする場合、キャプチャファイルはpcapng形式で保存されます。

次、キャプチャフィルタを使う

c:\Program Files\Wireshark>dumpcap.exe -w C:\tmp\capture.pcap -b filesize:10 -f "port 80"
Capturing on '繧、繝シ繧オ繝阪ャ繝・
File: C:\tmp\capture_00001_20201208182612.pcap
Packets captured: 0
Packets received/dropped on interface '繧、繝シ繧オ繝阪ャ繝・: 0/0 (pcap:0/dumpcap:0/flushed:0/ps_ifdrop:0) (0.0%)

c:\Program Files\Wireshark>dumpcap.exe -w C:\tmp\capture.pcap -b filesize:10 -i 1 -f "port 80"
Capturing on '繧、繝シ繧オ繝阪ャ繝・
File: C:\tmp\capture_00001_20201208182716.pcap
Packets captured: 0
Packets received/dropped on interface '繧、繝シ繧オ繝阪ャ繝・: 0/0 (pcap:0/dumpcap:0/flushed:0/ps_ifdrop:0) (0.0%)

構文自体は-f "port 80"で合ってるようだが、Apacheを起動して、ブラウザからhttp://ローカルのIP (192.168.x.x.) でアクセスしても、IF1 (NIC) でキャプチャされない
ためしにIF2 (ループバック) を指定するとキャプチャできた

c:\Program Files\Wireshark>dumpcap.exe -w C:\tmp\capture.pcap -b filesize:10 -i 2 -f "port 80"
Capturing on 'Adapter for loopback traffic capture'
File: C:\tmp\capture_00001_20201208182701.pcap
Packets captured: 18
Packets received/dropped on interface 'Adapter for loopback traffic capture': 18/0 (pcap:0/dumpcap:0/flushed:0/ps_ifdrop:0) (100.0%)

自分自身のIPを指定してアクセスしたときはループバックアドレスが使われる..????
ローカルのアクセスでも、IPを指定すればNICを経由すると思ってた..

WireSharkでキャプチャしたデータ見ると見事にループバック通信
image.png

ローカルのJavaからローカルのRDBへの通信も、IP指定でもループバック経由になるのか??
(アプリがブラウザでもJavaでもNW部分は透過的にOSの仕組みを使ってるわけだから一緒な気がする..)
キャプチャするときは実際の環境で先に調査したい通信流して、NICとループバックのどちらをキャプチャするか確認した方が良さそう

#DBサーバローカルでDB接続ツールを実行してローカルIPを指定してDBに接続してみた
やはりIF2 (ループバック) しか使われない

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?