labunix's blog

labunixのラボUnix

ARPのパケットキャプチャについて

■ARPのパケットキャプチャについて
 おそらくWeb上では表示が崩れるだろうけど。。。

.0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|ハードウエア識別番号(0x0001)...|プロトコル(0x0800).............|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|HLEN(0x06).......|PLEN(0x04)...|動作(ARP/RARP).................|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|送信元MACアドレス(6byte).......................................|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|送信元MACアドレス(続き)........|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|送信元IPアドレス(4byte)........................................|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|宛先MACアドレス(6byte).........................................|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|宛先MACアドレス(続き)..........|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|宛先IPアドレス.................................................|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

■概要

ハードウエア識別番号(0x0001)はイーサネット
プロトコル(0x0800)はTCP/IP
HLEN(0x06)はhardware address lengthの略でMACアドレスの長さ
PLEN(0x04)はprotocol address lengthの略で上位プロトコルの長さ(IPv4なら4byte)
動作(ARP/RARP)は4種類

 0x0001 ARP要求。最初にARP要求を送信する側が利用する
 0x0002 ARP応答。ARP要求に該当するコンピュータが応答する場合に利用する
 0x0003 RARP要求。RARP要求を送信する側が利用する
 0x0004 RARP応答。RARP要求をサービスするサーバ(RARPサーバ)が応答する場合に利用する

■自分宛のARP要求とその応答の場合
 ARPヘッダのサイズは28バイトで、イーサネットのデータサイズは461500バイト。
 ARP要求時は18byte分パディングされた後のパケットをキャプチャするが、
 ARP応答時はパディング前のパケットをキャプチャする。

$ sudo tcpdump -i eth0 -n -X -vvv arp

■送信元MAC[SOUR CEMA CADD]と送信元IP[SOUR CEIP]から
 宛先MAC[DEST MACA DDRE]の宛先IP[DEST IPAD]にARP要求をした。

23:25:06.586478 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has [DEST IPAD] tell [SOUR CEIP], length 46
	0x0000:  0001 0800 0604 0001 SOUR CEMA CADD SOUR
	0x0010:  CEIP DEST MACA DDRE DEST IPAD 0000 0000
	0x0020:  0000 0000 0000 0000 0000 0000 0000

■送信元MAC[SOUR CEMA CADD]と送信元IP[SOUR CEIP]から
 宛先MAC[DEST MACA DDRE]の宛先IP[DEST IPAD]にARP応答した。

23:25:06.586531 ARP, Ethernet (len 6), IPv4 (len 4), Reply [SOUR CEIP] is-at [SOUR CEMA CADD], length 28
	0x0000:  0001 0800 0604 0002 SOUR CEMA CADD SOUR
	0x0010:  CEIP DEST MACA DDRE DEST IPAD

■tsharkの場合
 WireSharkのパケット説明をすべて展開したような表示形式で取得する。

$ sudo tshark -i 1 -n -V -Y "arp"

■ARP要求

Frame 131: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
    Interface id: 0 (eth0)
    Encapsulation type: Ethernet (1)
    Arrival Time: Jun 24, 2016 01:13:05.042844000 JST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1466698385.042844000 seconds
    [Time delta from previous captured frame: 4.111058000 seconds]
    [Time delta from previous displayed frame: 0.000000000 seconds]
    [Time since reference or first frame: 52.510153000 seconds]
    Frame Number: 131
    Frame Length: 60 bytes (480 bits)
    Capture Length: 60 bytes (480 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:arp]
Ethernet II, Src: SO:UR:CE:MA:CA:DD (SO:UR:CE:MA:CA:DD), Dst: DE:ST:MA:CA:DD:RE (DE:ST:MA:CA:DD:RE)
    Destination: DE:ST:MA:CA:DD:RE (DE:ST:MA:CA:DD:RE)
        Address: DE:ST:MA:CA:DD:RE (DE:ST:MA:CA:DD:RE)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Source: SO:UR:CE:MA:CA:DD (SO:UR:CE:MA:CA:DD)
        Address: SO:UR:CE:MA:CA:DD (SO:UR:CE:MA:CA:DD)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: ARP (0x0806)
    Padding: 000000000000000000000000000000000000
Address Resolution Protocol (request)
    Hardware type: Ethernet (1)
    Protocol type: IP (0x0800)
    Hardware size: 6
    Protocol size: 4
    Opcode: request (1)
    Sender MAC address: SO:UR:CE:MA:CA:DD (SO:UR:CE:MA:CA:DD)
    Sender IP address: SOUR.CE.IP.ADD (SOUR.CE.IP.ADD)
    Target MAC address: 00:00:00:00:00:00 (00:00:00:00:00:00)
    Target IP address: DEST.IP.ADD.RES (DEST.IP.ADD.RES)

■ARP応答

Frame 132: 42 bytes on wire (336 bits), 42 bytes captured (336 bits) on interface 0
    Interface id: 0 (eth0)
    Encapsulation type: Ethernet (1)
    Arrival Time: Jun 24, 2016 01:13:05.042922000 JST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1466698385.042922000 seconds
    [Time delta from previous captured frame: 0.000078000 seconds]
    [Time delta from previous displayed frame: 0.000078000 seconds]
    [Time since reference or first frame: 52.510231000 seconds]
    Frame Number: 132
    Frame Length: 42 bytes (336 bits)
    Capture Length: 42 bytes (336 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ethertype:arp]
Ethernet II, Src: SO:UR:CE:MA:CA:DD (SO:UR:CE:MA:CA:DD), Dst: DE:ST:MA:CA:DD:RE (DE:ST:MA:CA:DD:RE)
    Destination: DE:ST:MA:CA:DD:RE (DE:ST:MA:CA:DD:RE)
        Address: DE:ST:MA:CA:DD:RE (DE:ST:MA:CA:DD:RE)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Source: SO:UR:CE:MA:CA:DD (SO:UR:CE:MA:CA:DD)
        Address: SO:UR:CE:MA:CA:DD (SO:UR:CE:MA:CA:DD)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: ARP (0x0806)
Address Resolution Protocol (reply)
    Hardware type: Ethernet (1)
    Protocol type: IP (0x0800)
    Hardware size: 6
    Protocol size: 4
    Opcode: reply (2)
    Sender MAC address: SO:UR:CE:MA:CA:DD (SO:UR:CE:MA:CA:DD)
    Sender IP address: SOUR.CE.IP.ADD (SOUR.CE.IP.ADD)
    Target MAC address: DE:ST:MA:CA:DD:RE (DE:ST:MA:CA:DD:RE)
    Target IP address: DEST.IP.ADD.RES (DEST.IP.ADD.RES)

■ARPテーブルのクリアを待っていられない人向け。

$ arping -c 5 -I eth0 DEST.IP.ADD.RES
ARPING DEST.IP.ADD.RES from SOUR.CE.IP.ADD eth0
Unicast reply from DEST.IP.ADD.RES [DE:ST:MA:CA:DD:RE]  0.792ms
Unicast reply from DEST.IP.ADD.RES [DE:ST:MA:CA:DD:RE]  0.872ms
Unicast reply from DEST.IP.ADD.RES [DE:ST:MA:CA:DD:RE]  0.873ms
Unicast reply from DEST.IP.ADD.RES [DE:ST:MA:CA:DD:RE]  0.879ms
Unicast reply from DEST.IP.ADD.RES [DE:ST:MA:CA:DD:RE]  0.872ms
Sent 5 probes (1 broadcast(s))
Received 5 response(s)