add create expample dissector

This commit is contained in:
stubbfel
2017-06-18 01:47:57 +02:00
parent 77db58f8ee
commit 1265ae90f0
6 changed files with 100 additions and 10 deletions

View File

@@ -2,5 +2,5 @@
["blob_src"] = "/path/to/blob-file",
["eth_fake_header_src"] = "00 00 00 00 00 00",
["eth_fake_header_dst"] = "11 11 11 11 11 11",
["eth_fake_header_type"] = "47 11"
["eth_fake_header_type"] = "4711"
}

View File

@@ -1,12 +1,22 @@
module("b2ws_const")
B2WS_PLUGIN_PATH = "plugins/b2ws-plugin/"
B2WS_IMPORT_BLOB_FILE = "b2ws_import.lua"
B2WS_UTIL_FILE = "b2ws_util.lua"
B2WS_DISSECTOR_TEMPLATE_FILE = "b2ws_dissector.template"
B2WS_DISSECTOR_EXTENSION= ".dissector.lua"
B2WS_PLUGIN_CONFIG_FILE_NAME = "b2ws.config"
B2WS_IMPORT_BLOB_MENU_TITLE = "b2ws/Import Blob"
B2WS_IMPORT_BLOB_BTN_TITLE = "Import Blob"
B2WS_SAVE_SETTINGS_BTN_TITLE = "Save Current Settings"
B2WS_SAVE_DISSECTOR_BTN_TITLE = "Save Dissector"
B2WS_SHOW_DISSECTOR_BTN_TITLE = "Show Dissector"
B2WS_SHOW_DISSECTOR_WIN_TITLE = "Created Dissector"
B2WS_CHANGE_SETTINGS_BTN_TITLE = "Change Settings"
B2WS_CREATE_DISSECTOR_BTN_TITLE = "Create Dissector"
B2WS_CHANGE_SETTINGS_DLG_TITLE = "Change Settings"
B2WS_IMPORT_BLOB_WIN_TITLE = "Import Blob"
B2WS_RELOAD_PLUGIN_WIN_TITLE = "Please reload plugin"
B2WS_RELOAD_PLUGIN_WIN_CONTENT = "Dissector created at {0}\nBefore using please reload plugin:\n\tAnalyze -> Reload Lua Plugin (qt version only) or restart wireshark"
B2WS_CONFIG_LABEL_BLOB_SRC = "Blob file path"
B2WS_CONFIG_LABEL_ETH_FAKE_HEADER_SRC = "fake eth src address"
B2WS_CONFIG_LABEL_ETH_FAKE_HEADER_DST = "fake eth dst address"

View File

@@ -0,0 +1,50 @@
-- from http://torsten-traenkner.de/linux/development/wireshark.php
--
-- Example Protocol Wireshark dissector (a.k.a. decoder)
-- Author: Torsten Traenkner
-- Version History:
-- 0.01 (02.04.2015)
--
-- This dissector decodes an example protocol.
--
-- use with:
-- wireshark -Xlua_script:example.lua example.pcap
--
do
local example_tree = 0
-- #####################
-- ## Example Layer 1 ##
-- #####################
example_layer_1 = Proto("example_layer", "exampleProtocol layer1")
local example_layer_1_fields = example_layer_1.fields
example_layer_1_fields.field1 = ProtoField.uint8("exampleProtocol_layer1.field1", "field 1", base.DEC)
example_layer_1_fields.field2 = ProtoField.uint8("exampleProtocol_layer1.field2", "field 2", base.HEX)
function example_layer_1.dissector(buffer, packet_info, tree)
example_layer_1_tree = tree:add(example_layer_1, buffer(0, 2))
example_layer_1_tree:add(example_layer_1_fields.field1, buffer(0, 1))
example_layer_1_tree:add(example_layer_1_fields.field1, buffer(1, 1))
-- do something
end
-- #########################################
-- ## example protocol all layers chained ##
-- #########################################
example_protocol = Proto("exampleProtocol", "example Protocol")
function example_protocol.dissector(buffer, packet_info, tree)
packet_info.cols.protocol = example_protocol.name
example_tree = tree:add(example_protocol, buffer())
Dissector.get("example_layer"):call(buffer, packet_info, example_tree)
end
-- initialization routine
function example_protocol.init()
local wtap_encap_table = DissectorTable.get("ethertype")
wtap_encap_table:add(0xffff, example_protocol)
end
end

View File

@@ -1,5 +1,5 @@
require "b2ws_const"
local loaded_b2ws_util= assert(loadfile(b2ws_const.B2WS_PLUGIN_PATH .. "b2ws_util.lua"))
local loaded_b2ws_util= assert(loadfile(b2ws_const.B2WS_PLUGIN_PATH .. b2ws_const.B2WS_UTIL_FILE))
loaded_b2ws_util()
function b2ws_import_blob(config_string)
@@ -52,3 +52,12 @@ function b2ws_change_settings(config_string, blob_src, eth_src, eth_dst, eth_typ
new_config_string = new_config_string .. "\t[\"eth_fake_header_type\"] = \"" .. b2ws_config.eth_fake_header_type .. "\"\n}"
return new_config_string
end
function b2ws_create_dissector(config_string)
local b2ws_config = create_b2ws_config_object(config_string)
local template_string = read_b2ws_folder_file(b2ws_const.B2WS_PLUGIN_PATH, b2ws_const.B2WS_DISSECTOR_TEMPLATE_FILE)
template_string = template_string:gsub("0xffff", "0x" .. b2ws_config.eth_fake_header_type)
local dissector_path = b2ws_config.blob_src .. b2ws_const.B2WS_DISSECTOR_EXTENSION
write_b2ws_file(dissector_path, template_string)
return dissector_path
end

View File

@@ -1,13 +1,13 @@
if not gui_enabled() then return end
require "b2ws_const"
local loaded_b2ws_import= assert(loadfile(b2ws_const.B2WS_PLUGIN_PATH .. "b2ws_import.lua"))
local loaded_b2ws_import= assert(loadfile(b2ws_const.B2WS_PLUGIN_PATH .. b2ws_const.B2WS_IMPORT_BLOB_FILE))
loaded_b2ws_import()
local function b2ws_win_import_blob()
local win = TextWindow.new(b2ws_const.B2WS_IMPORT_BLOB_WIN_TITLE)
win:set_editable()
config_file_path = create_b2ws_config_file_path(b2ws_const.B2WS_PLUGIN_PATH, b2ws_const.B2WS_PLUGIN_CONFIG_FILE_NAME)
config_file_path = create_b2ws_folder_file_path(b2ws_const.B2WS_PLUGIN_PATH, b2ws_const.B2WS_PLUGIN_CONFIG_FILE_NAME)
win:set(read_b2ws_file(config_file_path))
local function b2ws_win_btn_import_blob()
@@ -17,6 +17,7 @@ local function b2ws_win_import_blob()
-- import to and show in pcap file
output_path = b2ws_import_blob(win_text)
open_capture_file(output_path, "")
reload()
end
local function b2ws_win_btn_save_settings()
@@ -39,9 +40,29 @@ local function b2ws_win_import_blob()
b2ws_const.B2WS_CONFIG_LABEL_ETH_FAKE_HEADER_TYPE)
end
local function b2ws_win_btn_create_dissector()
local win_text = b2ws_trim(win:get_text())
local dissector_path = b2ws_create_dissector(win_text)
local info = TextWindow.new(b2ws_const.B2WS_RELOAD_PLUGIN_WIN_TITLE)
info:set(b2ws_const.B2WS_RELOAD_PLUGIN_WIN_CONTENT:gsub("{0}", dissector_path))
local function b2ws_win_btn_show_disector()
local dis_win = TextWindow.new(b2ws_const.B2WS_SHOW_DISSECTOR_WIN_TITLE)
dis_win:set_editable()
dis_win:set(read_b2ws_file(dissector_path))
local function b2ws_win_btn_save_disector()
local dis_win_text = b2ws_trim(dis_win:get_text())
write_b2ws_file(dissector_path, dis_win_text)
end
dis_win:add_button(b2ws_const.B2WS_SAVE_DISSECTOR_BTN_TITLE, b2ws_win_btn_save_disector)
end
info:add_button(b2ws_const.B2WS_SHOW_DISSECTOR_BTN_TITLE, b2ws_win_btn_show_disector)
end
win:add_button(b2ws_const.B2WS_IMPORT_BLOB_BTN_TITLE, b2ws_win_btn_import_blob)
win:add_button(b2ws_const.B2WS_SAVE_SETTINGS_BTN_TITLE, b2ws_win_btn_save_settings)
win:add_button(b2ws_const.B2WS_CHANGE_SETTINGS_BTN_TITLE, b2ws_win_btn_change_settings)
win:add_button(b2ws_const.B2WS_CREATE_DISSECTOR_BTN_TITLE, b2ws_win_btn_create_dissector)
end
register_menu(b2ws_const.B2WS_IMPORT_BLOB_MENU_TITLE, b2ws_win_import_blob, MENU_TOOLS_UNSORTED)

View File

@@ -9,7 +9,7 @@ function b2ws_trim(s)
return from > #s and "" or s:match(".*%S", from)
end
function create_b2ws_config_file_path(plugin_path, plugin_config_file_name)
function create_b2ws_folder_file_path(plugin_path, plugin_config_file_name)
return persconffile_path(plugin_path) .. plugin_config_file_name
end
@@ -26,13 +26,13 @@ function read_b2ws_file(file_path)
return config_string
end
function read_b2ws_config_file(plugin_path, plugin_config_file_name)
local path = create_b2ws_config_file_path(plugin_path, plugin_config_file_name)
function read_b2ws_folder_file(plugin_path, plugin_config_file_name)
local path = create_b2ws_folder_file_path(plugin_path, plugin_config_file_name)
return read_b2ws_file(path)
end
function write_b2ws_config_file(plugin_path, plugin_config_file_name, settings)
local path = create_b2ws_config_file_path(plugin_path, plugin_config_file_name)
function write_b2ws_folder_file(plugin_path, plugin_config_file_name, settings)
local path = create_b2ws_folder_file_path(plugin_path, plugin_config_file_name)
write_b2ws_file(path, settings)
end