3 releases

0.2.2 Aug 7, 2024
0.2.1 Apr 3, 2024
0.2.0 Feb 22, 2024

#639 in Encoding

Download history 49/week @ 2024-06-16 52/week @ 2024-06-23 63/week @ 2024-06-30 60/week @ 2024-07-07 11/week @ 2024-07-14 5/week @ 2024-07-21 17/week @ 2024-07-28 127/week @ 2024-08-04 27/week @ 2024-08-11 11/week @ 2024-08-18 18/week @ 2024-08-25 25/week @ 2024-09-01 48/week @ 2024-09-08 96/week @ 2024-09-15 102/week @ 2024-09-22 100/week @ 2024-09-29

348 downloads per month

MIT/Apache

16KB
77 lines

muddy

muddy is a static string obfuscation library, designed to provide an easy way of avoiding simple static binary analysis tools such as strings or YARA rules. It functions by encrypting texts at buildtime, and decrypting them lazily at runtime.

Usage & Examples

use muddy::{m, muddy_init};

muddy_init!();

println!("{}", m!("My highly obfuscated text"));
println!("{}", "My non obfuscated static str - ripgrep me");

Compile this example and grep the binary for obfuscated:

cargo b --example simple

strings ./target/debug/examples/simple | grep obfuscated
Only the second nonobfuscated line should appear.

muddy primarily provides the exported m!(), #[muddy], and muddy_all! { } macros, all which take text as input and encrypt it. The muddy_init!() macro provides the scaffolding for decrypting the strings at runtime and should be placed at the root of the user's crate.

These macros can be used as an in-place text replacement with m!("my text"):

use muddy::{muddy_init, m};

muddy_init!();

println!("{}", m!("my plaintext"));

As an annotated &'static str with the muddy attribute:

use muddy::{muddy, muddy_init};

muddy_init!();

#[muddy]
static MY_STR: &str = "my plaintext";

Or as an invocation around multiple annotated &'static strs with muddy_all:

use muddy::{muddy_all, muddy_init};

muddy_init!();

muddy_all! {
   pub static MY_STR: &str = "my plaintext";
   pub static MY_SECOND_STR: &str = "my second plaintext";
   static MY_THIRD_STR: &str = "my module-specific third plaintext";
}

By default, muddy will encrypt the static strings with the chacha20poly1305 implementation, and embed the key inside the binary.

To avoid hardcoding the deobfuscation key into your binary, you may use:


use muddy::{m, muddy_init};

muddy_init!("env");

// If you build your program with `muddy_init!("env")`,
// the deobfuscation key env variable and deobfuscation key
// will be printed out to stderr:  
// `MUDDY='D47A372C13DEFED74FD3B9B4C741C355F9CB2C23C43F98ADE2C02FD50CA55C3D'`

// This key needs to be provided at runtime else the program will panic.  
// `MUDDY='D47A372C13DEFED74FD3B9B4C741C355F9CB2C23C43F98ADE2C02FD50CA55C3D' ./target/debug/examples/env`
    println!("{}", m!("My highly obfuscated text"));
    println!("{}", "My non obfuscated static str - ripgrep me");

If muddy_init!("env") is set, the MUDDY (by default) env variable will be checked at runtime for the key and the program will panic if it's not found.

You can also set your own env key identifier at buildtime through MUDDY:
This: MUDDY='MY_KEY_NAME_2' cargo b --example env
prints: MY_KEY_NAME_2='FD5B85045B5278F5EDA567AD7C58EB56934BD8D7432C878B1AB6090052A64080'

muddy_init!

muddy_init!() can take one of two values:

  • muddy_init!("embed")
  • muddy_init!("env")

If no value is provided, the macro defaults to the "embed" configuration.
If "env" is provided, you may also set the env key identifier as the second field: muddy_init!("env", "MY_KEY")

Note on obfuscation and encryption

This crate does not provide any form of real encryption. It only makes the task of understanding strings in your binary more difficult. Obfuscation is not security.

This crate also does not obfuscate any debug symbols you may have. Profile settings such as

# inside Cargo.toml

[profile]
strip = true
panic = "abort"
# ...

and more can be found in the cargo reference.

Macro expansion

To check what this macro expands to:

  • install cargo expand
  • run: cargo expand -p muddy --example env

Next steps:

  • handle #![no_std] environments
  • check safety with leaking mut statics
  • check proc macro testing suites

Disclaimer

This library is developed with the sole intention of providing a tool to challenge and educate cybersecurity professionals. It is not intended for any malicious or unlawful activities. The creators and contributors of this library do not endorse, encourage, or support the use of this tool for any illegal purposes.

Similar/related projects

License

Dual-licensed under Apache 2.0 and MIT terms.

Dependencies

~1.5–2.1MB
~43K SLoC