wireshark dissector with lua

Similar documents
【注意事項】RXファミリ 組み込み用TCP/IP M3S-T4-Tiny

24th Embarcadero Developer Camp

PowerPoint プレゼンテーション

構造体

サーバセキュリティサービスアップグレード手順書 Deep Security 9.6SP1 (Windows) NEC 第 1 版 2017/08/23

HeartCoreインストールマニュアル(PHP版)

pgen :: net_stream net (" eth0 ", pgen :: open_mode :: netif ); uint8_t buf [10000]; size_t recvlen = net. recv (buf, sizeof buf ); pgen :: udp pack (

intra-mart Accel Platform — IM-共通マスタ スマートフォン拡張プログラミングガイド   初版  

SDC_SDIO_STM32F4 の説明 2013/09/17 SDIO インターフェースで SD カードをアクセスするプログラムのプロジェクトサンプルです FAT でファイルアクセスするために FatFs( 汎用 FAT ファイルシステム モジュール ) を使用しています VCP(USB 仮想 C

プログラミングI第10回

(Microsoft Word - FireWall\202\314\227\341\212O\220\335\222\350\202\360\215s\202\244.doc)

HeartCoreインストールマニュアル

untitled

PowerPoint プレゼンテーション

新コンフィギュレータのフレームワークについて

memo

株式会社日新テクニカ USB シリアル CAN 変換器 /8/22 ホームページ : メール

Microsoft Word combine.doc

XAMPP で CMS のお手軽 テスト環境を手に入れよう 2011/5/21 上村崇 1

サーバセキュリティサービス 導入手順書 Deep Security 9.5SP1 (Windows) プロキシ経由編

Sophos Enterprise Console

CashDrawer ライブラリ API 仕様書 2014/07/09 CashDrawer ライブラリ API 仕様書 Rev / 10

Microsoft Word - DWR-S01D_Updater_取扱説明書_120514A.doc

DWR-S01D Updater 取扱説明書 発行日 :2011/2/28

03 Podium Walkerのインストール方法およびアンインストール .docx

ColdFusion Builder インストール

HeartCore(PHP 版 ) インストール手順について説明いたします なお 本資料は 例として下記内容を前提として説明しております 環境情報 対象 OS: Linux ( ディストリビューション : Red Hat Enterprise Linux Server) APサーバ : Apache

Undestand の解析 Understand の C 言語で抽出できない依存関係について サンプルコードを用いて説明します 確認バージョン Understand 3.0 (Build 640) Understand 3.1 (Build 700) Understand 4.0 (Build 78

Android Layout SDK プログラミング マニュアル

Microsoft Word - PCOMM V6.0_FAQ.doc

untitled

Red Hat Enterprise Linux 6 Portable SUSE Linux Enterprise Server 9 Portable SUSE Linux Enterprise Server 10 Portable SUSE Linux Enterprise Server 11 P

Plano-POS Ver1

untitled

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

Microsoft PowerPoint - CproNt02.ppt [互換モード]

03 Podium Walkerのインストール方法およびアンインストール .docx

テンプレートエンジンの必要性 昔 (2000 年ごろ?) の典型的な PHP のコード : <?php // 処理?> <html> <body> <?php print("hello World!");?> </body> </html> 以下のような問題で衝突していた 1 一旦プログラムコードを

セゾン保険_PDF用.indd

Total Disc Makerサイレントインストールガイド

Java知識テスト問題

Release Note for Media File Player v1.6.3 (Japanese)

kiso2-03.key

Parametric Polymorphism

目次 1. 変換の対象 砂防指定地 XML 作成メニュー シェープファイルからXMLへ変換 砂防指定地 XMLとシェープファイルの対応.csv 変換処理 CSVファイルによる属性指定... 5

らくらくメニューVer2.70E9<セットアップガイド>

MX705110A Wi-SUN プロトコルモニタ 製品紹介

NGSハンズオン講習会

WebReportCafe

Microsoft Word - CygwinでPython.docx

(Microsoft Word - \203C\203\223\203X\203g\201[\203\213\203}\203j\203\205\203A\203\213version1.0 rev1.doc)

untitled

03 Podium Walkerのインストール方法およびアンインストール .docx

Fortinet社

1

BACREX-R クライアント利用者用ドキュメント

intra-mart e-Builder ver 5

Microsoft Word - LM A_SNMP_Cacti_ConfigureV5.doc

<4D F736F F D ED CC4C6F67696E20936F985E95FB964082C B838B A

RTC_STM32F4 の説明 2013/10/20 STM32F4 内蔵 RTC の日付 時刻の設定および読み込みを行うプログラムです UART2( 非同期シリアル通信ポート 2) を使用して RTC の設定および読み込みを行います 無料の開発ツール Atollic TrueSTUDIO for

Athena の起動 デスクトップ上の Athena のアイコンをダブルクリックする もしくは スタートメニューのプロ グラム一覧から Demeter with Strawberry Pert 内の Athena をクリックする デスクトップ上のアイコン スタートメニューのプログラム一覧 プラグイン

Complex Lab – Operating Systems - Graphical Console

EPSON Offirio SynergyWare PrintDirector 取扱説明書 導入ガイド

C 資料 電脳梁山泊烏賊塾 ファイルの入出力 C++ のバイナリファイル入出力 初めに 此処では Visual Studio 2017 を起動し 新しいプロジェクトで Visual C++ の Windows デスクトップを選択し Windows コンソールアプリケーションを作成する

<4D F736F F D B B83578B6594BB2D834A836F815B82D082C88C60202E646F63>

fp.gby

ソフトウェアライセンスの更新手順 Microsoft Windows版SAS 9.3 Foundation

Flash Loader

Transcription:

2013/06/05 @team_eririn https://www.ainoniwa.net/ssp/

Lua プラグインを用いて Wireshark にデコード可能なプロトコルを追加する手法について記載します 今回は ネットワークベンチマークソフトウェアである iperf パケットを題材にします 2

OS Windows XP, Vista, 7 Wireshark Version : 1.6.x or 1.8.x http://www.wireshark.org/download.html iperf Version : 2.0.5 http://sourceforge.jp/projects/sfnet_iperf/ 3

Windows を主な対象として記載しているものの Lua による Plugin 作成に関しては Wireshark を利用する Windows 以外の各種 OS で共通です 資料中では Wireshark 1.6 系をベースに記載しているため 1.8 系と細部が異なる可能性があります 4

5

Help -> About Wireshark "with Lua 5.1" のように表記があれば OK Windows はデフォルトで有効 6

A もしくは B の方法を選択します 本資料は A にて進行します A) ${wireshark_install_dir}/plugins/${wireshark_version}/ に *.lua ファイルを置く 例 ) C: Program Files Wireshark plugins 1.6.14 iperf.lua wireshark をバージョンアップすると ${wireshark_version} は消えるので 作成中などは注意 B) ${wireshark_install_dir}/init.lua に 以下のように書き加える dofile(data_dir.. your_script.lua ) 7

${wireshark_install_dir}/init.lua の中で disable_lua = true という記載がある場合は 以下のように変更します disable_lua = false または -- disable_lua = true 古い Wireshark の場合 ( もしくは Linux パッケージのポリシーに基づく場合 ) は 上記の記載が残っている可能性があります 8

1. 作ります ( ) hello.lua local hello_lua = "Hello." Shift-JISでないと動作しない可能性があります 2. 置きます 9

Help -> About Wireshark -> Plugins これ 見える? 10

11

必要となる知識 デコード対象プロトコルの構造体に対する知識 今回は iperf になります lua プラグインの wireshark での作法 12

本資料では iperf プロトコルを全部解剖して解説するなんてことはしません 極々限られた範囲のみをデコード出来るようにして とりあえずの達成感を得ましょう 13

1. wireshark を起動して適当なインタフェースでキャプチャ開始 2. iperf -c 192.168.122.150 -u 3. wireshark で検体を保存 14

以下の条件で進行します UDP のペイロード先頭部位のみ つまり以下の部分 iperf-2.0.5 include Settings.hpp // line : 292-304 // used to reference the 4 byte ID number we place in UDP datagrams // use int32_t if possible, otherwise a 32 bit bitfield (e.g. on J90) typedef struct UDP_datagram { #ifdef HAVE_INT32_T int32_t id; u_int32_t tv_sec; u_int32_t tv_usec; #else signed int id : 32; unsigned int tv_sec : 32; unsigned int tv_usec : 32; #endif } UDP_datagram; 15

この辺 (Hex View 参照 ) u_int32_t tv_usec; int32_t id; u_int32_t tv_sec; 16

iperf のデフォルトポート番号は 5001(TCP/UDP 両方 ) iperf のデータグラムの先頭は 以下のフォーマット 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 id tv_sec tv_usec iperf のプロトコルフォーマットを少しかじったところで wireshark の lua プラグインのお作法へ 17

1. プロトコルの宣言 2. フィールドの宣言 3. 実際のデータ処理 4. プロトコルツリーへの追加 5. プロトコルの登録 18

基本のステップはこれだけ (-- はコメントアウト ) -- *** Step 1 : プロトコルの宣言 *** iperf_proto = Proto("iperf","Iperf UDP packet") -- *** Step 2 : フィールドの宣言 *** iperf_seq_f = ProtoField.uint32("iperf.seq", "Iperf sequence") iperf_proto.fields = {iperf_seq_f} function iperf_proto.dissector(buffer,pinfo,tree) -- *** Step 3 : 実際のデータ処理 *** local iperf_seq_range = buffer(0,4) local iperf_seq = iperf_seq_range:uint() -- *** Step 4 : プロトコルツリーに追加 *** local subtree = tree:add(iperf_proto, buffer(), "Iperf packet data") subtree:add(iperf_seq_f, iperf_seq_range, iperf_seq) end -- *** Step 5 : プロトコルの登録 *** DissectorTable.get("udp.port"):add(5001, iperf_proto) ファイルに保存して plugins ディレクトリに置く 19

ごく自然にフィルタも書けるようになる ただの Data は Iperf sequence に 20

さっきの基本ステップに書き足していく ( 赤字部 ) -- *** Step 1 : プロトコルの宣言 *** iperf_proto = Proto("iperf","Iperf UDP packet") -- *** Step 2 : フィールドの宣言 *** iperf_seq_f = ProtoField.uint32("iperf.seq", "Iperf sequence") iperf_sec_f = ProtoField.uint32("iperf.sec", "Iperf sec") iperf_usec_f = ProtoField.uint32("iperf.usec", "Iperf usec") iperf_proto.fields = {iperf_seq_f, iperf_sec_f, iperf_usec_f } function iperf_proto.dissector(buffer,pinfo,tree) -- *** Step 3 : 実際のデータ処理 *** local iperf_seq_range = buffer(0,4) local iperf_sec_range = buffer(4,4) local iperf_usec_range = buffer(8,4) local iperf_seq = iperf_seq_range:uint() local iperf_sec = iperf_sec_range:uint() local iperf_usec = iperf_usec_range:uint() -- *** Step 4 : プロトコルツリーに追加 *** local subtree = tree:add(iperf_proto, buffer(), "Iperf packet data") subtree:add(iperf_seq_f, iperf_seq_range, iperf_seq) subtree:add(iperf_sec_f, iperf_sec_range, iperf_sec) subtree:add(iperf_usec_f, iperf_usec_range, iperf_usec) end -- *** Step 5 : プロトコルの登録 *** DissectorTable.get("udp.port"):add(5001, iperf_proto) 21

22

iperf(udp) のシーケンス番号 タイムスタンプがデコードできるようになったよ! 23

24

A. Data をツリーに追加していないので見えません 必要であれば Wireshark の Data Dissector に再度残ったデータを入れることで 一般的な表現形に戻すことができます 赤字部を追加 -- 前略 -- *** Step 3 : 実際のデータ処理 *** local iperf_seq_range = buffer(0,4) local iperf_sec_range = buffer(4,4) local iperf_usec_range = buffer(8,4) local iperf_seq = iperf_seq_range:uint() local iperf_sec = iperf_sec_range:uint() local iperf_usec = iperf_usec_range:uint() -- *** Step 4 : プロトコルツリーに追加 *** local subtree = tree:add(iperf_proto, buffer(), "Iperf packet data") subtree:add(iperf_seq_f, iperf_seq_range, iperf_seq) subtree:add(iperf_sec_f, iperf_sec_range, iperf_sec) subtree:add(iperf_usec_f, iperf_usec_range, iperf_usec) Dissector.get("data"):call(buffer(12,buffer:len()-12):tvb(), pinfo, tree) -- 以下略 25

Data ツリーが元通り 26

A. できます 単に bit の値を切り出したい場合 local iperf_seq = iperf_seq_range:bitfield(30,2) Tree に追加するためのフィールド宣言 iperf_flag_bit_f = ProtoField.uint32("iperf.flag_bit","bit", base.hex, None, 0x00008000) Tree に実際追加する場合 subflagatree:add(iperf_flag_bit_f, iperf_flags_range, iperf_flags) 第一引数のフィールド指定以外は 参照元の値を使う 27

-- *** Step 1 : プロトコルの宣言 *** iperf_proto = Proto("iperf","Iperf UDP packet") -- *** Step 2 : フィールドの宣言 *** iperf_seq_f = ProtoField.uint32("iperf.seq", "Iperf sequence") iperf_sec_f = ProtoField.uint32("iperf.sec", "Iperf sec") iperf_usec_f = ProtoField.uint32("iperf.usec", "Iperf usec") local VALS_BOOL = {[0] = "False", [1] = "True"} iperf_flag_bit_f = ProtoField.uint32("iperf.flag_bit","bit", base.hex, VALS_BOOL, 0x00000001) iperf_proto.fields = {iperf_seq_f, iperf_sec_f, iperf_usec_f, iperf_flag_bit_f } function iperf_proto.dissector(buffer,pinfo,tree) -- *** Step 3 : 実際のデータ処理 *** local iperf_seq_range = buffer(0,4) local iperf_sec_range = buffer(4,4) local iperf_usec_range = buffer(8,4) local iperf_seq = iperf_seq_range:uint() local iperf_sec = iperf_sec_range:uint() local iperf_usec = iperf_usec_range:uint() -- *** Step 4 : プロトコルツリーに追加 *** local subtree = tree:add(iperf_proto, buffer(), "Iperf packet data") --subtree:add(iperf_seq_f, iperf_seq_range, iperf_seq) local subflagatree = subtree:add(iperf_seq_f, iperf_seq_range, iperf_seq) subflagatree:add(iperf_flag_bit_f, iperf_seq_range, iperf_seq) subtree:add(iperf_sec_f, iperf_sec_range, iperf_sec) subtree:add(iperf_usec_f, iperf_usec_range, iperf_usec) Dissector.get("data"):call(buffer(12,buffer:len()-12):tvb(), pinfo, tree) end -- *** Step 5 : プロトコルの登録 *** DissectorTable.get("udp.port"):add(5001, iperf_proto) 28

末尾の bit を可視化 29

A. 使えます Tree にアイテムを追加する際は Item オブジェクト SubTree を追加する際は Tree オブジェクトが返ってくるので それぞれに設定する Item の場合 bit_item:add_expert_info(pi_malformed, PI_WARN, 'seq bit on') Tree の場合 subtree:set_expert_flags(pi_malformed, PI_WARN) 詳しくはこの辺のドキュメントを見る http://www.wireshark.org/docs/wsug_html_chunked/lua_m odule_tree.html#lua_fn_treeitem_set_expert_flags group severity 30

iperf_proto = Proto("iperf","Iperf UDP packet") iperf_seq_f = ProtoField.uint32("iperf.seq", "Iperf sequence") iperf_sec_f = ProtoField.uint32("iperf.sec", "Iperf sec") iperf_usec_f = ProtoField.uint32("iperf.usec", "Iperf usec") iperf_flag_bit_f = ProtoField.uint32("iperf.flag_bit","bit", base.hex, None, 0x00000001) iperf_proto.fields = {iperf_seq_f, iperf_sec_f, iperf_usec_f, iperf_flag_bit_f } function iperf_proto.dissector(buffer,pinfo,tree) local iperf_seq_range = buffer(0,4) local iperf_sec_range = buffer(4,4) local iperf_usec_range = buffer(8,4) local iperf_seq = iperf_seq_range:uint() local iperf_bit = iperf_seq_range:bitfield(31,1) local iperf_sec = iperf_sec_range:uint() local iperf_usec = iperf_usec_range:uint() local subtree = tree:add(iperf_proto, buffer(), "Iperf packet data") local subflagatree = subtree:add(iperf_seq_f, iperf_seq_range, iperf_seq) bit_item = subflagatree:add(iperf_flag_bit_f, iperf_seq_range, iperf_seq) if iperf_bit == 1 then subtree:set_expert_flags(pi_malformed, PI_WARN) bit_item:add_expert_info(pi_malformed, PI_WARN, 'seq bit on') end subtree:add(iperf_sec_f, iperf_sec_range, iperf_sec) subtree:add(iperf_usec_f, iperf_usec_range, iperf_usec) end DissectorTable.get("udp.port"):add(5001, iperf_proto) 31

Expert Infos は Analyze -> Expert Info Composite から表示できます 末尾の bit が 1 の時 Warning にしてしまう 32

Chapter 11. Lua Support in Wireshark http://www.wireshark.org/docs/wsug_html_chunked/w sluarm.html 33