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

tsharkで解析

0
Posted at

tsharkが必要だった

Wiresharkで取得したデータにて、特定条件にあてはまるパケットの全てのデータ(IPパケット)サイズを、Wiresharkで確認しようとしたが、メニューに見つからず。調べたところ、tsharkで実現できることが判明。関連事項も含めた小ネタである。

参考URL

非常にためになるサイトである。

実際のところ+α

実例をいくつか下記。

IPパケットサイズ(本来の目的)

% tshark -r testdata.pcapng -Y tcp -T fields -e ip.len | head -5
1452
1452
1452
202
309
  • -r: 読み込むキャプチャデータ
  • -Y: フィルター(Wiresharkの表示フィルタと同じらしい)
    • この例ではTCPを対象
  • -T: フィールドで出力
  • -e: フィールド出力時に対象とするもの
    • この例ではIPパケットサイズ

上記のような出力となるので、TCPパケットのIPパケットサイズの合計は、awkを使って、下記で求められる。

% tshark -r testdata.pcapng -Y tcp -T fields -e ip.len | awk '{sum+=$1} END{print sum}'
79077853

他にもあります

その他、tsharkによる解析に役立ちそうな内容を紹介。ほぼ、個人的なメモである。

単なる読み込み(-rオプションのみ)

標準出力は下記となる。

% tshark -r testdata.pcapng| head -3
    1   0.000000 192.168.10.104 → 142.250.207.46 SSL 1466 
    2   0.000014 192.168.10.104 → 142.250.207.46 TCP 1466 49312 → 443 [ACK] Seq=1401 Ack=1 Win=2048 Len=1400 TSval=3757587655 TSecr=2257172828
    3   0.000016 192.168.10.104 → 142.250.207.46 TCP 1466 49312 → 443 [ACK] Seq=2801 Ack=1 Win=2048 Len=1400 TSval=3757587655 TSecr=2257172828

大まかなパケット種別。

データ数。

% tshark -r testdata.pcapng  | wc -l  
   78538

IPv6パケット数。

% tshark -r testdata.pcapng -Y ipv6 | wc -l
    1405

IPパケット数。

% tshark -r testdata.pcapng -Y ip | wc -l
   77098

ARPパケット数。

% tshark -r testdata.pcapng -Y arp | wc -l
      35

IPパケット以外の数。

% tshark -r testdata.pcapng -Y "not ip" | wc -l
    1440

1440 = 1405 + 35
78538 = 1440 + 77098

データ(レイヤ)構造

% tshark -r testdata.pcapng -T fields -e frame.protocols | tail
eth:ethertype:ip:tcp:tls
eth:ethertype:ip:tcp
eth:ethertype:ip:udp:mdns
eth:ethertype:ipv6:udp:mdns
eth:ethertype:ip:udp:mdns
eth:ethertype:ip:udp:mdns
eth:ethertype:ipv6:udp:mdns
eth:ethertype:ipv6:udp:dns
eth:ethertype:ip:udp:data
eth:ethertype:ip:udp:data

特定UDPポートのUDPサイズ

% tshark -r testdata.pcapng -Y 'udp.port == 443' -T fields -e udp.length

IPパケットの全てのサイズ(Ethernetフレーム含めて)

% tshark -r testdata.pcapng -Y ip -T fields -e frame.len

終わりに

パイプとの組み合わせが容易なCLIベースのコマンドは何かと便利である。うまく使い分けることが重要。tsharkも奥が深そう。

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