diff --git a/Cargo.lock b/Cargo.lock index 24d26cd..ae445d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1644,11 +1644,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" [[package]] -name = "frida_cli" +name = "frida-cli" version = "0.2.0" [[package]] -name = "frida_client" +name = "frida-client" +version = "0.2.0" +dependencies = [ + "aes-gcm", + "base64 0.22.1", + "env_logger", + "frida_core", + "log", + "tokio 1.42.0", + "tokio-util", + "x25519-dalek", +] + +[[package]] +name = "frida-gui" +version = "0.2.0" + +[[package]] +name = "frida-lib" +version = "0.2.0" + +[[package]] +name = "frida-server" version = "0.2.0" [[package]] @@ -1691,18 +1713,6 @@ dependencies = [ "x25519-dalek", ] -[[package]] -name = "frida_gui" -version = "0.2.0" - -[[package]] -name = "frida_lib" -version = "0.2.0" - -[[package]] -name = "frida_server" -version = "0.2.0" - [[package]] name = "fuchsia-zircon" version = "0.3.3" diff --git a/frida_cli/Cargo.toml b/frida_cli/Cargo.toml index 874cdeb..5d37010 100644 --- a/frida_cli/Cargo.toml +++ b/frida_cli/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "frida_cli" +name = "frida-cli" version = "0.2.0" edition = "2021" license-file = "../LICENSE.md" diff --git a/frida_client/Cargo.toml b/frida_client/Cargo.toml index fd55f67..b3d9706 100644 --- a/frida_client/Cargo.toml +++ b/frida_client/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "frida_client" +name = "frida-client" version = "0.2.0" edition = "2021" license-file = "../LICENSE.md" @@ -7,6 +7,17 @@ authors = ["alterwain"] keywords = ["tun", "network", "tunnel", "vpn"] categories = ["network-programming", "asynchronous"] readme = "../README.md" -workspace = "../" + +[[bin]] +name = "frida-client" +path = "src/client.rs" [dependencies] +frida_core = { path = "../frida_core", package = "frida_core" } +aes-gcm = "0.10.3" +x25519-dalek = { version = "2.0.1", features = ["getrandom", "static_secrets"] } +base64 = "0.22.1" +tokio = { version = "1", features = ["full", "signal", "tracing"] } +tokio-util = "0.7.12" +env_logger = "0.9" +log = "0.4.20" \ No newline at end of file diff --git a/frida_client/src/client.rs b/frida_client/src/client.rs index b2978db..8c17b44 100644 --- a/frida_client/src/client.rs +++ b/frida_client/src/client.rs @@ -1,4 +1,3 @@ - pub mod general { use crate::config::ClientConfiguration; use async_channel::{Receiver, Sender}; @@ -16,103 +15,21 @@ pub mod general { use x25519_dalek::{PublicKey, StaticSecret}; use crate::udp::{UDPVpnPacket, UDPVpnHandshake, UDPSerializable}; - use tun::{ AsyncDevice, DeviceReader, DeviceWriter, TunPacketCodec }; - - pub trait ReadWrapper { - async fn read(&mut self, buf: &mut Vec) -> Result; - } - - pub struct DevReader { - pub dr: SplitStream> - } - - // TODO: implement custom Error - impl ReadWrapper for DevReader { - async fn read(&mut self, buf: &mut Vec) -> Result { - if let Some(Ok(tb)) = self.dr.next().await { - *buf = tb; - return Ok(buf.len()); - } - Err(()) - } - } - - pub struct FdReader { - pub br: File - } - - impl ReadWrapper for FdReader { - async fn read(&mut self, buf: &mut Vec) -> Result { - let r = self.br.read(buf).await; - if let Ok(a) = r { - return Ok(a); - } - Err(()) - } - } - - pub trait WriteWrapper { - async fn write(&mut self, msg: WriterMessage) -> Result; - } - - pub enum WriterMessage { - Plain(Vec), - Gateway(Ipv4Addr) - } - - pub struct DevWriter { - pub dr: SplitSink, Vec> - } - - // TODO: implement custom Error - impl WriteWrapper for DevWriter { - async fn write(&mut self, msg: WriterMessage) -> Result { - match msg { - WriterMessage::Plain(buf) => { - let l = buf.len(); - return match self.dr.send(buf).await { - Ok(()) => Ok(l), - Err(e) => Err(e.to_string()) - }; - }, - // this thing should be abolished later - WriterMessage::Gateway(_addr) => { - Ok(0) - } - } - } - } - - pub struct FdWriter { - pub br: File - } - - impl WriteWrapper for FdWriter { - async fn write(&mut self, msg: WriterMessage) -> Result { - match msg { - WriterMessage::Plain(buf) => { - if let Ok(a) = self.br.write(&buf).await { - return Ok(a); - } - Err(String::new()) - }, - WriterMessage::Gateway(_addr) => {Ok(0)} - } - } - } + use frida_core::tun::create_tun; + use frida_core::{DeviceReader, DeviceWriter}; pub trait VpnClient { async fn start(&self); } - pub struct CoreVpnClient where T: ReadWrapper, R: WriteWrapper { + pub struct CoreVpnClient { pub client_config: ClientConfiguration, - pub dev_reader: T, - pub dev_writer: R, + pub dev_reader: DeviceReader, + pub dev_writer: DeviceWriter, pub close_token: CancellationToken } - impl CoreVpnClient { + impl CoreVpnClient { pub async fn start(&mut self, sock: UdpSocket) { info!("Starting client..."); @@ -142,7 +59,7 @@ pub mod general { let s_cipher = cipher_shared.clone(); - let _ = self.dev_writer.write(WriterMessage::Plain(handshake.serialize())).await; + let _ = self.dev_writer.write(handshake.serialize()).await; let mut buf = vec![0; 1400]; // mtu let mut buf1 = vec![0; 4096]; // should be changed to less bytes @@ -159,7 +76,7 @@ pub mod general { if let Some(bytes) = rr { info!("Write to tun. len={:?}", bytes.len()); - if let Err(e) = self.dev_writer.write(WriterMessage::Plain(bytes)).await { + if let Err(e) = self.dev_writer.write(&bytes).await { error!("Writing error: {:?}", e); } /* if let Err(e) = self.dev_writer.flush().await { @@ -283,8 +200,6 @@ pub mod desktop { #[cfg(target_os = "linux")] use network_interface::{NetworkInterface, NetworkInterfaceConfig}; - use tun::{ Configuration, create_as_async }; - #[cfg(target_os = "linux")] fn configure_routes(endpoint_ip: &str, s_interface: Option) { diff --git a/frida_client/src/main.rs b/frida_client/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/frida_client/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/frida_core/Cargo.toml b/frida_core/Cargo.toml index 544dc0d..a02f482 100644 --- a/frida_core/Cargo.toml +++ b/frida_core/Cargo.toml @@ -7,11 +7,9 @@ authors = ["alterwain"] keywords = ["tun", "network", "tunnel", "vpn"] categories = ["network-programming", "asynchronous"] readme = "../README.md" -workspace = "../" -[[bin]] -name = "frida-core" -path = "src/main.rs" +[lib] +crate-type = ["staticlib", "cdylib", "lib"] [dependencies] clap = "2.33" diff --git a/frida_core/src/lib.rs b/frida_core/src/lib.rs new file mode 100644 index 0000000..5049970 --- /dev/null +++ b/frida_core/src/lib.rs @@ -0,0 +1,14 @@ +pub mod device; +pub mod tun; + +#[cfg(target_os = "windows")] +mod win_tun; + +#[cfg(target_os = "windows")] +pub use r#win_tun::*; + +#[cfg(target_os = "linux")] +mod linux_tun; + +#[cfg(target_os = "linux")] +pub use r#linux_tun::*; \ No newline at end of file diff --git a/frida_core/src/tun.rs b/frida_core/src/tun.rs index 31145b1..45e8112 100644 --- a/frida_core/src/tun.rs +++ b/frida_core/src/tun.rs @@ -4,6 +4,6 @@ use crate::win_tun::{DeviceReader, DeviceWriter, create}; #[cfg(target_os = "linux")] use crate::linux_tun::{DeviceReader, DeviceWriter, create}; -pub(crate) fn create_tun() -> (DeviceReader, DeviceWriter) { +pub fn create_tun() -> (DeviceReader, DeviceWriter) { create() } \ No newline at end of file diff --git a/frida_gui/Cargo.toml b/frida_gui/Cargo.toml index 403753f..2a91ba0 100644 --- a/frida_gui/Cargo.toml +++ b/frida_gui/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "frida_gui" +name = "frida-gui" version = "0.2.0" edition = "2021" license-file = "../LICENSE.md" diff --git a/frida_lib/Cargo.toml b/frida_lib/Cargo.toml index 8d72587..3236551 100644 --- a/frida_lib/Cargo.toml +++ b/frida_lib/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "frida_lib" +name = "frida-lib" version = "0.2.0" edition = "2021" license-file = "../LICENSE.md" diff --git a/frida_server/Cargo.toml b/frida_server/Cargo.toml index 634b3ad..1cea2dc 100644 --- a/frida_server/Cargo.toml +++ b/frida_server/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "frida_server" +name = "frida-server" version = "0.2.0" edition = "2021" license-file = "../LICENSE.md"