该库的目的是使静态和动态(调试)分析更加困难。
该库针对Linux环境。
它目前基于ptrace抗分析技巧,并提供以下主要特征:
直接syscall调用而无需依赖libc(这使得LD_PRELOAD旁路机制无效);
系统调用混淆,这使静态反向工程更加困难(目前仅在x86_64中支持此功能);
多个ptrace SYSCALL调用。对ptrace的每个调用都必须返回预期值(即,第一次调用时为0,此后为-1),并有助于计算“ offset ”值,该值在ptrace呼叫链的末尾必须匹配期望值(请参阅此处)。如果Ptrace返回未表达的值或“ offset ”值不匹配,则该过程将终止;
“ ptrace”在嵌套环中被称为。循环是展开的,并且在每次汇编时迭代的数量是随机的。此外,在每次迭代时,“ offset ”值也会辐射。
通过启用依赖Goldberg Crate的obfuscate功能,可以使生成的代码更加混淆。
要使用板条箱,请将其添加到您的依赖项中:
[dependencies]
debugoff = { version = "0.2.1, features = ["obfuscate"] }
为了启用系统,请调用obfuscation,请使用syscallobf功能(这是一个实验功能,仅影响针对x86_64体系结构的二进制功能):
[dependencies]
debugoff = { version = "0.2.1, features = ["obfuscate", "syscallobf"] }
鉴于库在每次编译中都会生成随机代码,请确保每次重建所有内容。这样的事情:
cargo clean
cargo build --release
发行版构建中的剥离符号也是一个好主意:
[profile.release]
debug = false
strip = "symbols"
panic = "abort"
在下面的示例中,仅当目标操作系统是Linux而仅用于发行版构建时才使用debugoff (通过这种方式,当代码以调试模式编译时,它可以在无需绕过debugoff情况下进行调试)。
// Include only for Linux and when building in release mode
# [ cfg ( target_os = "linux" ) ]
# [ cfg ( not ( debug_assertions ) ) ]
use debugoff ;
use std :: time :: SystemTime ;
fn main ( ) {
// Call only for Linux and when building in release mode
# [ cfg ( target_os = "linux" ) ]
# [ cfg ( not ( debug_assertions ) ) ]
debugoff :: multi_ptraceme_or_die ( ) ;
println ! (
"Time: {}" ,
SystemTime :: now ( )
. duration_since ( SystemTime :: UNIX_EPOCH )
. unwrap ( )
. as_millis ( )
) ;
// Call only for Linux and when building in release mode
# [ cfg ( target_os = "linux" ) ]
# [ cfg ( not ( debug_assertions ) ) ]
debugoff :: multi_ptraceme_or_die ( ) ;
println ! ( "Example complete!" ) ;
}请参阅示例目录中的其他示例,这些示例可以与以下方式构建:
cargo build --release --features obfuscate,syscallobf --examples如果我们在发布模式下构建以下代码(不使用DebugOff ):
use std :: time :: SystemTime ;
fn main ( ) {
println ! (
"Time: {}" ,
SystemTime :: now ( )
. duration_since ( SystemTime :: UNIX_EPOCH )
. unwrap ( )
. as_millis ( )
) ;
println ! ( "Example complete!" ) ;
}这是main函数的相应函数图:
。
如果我们使用具有obfuscate功能的DebugOff构建相同的代码:
# [ cfg ( target_os = "linux" ) ]
# [ cfg ( not ( debug_assertions ) ) ]
use debugoff ;
use std :: time :: SystemTime ;
fn main ( ) {
# [ cfg ( target_os = "linux" ) ]
# [ cfg ( not ( debug_assertions ) ) ]
debugoff :: multi_ptraceme_or_die ( ) ;
println ! (
"Time: {}" ,
SystemTime :: now ( )
. duration_since ( SystemTime :: UNIX_EPOCH )
. unwrap ( )
. as_millis ( )
) ;
# [ cfg ( target_os = "linux" ) ]
# [ cfg ( not ( debug_assertions ) ) ]
debugoff :: multi_ptraceme_or_die ( ) ;
println ! ( "Example complete!" ) ;
}这是main函数的混淆函数图:
。
在此特定示例中, DebugOff生成的所有代码都在main函数中列入。不能保证总是这样的情况,因为内在的功能可能会受到称为DebugOff的位置以及用于构建项目的工具链版本的许多因素。在其他情况下,所得的函数图可能比示例中报告的函数图更简单,但是无论如何,比不使用DebugOff时生成的功能图更复杂。
许可以下:
obfuscate功能时;obfuscate功能时; x86_64 );