diff --git a/Cargo.toml b/Cargo.toml index d977c9d..d668ddf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,3 +21,4 @@ retour = "0.1" # plain detour doesn't work on latest nightly? idk elf = "0.7.2" nix = "0.26.2" proc-maps = "0.3.0" +dlopen = "0.1.8" diff --git a/src/lib.rs b/src/lib.rs index d5180fd..d64fed5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,24 @@ use std::{error::Error, ffi::c_int}; +use dlopen::symbor::Library; use nix::libc::{socklen_t, sockaddr}; use retour::static_detour; static_detour! { static SOCKET_HOOK : unsafe extern "C" fn(i32, i32, i32) -> i32; static CONNECT_HOOK : unsafe extern "C" fn(c_int, *const sockaddr, socklen_t) -> c_int; + static LOAD_EXT_HOOK : unsafe extern "C" fn(c_int) -> c_int; } +// extern "C" { +// fn load_ext() -> (); +// } + fn add_hooks() -> Result<(), Box> { + let exec = Library::open_self()?; + + let load_ext_sym = unsafe { exec.symbol:: c_int>("load_ext") }; + unsafe { SOCKET_HOOK.initialize(nix::libc::socket, |dom, tp, proto| { eprintln!("caught socket({}, {}, {}) call", dom, tp, proto); @@ -21,6 +31,16 @@ fn add_hooks() -> Result<(), Box> { CONNECT_HOOK.call(fd, info, len) })?; CONNECT_HOOK.enable()?; + + match load_ext_sym { + Ok(sym) => { + LOAD_EXT_HOOK.initialize(*sym, |x| { eprintln!("intercepted load_ext!"); x })?; + LOAD_EXT_HOOK.enable()?; + }, + Err(e) => { + eprintln!("[!] skipping load_ext hook : {}", e); + }, + } } Ok(())