This is a template for a Rust project that uses DFIR for distributed services. It implements a simple echo server and client over UDP.
cargo generate gh:hydro-project/dfir-templateYou will be prompted to name your project. Once the command completes, you can cd into the project.
Ensure the correct version of Rust is installed. The template pins its toolchain via
rust-toolchain.toml, which cargo detects automatically:
rustup updateThen test the project:
cargo testThe server can be run in one terminal and one or more clients can be run in separate terminals.
% cargo run -- --role serverYou can run multiple instances of the client by running the following command:
% cargo run -- --role clientcargo run -- --helpThe src directory contains the following files:
| File | Description |
|---|---|
main.rs |
Contains main entry-point function for both client and server. Performs command-line argument parsing. |
protocol.rs |
Contains the Message enum that defines the messages that can be sent between instances. |
<role>.rs |
Contains the service for the given role. Example implementations and skeletal DFIR spec are provided for server and client. |
helpers.rs |
Contains helper functions that are invoked from DFIR code in multiple services. |
No particular communication pattern is assumed by DFIR. The unmodified template application is designed to be used in a "star topology":
multiple independent clients talking to a single server. However, the template can be easily modified to support other topologies.
Additional examples are provided in the hydro repository in the dfir_rs/examples directory.
This template is intended to be a starting point for your own project. You'll undoubtedly want to change it.
In our experience, when starting a DFIR project we recommend a four-step approach:
- Roles: Identify the roles that your services will play (in the
Optsstruct insrc/main.rs) - Messages: Define the basic message types that services will send to each other (in the
Messageenum insrc/protocol.rs). - Print Received Messages: Utilize the template logic at each service that prints out messages received.
- Exercise Sending Patterns: Make sure the right messages get to the right recipients! Write simple logic to send out messages in all the message patterns you expect to see (in the
src/<role>.rsfiles). - Service Programming: Begin writing the actual logic for each service, with plenty of
inspect(|m| println!("{:?}", m))operators peppered throughout!
Have fun!
The client and server can optionally print out a dataflow graph of their DFIR code.
Run the following command and view the messages received by the server on stdout.
% cargo run -- --role server --graph mermaidRun the following command and type in the messages to send to the server. When the server responds, the echoed message will be printed on stdout.
% cargo run -- --role client --graph mermaid% cargo run -- --role server --graph dot% cargo run -- --role client --graph dot