👀

WiresharkのMACアドレスを名前解決

2022/06/20に公開

はじめに

Wiresharkでパケット(とかフレーム)を見ているときにこのMACアドレスはどのサーバ、NW機器のものなんだろう、と悩むことはないですか?
私もメモ帳とかにMACアドレスとサーバ名を書いておいて、頭の中でマッピングしながらパケットキャプチャを読むことが多いです。

Wiresharkの画面内でそのマッピングができるようにします。図で説明した方が目的が分かりやすいですね。

↑これを
↓こうする方法です。

やり方

ここにやり方が書いてあります。

https://www.wireshark.org/docs/wsug_html_chunked/ChAppFilesConfigurationSection.html

ethers
When Wireshark is trying to translate a hardware MAC address to a name, it consults the ethers file in the personal configuration folder first. If the address is not found in that file, Wireshark consults the ethers file in the system configuration folder.

This file has the same format as the /etc/ethers file on some Unix-like systems. Each line in these files consists of one hardware address and name separated by whitespace. The digits of hardware addresses are separated by colons (:), dashes (-) or periods(.). The following are some examples:

ff-ff-ff-ff-ff-ff Broadcast
c0-00-ff-ff-ff-ff TR_broadcast
00.2b.08.93.4b.a1 Freds_machine
The settings from this file are read in when a MAC address is to be translated to a name, and never written by Wireshark.

(意訳)ethersっていうファイルにマッピングをかけばいいよ。

On Windows:

The personal configuration folder for Wireshark is the Wireshark sub-folder of that folder, i.e., %APPDATA%\Wireshark.
The global configuration folder for Wireshark is the Wireshark program folder and is also used as the system configuration folder.
On Unix-like systems:

The personal configuration folder is $XDG_CONFIG_HOME/wireshark. For backwards compatibility with Wireshark before 2.2, if $XDG_CONFIG_HOME/wireshark does not exist and $HOME/.wireshark is present, then the latter will be used.
If you are using macOS and you are running a copy of Wireshark installed as an application bundle, the global configuration folder is APPDIR/Contents/Resources/share/wireshark. Otherwise, the global configuration folder is INSTALLDIR/share/wireshark.
The /etc folder is the system configuration folder. The folder actually used on your system may vary, maybe something like: /usr/local/etc.

(意訳)ethersは%APPDATA%\Wiresharkに置けばいいよ。

以下の環境のMACアドレスを名前解決してみます。

https://zenn.dev/takai404/articles/70c554c4a0de45

以下のコマンドで

  • Windowsのユーザ名をWSL取得(APPDATAフォルダの場所を知るため)
  • 収集したMACアドレスとBridge、NIC名マッピングを%APPDATA%/Wireshark/ethersに書き込む
    • ip linkコマンドでデフォルトネームスペースのBridge、NIC名とMACアドレスのマッピングを取得
    • 各ネットワークネームスペースで同様のマッピングを取得。(ネットワークネームスペースが異なると同じ名前のNICが存在しうるので)NIC名の先頭にはネームスペース名を付与。
winusername=`cmd.exe /C 'echo %USERNAME%' | tr -d '\015'`
(ip -br link; for ns in `ip netns | awk '{print $1}'`; do ip netns exec $ns ip -br link | sed -e "s/^/$ns-/"; done) | sed -n -e 's/^\([^@ ]\+\).*\([0-9a-fA-F:]\{17\}\).*/\2 \1/p' | tee /mnt/c/Users/$winusername/AppData/Roaming/Wireshark/ethers

上記のコマンドで以下のファイルができます。コマンドを使わなくても、手動で以下のように「MACアドレス、スペース、ホスト名」が並んだテキストファイルを作ってあげればOKです。

%APPDATA%\Wireshark\ethers
00:00:00:00:00:00 lo
fe:e4:70:76:03:c9 bond0
6e:f9:44:56:77:18 dummy0
00:15:5d:d5:5e:c9 eth0
26:4b:c9:95:0e:e0 core2_e0
c2:67:12:ab:9a:a1 core1_e0
d2:62:ef:5b:0d:85 access1_e1
6a:78:dc:b8:0a:3d core1_e1
06:6e:04:36:2e:c5 access3_e1
ba:53:6c:3a:f2:a6 core1_e2
ee:7a:38:59:e8:35 access2_e1
8e:ec:ba:e3:d8:e2 core2_e1
96:e6:22:86:7c:86 access4_e1
32:8e:62:9d:2f:1f core2_e2
ce:3f:e7:b8:99:02 access2_e0
52:65:55:a4:d6:45 access1_e0
5e:31:05:90:b1:0c access4_e0
fe:53:e0:d3:ad:0a access3_e0
32:c8:70:0d:8a:30 access1_e2
3e:cc:33:fc:df:10 access2_e2
0a:87:a3:48:e2:4a access3_e2
42:bf:cd:48:42:30 access4_e2
6a:78:dc:b8:0a:3d core1
26:4b:c9:95:0e:e0 core2
32:c8:70:0d:8a:30 access1
3e:cc:33:fc:df:10 access2
06:6e:04:36:2e:c5 access3
42:bf:cd:48:42:30 access4
00:00:00:00:00:00 pc4-lo
1e:50:30:f1:e4:3a pc4-eth0
00:00:00:00:00:00 pc3-lo
42:e1:2f:33:36:1b pc3-eth0
00:00:00:00:00:00 pc2-lo
fa:1f:2f:06:68:8f pc2-eth0
00:00:00:00:00:00 pc1-lo
06:3b:88:6b:b8:35 pc1-eth0

パケットNo.2のようにIPパケットであれば下半分のペインでイーサネットヘッダのMACアドレスがホスト名に変換されています。
パケットNo.3のようにL2のフレームであれば上のペインでも名前解決されます。

Discussion