LoginSignup
5
5

More than 1 year has passed since last update.

WiresharkのUSBPcapのログの見方

Last updated at Posted at 2019-08-11

Windows 7のWireshark 3.0.3で試してみました。以前インストールしたものがなぜか動かなくなっていたので、一回アプリを消して再インストールしました。

メインウインドでURB setupを開いた状態にしてFileメニューのExport Packet DissectionでAs Plan Textを選んでPacket detailsにチェックを入れてAs displayedで保存しました。ちょっと分かりづらい気がします。

通常の解析ではアイソクロナス通信は不要なのでコントロール転送だけを保存したい場合は、filterでusb.src=="7.5.0"||usb.dst="7.5.0"のようにします。""で囲む必要があるのが分かるのに一日かかりました。。。

コントロール転送でデバイスからデータの読み込み

No.     Time           Source                Destination           Protocol Length Info
      1 0.000000       host                  7.5.0                 USB      36     URB_CONTROL in

Frame 1: 36 bytes on wire (288 bits), 36 bytes captured (288 bits) on interface 0
USB URB
URB setup
    bmRequestType: 0xc0
    bRequest: 0
    wValue: 0x0000
    wIndex: 15 (0x000f)
    wLength: 1

No.     Time           Source                Destination           Protocol Length Info
      2 0.000000       7.5.0                 host                  USB      29     URB_CONTROL in

Frame 2: 29 bytes on wire (232 bits), 29 bytes captured (232 bits) on interface 0
USB URB
CONTROL response data: 07

No.     Time           Source                Destination           Protocol Length Info
      3 0.000000       7.5.0                 host                  USB      28     GET STATUS Status

Frame 3: 28 bytes on wire (224 bits), 28 bytes captured (224 bits) on interface 0
USB URB

Frame 2がデバイスからの返答です。

コントロール転送でデバイスへのデータの書き込み

No.     Time           Source                Destination           Protocol Length Info
      4 0.000000       host                  7.5.0                 USB      36     URB_CONTROL out

Frame 4: 36 bytes on wire (288 bits), 36 bytes captured (288 bits) on interface 0
USB URB
URB setup
    bmRequestType: 0x40
    bRequest: 0
    wValue: 0x0000
    wIndex: 15 (0x000f)
    wLength: 1

No.     Time           Source                Destination           Protocol Length Info
      5 0.000000       host                  7.5.0                 USB      29     URB_CONTROL out

Frame 5: 29 bytes on wire (232 bits), 29 bytes captured (232 bits) on interface 0
USB URB
Leftover Capture Data: 07

No.     Time           Source                Destination           Protocol Length Info
      6 0.000000       7.5.0                 host                  USB      28     GET STATUS Status

Frame 6: 28 bytes on wire (224 bits), 28 bytes captured (224 bits) on interface 0
USB URB

Frame 5をデバイスに書き込んでいます。

このケースでは読んだデータと同じものを書き込んでいますが、プログラムではビットのorをとって書き込んでるんじゃないかと考えられます。

awkスクリプトで見やすくしてみました。

/URB_CONTROL/ {DIR=$8;gsub(".$","",DIR)}
/bRequest/ {REQ=$2;gsub(".$","",REQ)}
/wIndex/ {IDX=substr($3,2,6)}
/wLength/ {LEN=$2;gsub(".$","",LEN)}
/(CONTROL response data)|(Leftover Capture Data)/ {
DATA=""
for (I = 0; I < LEN; ++I) {
BYTE=substr($4, I*2+1, 2);DATA=DATA"0x"BYTE;if (I != LEN -1) {DATA=DATA","}}
print DIR","REQ","IDX","LEN","DATA
}
in,0,0x000f,1,0x07
out,0,0x000f,1,0x07

これをsed 's/out/0/;s/in/1/;s/$/,/'してバイナリ配列にしてプログラムに組み込み、リプレイ攻撃するのも有効です。

v3.2.1で試したら、outのデータが同じフレームに入っていました。ドライバーの作り方によるものなのか、Wiresharkなどのバージョンによるものなのかは不明です。

No.     Time           Source                Destination           Protocol Length Info
     29 0.062400       host                  5.1.0                 USB      37     URB_CONTROL out

Frame 29: 37 bytes on wire (296 bits), 37 bytes captured (296 bits) on interface wireshark_extcap972, id 0
USB URB
Setup Data
    bmRequestType: 0x40
    bRequest: 0
    wValue: 0x0000
    wIndex: 13 (0x000d)
    wLength: 1
    Data Fragment: ff
5
5
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
5