Skip to main content

multi_ptraceme_or_die

Function multi_ptraceme_or_die 

Source
pub fn multi_ptraceme_or_die()
Expand description

Call ptrace(PTRACE_TRACEME, ...) multiple times in nested loops.

The loop iterations are unrolled and the number of iterations is randomized for each compilation (just remember to clean you project before compiling again: cargo clean).

For each iteration, if the value returned by ptrace is not the expected one, the function calls exit_group(0). If the value returned by ptrace is the expected one (0 at the first call in a thread and -1 thereafter) then a random value (sum of a dynamic random value and a compilation time random value) is added to an offset value. At the end of all the iterations the offset value is checked. If the check fails, the function calls exit_group(0)

If debugoff is included as a dependency with obfuscate feature enabled, the code is even more obfuscated by goldberg.

This function can be called multiple times. To be more effective, the function should be called at least once for each thread.

ยงExamples

// Import only on Linux and for "release builds"
#[cfg(target_os = "linux")]
#[cfg(not(debug_assertions))]
use debugoff;

// Call only on Linux and for "release" builds.
#[cfg(target_os = "linux")]
#[cfg(not(debug_assertions))]
debugoff::multi_ptraceme_or_die();
Examples found in repository?
examples/simple2_multi_ptrace.rs (line 15)
13pub fn main() {
14    if cfg!(target_os = "linux") && cfg!(not(debug_assertions)) {
15        debugoff::multi_ptraceme_or_die();
16    }
17
18    println!(
19        "Time: {}",
20        SystemTime::now()
21            .duration_since(SystemTime::UNIX_EPOCH)
22            .unwrap()
23            .as_millis()
24    );
25
26    if cfg!(target_os = "linux") && cfg!(not(debug_assertions)) {
27        debugoff::multi_ptraceme_or_die();
28    }
29
30    println!("Example complete!");
31}