Giter Site home page Giter Site logo

cerclique / wirdigen Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 0.0 59 KB

LUA dissector plugin generator for Wireshark

Home Page: https://crates.io/crates/wirdigen

License: MIT License

Rust 100.00%
rust wireshark wireshark-dissector wireshark-dissector-plugin wireshark-lua wireshark-plugin

wirdigen's Introduction

RustCI Codecov RustAudit


Table of Contents

Overview

Wirdigen (Wireshark Dissector Generator) is a small library that aims to generate LUA dissector for Wireshark based on a JSON description of the packet you want to analyze.

For more information about packet dissection, please refer to Wireshark documentation and wiki.

How to use

The library is composed of two tools:

Validator

Validator compare a JSON packet description with a predefined JSON schema to ensure data integrity for plugin generation.

If the packet description is invalid, errors are automatically reported to the user through stderr with detailled location/description.

use wirdigen::validator::Validator;
use wirdigen::error::WirdigenError;

fn foo() -> Result<(), WirdigenError> {
    // Load JSON file
    let file_path = "./example/example_dissector.json";
    let file = File::open(file_path)?;
    let rdr = BufReader::new(file);

    // Create serde JSON value from the file
    let value: Value = serde_json::from_reader(rdr)?;

    // Create Validator object
    let val = Validator::new()?;

    // Call to validation function
    match val.validate(&value) {
        true => println!("{}: VALID", file_path),
        false => println!("{}: INVALID", file_path)
    }
    Ok(())
}

Generator

Generator generate LUA plugin based on JSON input given by the user.

use wirdigen::generator::Generator;
use wirdigen::error::WirdigenError;

fn foo() -> Result<(), WirdigenError> {
    // Load JSON file
    let file_path = "./example/example_dissector.json";
    let file = File::open(file_path)?;
    let rdr = BufReader::new(file);

    // Create Generator object
    let gen = Generator::default();
    // let gen = Generator::new();   <-- Alternative

    // Generate from a reader source
    let generated_file_path: String = gen.from_reader(rdr)?;
    println!("Generated: {}", generated_file_path);

    Ok(())
}

Note: The Generator does not perform any pre-validation on the user input. This is the role of the Validator. In case of invalid file, method from Generator will return appropriate Err(WirdigenError). To avoid these kinds of problem, it's best to first perform a validation and, then, generate the LUA dissector.

Generator object also have a from_value method in order to reuse the serde-json Value from the validation task for the generation.

fn foo() -> Result<(), WirdigenError> {
    // Open the JSON file
    let file_path = "./example/example_dissector.json";
    let file = File::open(file_path)?;
    let rdr = BufReader::new(file);

    // Create serde JSON value from the file
    let value: Value = serde_json::from_reader(rdr)?;

    // Create Validator object
    let val = Validator::new()?;

    // Call to validation method
    if val.validate(&value) {
        // Create Generator object
        let gen = Generator::default();

        // Generate plugin from validated data
        let generated_file_path: String = gen.from_value(value)?;
        println!("{}", generated_file_path);
    }
    else {
        println!("Invalid user input: {}", file_path);
    }
    
    Ok(())
}

By default, the plugin is generated in the temporary folder defined in environment variable. The user can modify the output directory through set_output_directory() method and retrieve the current one through get_output_directory().

fn foo {
    let mut gen = Generator::default();

    println!("{}", gen.get_output_directory());

    let new_output = "/Documents/MyDissectors";
    gen.set_output_directory(new_output);

    println!("{}", gen.get_output_directory());
}

Note: The method set_output_directory does not create non-existant directory from user input. If the output directory is not reachable, the error will be propagated from the generation method when trying to create the final LUA file.

Dissector format

A JSON dissector description is composed of 4 elements:

  • name
  • endianness
  • connection
  • data

Name

name element is a string (max size: 32) representing the name of the protocol to dissect that will be used inside Wireshark ("Protocol" column) to identify your packet.

Note: This name is also used for the generated LUA file. For example, if the attribute is MY_PROTO, the generated plugin will be called dissector_MY_PROTO.lua.

Endianness

String defining which endianness is used by the protocol. Possible values are little and big.

Connection

The connection object contains 2 fields :

  • protocol: String. Either udp or tcp.
  • ports: Array of port the dissector need to spy (between 1 and 65535).

Data

data is an array of object describing the packet. Each object define a chunk of the packet we want to identify.

Each chunk contains the following attributes:

  • name: String (max size: 32).
  • format: String representing the data type of the chunk. Refer to format/base matrices below for available values.
  • base: String representing how the value should be displayed. Refer to format/base matrices below for available values.
  • offset: Position offset, in byte, from the begining of the packet.
  • size: Size, in byte, of the chunk inside the packet.
  • valstr (Optional) : Array of value/string object to identify specific values in the payload. See below for more information.

About strval:

This attribute can be used to identify and replace specific value by its string representation (max size: 32). For instance, when dealing with webpage status code, it can be usefull to view status code 404 as "NOT FOUND" or 200 as "OK" inside wireshark capture view. This example can be described as follow inside the dissector JSON file :

{
    ..., // First part of data chunk description
    "valstr" : [
        { "value": 404, "string": "NOT FOUND" },
        { "value": 200, "string": "OK"}
    ]
}

Format/Base compatibility matrices

These matrices show which format/base combination are supported by Wirdigen.

Numeric

Format \ Base NONE DEC OCT HEX DEC_HEX HEX_DEC
bool X
char X X
uint8 X X X X X
uint16 X X X X X
uint24 X X X X X
uint32 X X X X X
uint64 X X X X X
int8 X
int16 X
int24 X
int32 X
int64 X
float(*) X X X X X X
double(*) X X X X X X

(*) = For the specified format, the base is ignored by Wireshark.

Time

Format \ Base LOCAL UTC DOY_UTC
absolute_time X X X
relative_time(*) X X X

(*) = For the specified format, the base is ignored by Wireshark.

Raw

Format \ Base NONE DOT DASH COLON SPACE
byte X X X X X

Specific

For these specific type of data, display is automatically handled by Wirehsark. Hense, base is ignored. I would recommend using NONE in these case.

  • none
  • ipv4
  • ipv6
  • ether
  • guid
  • oid

Import dissector into Wireshark

First, you need to check in which directory Wireshark is looking for LUA plugin.

To do this, open Wireshark and go to help -> About Wireshark -> Folder.

Find the path associated to "Personal Lua plugins". This is where you need to copy your dissector. If the path does not exist on your machine, you can manually create missing directories.

The dissector script will be active after Wireshark is refreshed. You can either restart Wireshark or press Ctrl + Shift + L to reload all Lua scripts.

Note: You need to reload/restart everytime you make a change in a dissector.

Roadmap

  • Missing data type:

    • framenum
    • string
    • stringz
    • ubytes
    • protocol
    • rel_oid
    • systemid
    • eui64
  • Support for child subtree to clearly describe more complex packet.

Related tools

wirdigen's People

Contributors

cerclique avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wirdigen's Issues

RUSTSEC-2020-0071: Potential segfault in the time crate

Potential segfault in the time crate

Details
Package time
Version 0.1.44
URL time-rs/time#293
Date 2020-11-18
Patched versions >=0.2.23
Unaffected versions =0.2.0,=0.2.1,=0.2.2,=0.2.3,=0.2.4,=0.2.5,=0.2.6

Impact

Unix-like operating systems may segfault due to dereferencing a dangling pointer in specific circumstances. This requires an environment variable to be set in a different thread than the affected functions. This may occur without the user's knowledge, notably in a third-party library.

The affected functions from time 0.2.7 through 0.2.22 are:

  • time::UtcOffset::local_offset_at
  • time::UtcOffset::try_local_offset_at
  • time::UtcOffset::current_local_offset
  • time::UtcOffset::try_current_local_offset
  • time::OffsetDateTime::now_local
  • time::OffsetDateTime::try_now_local

The affected functions in time 0.1 (all versions) are:

  • at
  • at_utc
  • now

Non-Unix targets (including Windows and wasm) are unaffected.

Patches

Pending a proper fix, the internal method that determines the local offset has been modified to always return None on the affected operating systems. This has the effect of returning an Err on the try_* methods and UTC on the non-try_* methods.

Users and library authors with time in their dependency tree should perform cargo update, which will pull in the updated, unaffected code.

Users of time 0.1 do not have a patch and should upgrade to an unaffected version: time 0.2.23 or greater or the 0.3 series.

Workarounds

No workarounds are known.

References

time-rs/time#293

See advisory page for additional details.

RUSTSEC-2020-0159: Potential segfault in `localtime_r` invocations

Potential segfault in localtime_r invocations

Details
Package chrono
Version 0.4.19
URL chronotope/chrono#499
Date 2020-11-10

Impact

Unix-like operating systems may segfault due to dereferencing a dangling pointer in specific circumstances. This requires an environment variable to be set in a different thread than the affected functions. This may occur without the user's knowledge, notably in a third-party library.

Workarounds

No workarounds are known.

References

See advisory page for additional details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.