diff --git a/Cargo.lock b/Cargo.lock index 76e4c5d..06ff490 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1668,7 +1668,7 @@ dependencies = [ "env_logger", "frida_core", "log", - "network-interface", + "regex", "tokio 1.42.0", "tokio-util", "x25519-dalek", @@ -1696,7 +1696,6 @@ dependencies = [ "jni 0.20.0", "log", "log4rs", - "network-interface", "nonblock", "packet", "rand", @@ -2961,18 +2960,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "network-interface" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "433419f898328beca4f2c6c73a1b52540658d92b0a99f0269330457e0fd998d5" -dependencies = [ - "cc", - "libc", - "thiserror 1.0.69", - "winapi 0.3.9", -] - [[package]] name = "nix" version = "0.29.0" diff --git a/frida_client/Cargo.toml b/frida_client/Cargo.toml index 1c3d05b..26a4452 100644 --- a/frida_client/Cargo.toml +++ b/frida_client/Cargo.toml @@ -20,4 +20,4 @@ tokio = { version = "1", features = ["full", "signal", "tracing"] } tokio-util = "0.7.12" env_logger = "0.9" log = "0.4.20" -network-interface = "2.0.0" \ No newline at end of file +regex = "1.11.1" \ No newline at end of file diff --git a/frida_client/src/client.rs b/frida_client/src/client.rs index dd8ac09..7bbe00c 100644 --- a/frida_client/src/client.rs +++ b/frida_client/src/client.rs @@ -201,34 +201,54 @@ pub mod desktop { use tokio::net::UdpSocket; #[cfg(target_os = "linux")] - use network_interface::{NetworkInterface, NetworkInterfaceConfig}; + use regex::Regex; #[cfg(target_os = "linux")] fn configure_routes(endpoint_ip: &str) { - let interfaces = NetworkInterface::show().unwrap(); - - let net_inter = interfaces.iter() - .filter(|i| !i.addr.iter().any(|b| b.ip().to_string() == "127.0.0.1" || b.ip().to_string() == "::1") ) - .min_by(|x, y| x.index.cmp(&y.index)) - .unwrap(); - - info!("Main interface: {:?}", net_inter); + let mut if_out = std::process::Command::new("ip") + .arg("-4") + .arg("route") + .arg("show") + .arg("default") + .output() + .expect("Failed to get default route"); - let inter_name = net_inter.name.clone(); - - info!("Main network interface: {:?}", inter_name); + if !if_out.status.success() { + log::error!("Failed to execute ip route command: {:?}", String::from_utf8_lossy(&if_out.stderr)); + } + + let r = if_out.stdout; + + let gateway = None; + let if_name = None; + + let rg = Regex::new(r"default via .+ dev ").unwrap(); + + if let Some(m) = rg.find(r) { // gateway + gateway = Some(&m.as_str()[12..m.len()-4]); + } + + let rg = Regex::new(r"dev .+ proto").unwrap(); + if let Some(m) = rg.find(r) { // name + if_name = Some(&m.as_str()[4..m.len()-6]); + } + + info!("Main interface: {:?}", &if_name.unwrap()); + + let inter_name = if_name.unwrap(); + + info!("Main network interface: {:?}", &gateway.unwrap()); - /* let mut ip_output = std::process::Command::new("sudo") .arg("route") .arg("add") .arg("-host") .arg(endpoint_ip) .arg("gw") - .arg() // default interface gateway + .arg(&gateway.unwrap()) // default interface gateway .arg("dev") - .arg() // default interface + .arg(&inter_name) // default interface .output() .expect("Failed to execute route command."); @@ -242,7 +262,7 @@ pub mod desktop { .arg("add") .arg("0.0.0.0/0") .arg("dev") - .arg() // tun adapter name + .arg("tun0") // tun adapter name .output() .expect("Failed to execute ip route command."); @@ -256,7 +276,7 @@ pub mod desktop { .arg("add") .arg("128.0.0.0/1") .arg("dev") - .arg() // tun adapter name + .arg("tun0") // tun adapter name .output() .expect("Failed to execute ip route command."); @@ -270,16 +290,15 @@ pub mod desktop { .arg("-host") .arg(endpoint_ip) .arg("gw") - .arg() // default interface gateway + .arg(&gateway.unwrap()) // default interface gateway .arg("dev") - .arg() // default interface + .arg(&inter_name) // default interface .output() .expect("Failed to execute route command."); if !ip_output.status.success() { log::error!("Failed to execute route command: {:?}", String::from_utf8_lossy(&ip_output.stderr)); } - */ } pub struct DesktopClient { diff --git a/frida_core/Cargo.toml b/frida_core/Cargo.toml index a02f482..fe993f8 100644 --- a/frida_core/Cargo.toml +++ b/frida_core/Cargo.toml @@ -33,7 +33,6 @@ x25519-dalek = { version = "2.0.1", features = ["getrandom", "static_secrets"] } base64 = "0.22.1" chrono = "0.4.38" console-subscriber = "0.4.0" -network-interface = "2.0.0" tun = { version = "0.7.5", features = ["async"] } [target.'cfg(target_os="windows")'.dependencies]