modified: Cargo.lock

modified:   frida_cli/Cargo.toml
	modified:   frida_client/Cargo.toml
	modified:   frida_client/src/client.rs
	deleted:    frida_client/src/main.rs
	modified:   frida_core/Cargo.toml
	new file:   frida_core/src/lib.rs
	modified:   frida_core/src/tun.rs
	modified:   frida_gui/Cargo.toml
	modified:   frida_lib/Cargo.toml
	modified:   frida_server/Cargo.toml
This commit is contained in:
Michael Wain 2024-12-09 04:49:22 +03:00
parent e922ee3033
commit 12fda1d912
11 changed files with 66 additions and 121 deletions

38
Cargo.lock generated
View File

@ -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"

View File

@ -1,5 +1,5 @@
[package]
name = "frida_cli"
name = "frida-cli"
version = "0.2.0"
edition = "2021"
license-file = "../LICENSE.md"

View File

@ -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"

View File

@ -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<u8>) -> Result<usize, ()>;
}
pub struct DevReader {
pub dr: SplitStream<Framed<AsyncDevice, TunPacketCodec>>
}
// TODO: implement custom Error
impl ReadWrapper for DevReader {
async fn read(&mut self, buf: &mut Vec<u8>) -> Result<usize, ()> {
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<u8>) -> Result<usize, ()> {
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<usize, String>;
}
pub enum WriterMessage {
Plain(Vec<u8>),
Gateway(Ipv4Addr)
}
pub struct DevWriter {
pub dr: SplitSink<Framed<AsyncDevice, TunPacketCodec>, Vec<u8>>
}
// TODO: implement custom Error
impl WriteWrapper for DevWriter {
async fn write(&mut self, msg: WriterMessage) -> Result<usize, String> {
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<usize, String> {
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<T, R> 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<T: ReadWrapper + std::marker::Sync, R: WriteWrapper + std::marker::Sync> CoreVpnClient<T, R> {
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<String>) {

View File

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}

View File

@ -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"

14
frida_core/src/lib.rs Normal file
View File

@ -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::*;

View File

@ -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()
}

View File

@ -1,5 +1,5 @@
[package]
name = "frida_gui"
name = "frida-gui"
version = "0.2.0"
edition = "2021"
license-file = "../LICENSE.md"

View File

@ -1,5 +1,5 @@
[package]
name = "frida_lib"
name = "frida-lib"
version = "0.2.0"
edition = "2021"
license-file = "../LICENSE.md"

View File

@ -1,5 +1,5 @@
[package]
name = "frida_server"
name = "frida-server"
version = "0.2.0"
edition = "2021"
license-file = "../LICENSE.md"