Wireshark(Ethereal)で独自パケットフォーマットを解析する方法
Luaプラグインを使うと、独自パケットフォーマットのパーサーを簡単に定義することができます。
Lua - The Wireshark Wiki
プラグインの有効化
Wiresharkのインストールディレクトリ → init.luaを編集
disable_lua = true; do return end; をコメントアウト -- disable_lua = true; do return end;
run_user_scripts_when_superuser = falseを run_user_scripts_when_superuser = trueに
一番最下行に実行したいluaスクリプトを記述したファイルをWiresharkのインストールディレクトリに置き、dofileで指定する。
dofile("hoge.lua")
以下の例は、プロトコル名をTRIVIALとし、UDPの7777番にきたパケットをサブツリーで分解する例です。
hoge.lua
-- trivial protocol example -- プロトコルの定義 trivial_proto = Proto("trivial","TRIVIAL","Trivial Protocol") -- パース用の関数定義 function trivial_proto.dissector(buffer,pinfo,tree) pinfo.cols.protocol = "TRIVIAL" local subtree = tree:add(trivial_proto,buffer(),"Trivial Protocol Data") subtree:add(buffer(0,2),"The first two bytes: " .. buffer(0,2):uint()) subtree = subtree:add(buffer(2,2),"The next two bytes") subtree:add(buffer(2,1),"The 3rd byte: " .. buffer(2,1):uint()) subtree:add(buffer(3,1),"The 4th byte: " .. buffer(3,1):uint()) end -- udp.portテーブルのロード udp_table = DissectorTable.get("udp.port") -- ポート7777番とプロトコルの紐付けをする udp_table:add(7777,trivial_proto)