From c3b886c21f747193b66315d0e90315ee800280e2 Mon Sep 17 00:00:00 2001 From: alterdekim Date: Mon, 9 Dec 2024 05:05:28 +0300 Subject: [PATCH] modified: Cargo.lock modified: frida_client/src/client.rs modified: frida_core/src/device.rs modified: frida_core/src/linux_tun.rs modified: frida_core/src/tun.rs modified: frida_core/src/win_tun.rs --- Cargo.lock | 10 +++++----- frida_client/src/client.rs | 6 ++++-- frida_core/src/device.rs | 37 ++++++++++++++++++++++--------------- frida_core/src/linux_tun.rs | 2 +- frida_core/src/tun.rs | 5 +++-- frida_core/src/win_tun.rs | 4 +++- 6 files changed, 38 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8840e4d..77c7e8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1644,7 +1644,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" [[package]] -name = "frida-client" +name = "frida_cli" +version = "0.2.0" + +[[package]] +name = "frida_client" version = "0.2.0" dependencies = [ "aes-gcm", @@ -1657,10 +1661,6 @@ dependencies = [ "x25519-dalek", ] -[[package]] -name = "frida_cli" -version = "0.2.0" - [[package]] name = "frida_core" version = "0.2.0" diff --git a/frida_client/src/client.rs b/frida_client/src/client.rs index 8c17b44..c09d83b 100644 --- a/frida_client/src/client.rs +++ b/frida_client/src/client.rs @@ -192,6 +192,8 @@ pub mod android { pub mod desktop { use crate::client::general::{CoreVpnClient, DevReader, DevWriter, VpnClient}; use crate::config::ClientConfiguration; + use frida_core::create; + use frida_core::device::AbstractDevice; use futures::{SinkExt, StreamExt}; use log::info; use tokio::net::UdpSocket; @@ -267,7 +269,7 @@ pub mod desktop { async fn start(&self) { info!("s_interface: {:?}", &self.s_interface); info!("client_address: {:?}", &self.client_config.client.address); - let mut config = Configuration::default(); + let mut config = AbstractDevice::default(); config.address(&self.client_config.client.address) .netmask("255.255.255.255") .destination("10.66.66.1") @@ -279,7 +281,7 @@ pub mod desktop { let sock = UdpSocket::bind(("0.0.0.0", 0)).await.unwrap(); sock.connect(&self.client_config.server.endpoint).await.unwrap(); - let dev = create_as_async(&config).unwrap(); + let dev = create(&config).unwrap(); let (mut dev_writer , mut dev_reader) = dev.into_framed().split(); let mut client = CoreVpnClient{ client_config: self.client_config.clone(), dev_reader: DevReader{ dr: dev_reader }, dev_writer: DevWriter{dr: dev_writer }, close_token: tokio_util::sync::CancellationToken::new()}; diff --git a/frida_core/src/device.rs b/frida_core/src/device.rs index a1e45b1..fce9b20 100644 --- a/frida_core/src/device.rs +++ b/frida_core/src/device.rs @@ -1,31 +1,38 @@ +use std::net::IpAddr; + #[derive(Default)] pub struct AbstractDevice { - address: String, - netmask: String, - destination: String, - mtu: u16, - tun_name: String + address: Option, + netmask: Option, + destination: Option, + mtu: Option, + tun_name: Option } impl AbstractDevice { - fn address(&mut self, address: String) { - self.address = address; + pub fn address(&mut self, address: IpAddr) -> &mut Self { + self.address = Some(address); + self } - fn netmask(&mut self, netmask: String) { - self.netmask = netmask; + pub fn netmask(&mut self, netmask: IpAddr) -> &mut Self { + self.netmask = Some(netmask); + self } - fn destination(&mut self, destination: String) { - self.destination = destination; + pub fn destination(&mut self, destination: IpAddr) -> &mut Self { + self.destination = Some(destination); + self } - fn mtu(&mut self, mtu: u16) { - self.mtu = mtu; + pub fn mtu(&mut self, mtu: u16) -> &mut Self { + self.mtu = Some(mtu); + self } - fn tun_name(&mut self, tun_name: String) { - self.tun_name = tun_name; + pub fn tun_name>(&mut self, tun_name: S) -> &mut Self { + self.tun_name = Some(tun_name.as_ref().into()); + self } } \ No newline at end of file diff --git a/frida_core/src/linux_tun.rs b/frida_core/src/linux_tun.rs index a58ac43..ed02c08 100644 --- a/frida_core/src/linux_tun.rs +++ b/frida_core/src/linux_tun.rs @@ -4,7 +4,7 @@ use tokio_tun::Tun; use std::net::Ipv4Addr; use std::os::unix::io::AsRawFd; -pub fn create() -> (DeviceReader, DeviceWriter) { +pub fn create(cfg: AbstractDevice) -> (DeviceReader, DeviceWriter) { let tun = Arc::new( Tun::builder() .name("") // if name is empty, then it is set by kernel. diff --git a/frida_core/src/tun.rs b/frida_core/src/tun.rs index 45e8112..c51b669 100644 --- a/frida_core/src/tun.rs +++ b/frida_core/src/tun.rs @@ -1,9 +1,10 @@ +use crate::device::AbstractDevice; #[cfg(target_os = "windows")] use crate::win_tun::{DeviceReader, DeviceWriter, create}; #[cfg(target_os = "linux")] use crate::linux_tun::{DeviceReader, DeviceWriter, create}; -pub fn create_tun() -> (DeviceReader, DeviceWriter) { - create() +pub fn create_tun(cfg: AbstractDevice) -> (DeviceReader, DeviceWriter) { + create(cfg) } \ No newline at end of file diff --git a/frida_core/src/win_tun.rs b/frida_core/src/win_tun.rs index e395c20..371f8a6 100644 --- a/frida_core/src/win_tun.rs +++ b/frida_core/src/win_tun.rs @@ -3,7 +3,9 @@ use wintun::Session; use std::sync::Arc; use std::error::Error; -pub fn create() -> (DeviceReader, DeviceWriter) { +use crate::device::AbstractDevice; + +pub fn create(cfg: AbstractDevice) -> (DeviceReader, DeviceWriter) { //Unsafe because we are loading an arbitrary dll file let wintun = unsafe { wintun::load_from_path("wintun.dll") } .expect("Failed to load wintun dll");