はじめに
2015年の末にWiresharkがバージョン2になっていました。
なので公式サイトからダウンロードしてインストールしました。
インストール完了後に init.lua を弄って自作のスクリプトを読み込ませてみた所、以前のバージョンではエラーが無かったLuaスクリプトでエラーが発生しました。
ipprotoが使えない
読み込ませたのは以下のLuaスクリプトです。
ポート:6609番への通信を"ORG_PROT"プロトコルとして表示します。
-- ポート:6609番への通信を"ORG_PROT"プロトコルとしてデコードする
-- Create a new dissector
ORG_PROT = Proto ("ORGNP", "Original Network Protocol")
-- Tables
CONSTANT = {
-- IP Protocols
TCP_PROTOCOL = 6,
UDP_PROTOCOL = 17,
-- Port Number
PORT_NUM = 6609,
}
-- Dissector function
function ORG_PROT.dissector (buffer, pinfo, tree)
-- Add the protocol to the tree
orgnpTree = tree:add (ORG_PROT, buffer())
-- Check whether packet uses TCP or UDP
if ( pinfo.ipproto == CONSTANT.TCP_PROTOCOL) then
-- TCP Packet
debug( "TCP Packet dissector Function" )
elseif ( pinfo.ipproto == CONSTANT.UDP_PROTOCOL) then
-- UDP Packet
debug( "UDP Packet dissector Function" )
end
end
-- UDP with static port
udp_table = DissectorTable.get ("udp.port")
udp_table:add (CONSTANT.PORT_NUM, ORG_PROT)
-- TCP with dynamic port assignment
tcp_table = DissectorTable.get ("tcp.port")
tcp_table:add (CONSTANT.PORT_NUM, ORG_PROT)
実際に読み込んでみたところ以下のエラーが発生しました。
Lua Error: C:\Wireshark\plugins\sample.lua:504: No such 'ipproto' getter attribute/field for object type 'Pinfo'
原因
原因はWiresharkが 2.0 になって ipproto が無くなった為にこのエラーが発生していました。
参照: Wireshark’s Lua API Reference Manual
参考: Wireshark-bugs: [Wireshark-bugs] [Bug 10882] No such 'ipproto'getter attribute/field for object
解決案
ipproto を使用しないでTCPかUDPかを判定するために以下の方法を使いました。
ipprotof = Field.new("ip.proto")
local ipprotostr = tostring( ipprotof() )
local ipproto = tonumber(ipprotostr)
if ( ipproto == CONSTANT.TCP_PROTOCOL ) then
-- TCP Packet
debug( "TCP Packet dissector Function" )
elseif( ipproto == CONSTANT.UDP_PROTOCOL ) then
-- UDP Packet
debug( "UDP Packet dissector Function" )
end
それにしても何でipprotoを無くしたんでしょうかね?