From 7bbae124fcc45312c4cb4c60fb004a8040cdb348 Mon Sep 17 00:00:00 2001 From: alterdekim Date: Sat, 7 Sep 2024 01:49:52 +0300 Subject: [PATCH] Changes to be committed: modified: README.md modified: src/client.rs modified: src/main.rs modified: src/server.rs --- README.md | 33 +++++++++++++++++++++++++++++++-- src/client.rs | 10 ++++++---- src/main.rs | 29 ++++++++++++++--------------- src/server.rs | 15 ++++++++------- 4 files changed, 59 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index c729f90..70d044c 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,38 @@ A lightweight VPN software, focused on scalability, traffic obfuscation and simplicity. -## Documentation +## CLI Arguments -Check the [repository wiki]() to access the documentation, tutorials. +### Usage + +```bash +./frida_vpn [FLAGS] [OPTIONS] --config +``` + +### Options +| Name | Value type | Description | +| ------------- |:-------------:| -----:| +| bind-address | IP:PORT | The ip:port that would be used to bind server (config) | +| config | FILE_PATH | The path to VPN configuration file | +| endpoint | IP:PORT | The ip:port that would be used by client to connect (config) | +| interface | NAME | Explicitly set network interface name for routing | +| internal-address | IP | The address of VPN server in it's subnet (config) | +| keepalive | SECONDS_UINT | Keepalive packets interval (config) [default: 0] | +| obfs-type | OBFS | Obfuscation protocol (config) [possible values: dns, veil, xor] | +| peer-cfg | FILE_PATH | The path to VPN peer configuration file | + +### Flags +| Name (short) | Name (long) | Description | +| ------------- |:-------------:| -----:| +| | broadcast-mode | If set to true, then all incoming traffic with an unknown destination address will be forwarded to all peers (config) | +| | grab-endpoint | If set to true, the endpoint address for peers will be grabbed from server config (config) | +| h | help | Prints help information | +| V | version | Prints version information | + +### Args +| Name | Required | Description | +| ------------- |:-------------:| -----:| +| mode | true | Runs the program in certain mode [possible values: server, client, gen_cfg, new_peer] | ## Installation diff --git a/src/client.rs b/src/client.rs index 4bd8fe4..5fd39ea 100644 --- a/src/client.rs +++ b/src/client.rs @@ -16,7 +16,7 @@ use crate::udp::{UDPVpnPacket, UDPVpnHandshake, UDPSerializable}; use network_interface::NetworkInterface; use network_interface::NetworkInterfaceConfig; -fn configure_routes(endpoint_ip: &str) { +fn configure_routes(endpoint_ip: &str, s_interface: Option<&str>) { let interfaces = NetworkInterface::show().unwrap(); let net_inter = interfaces.iter() @@ -26,6 +26,8 @@ fn configure_routes(endpoint_ip: &str) { info!("Main network interface: {:?}", &net_inter.name); + let inter_name = if s_interface.is_some() { s_interface.unwrap() } else { &net_inter.name }; + let mut ip_output = Command::new("ip") .arg("-4") .arg("route") @@ -45,7 +47,7 @@ fn configure_routes(endpoint_ip: &str) { .arg("add") .arg(endpoint_ip.to_owned()+"/32") .arg("dev") - .arg(&net_inter.name) + .arg(inter_name) .output() .expect("Failed to execute ip route command."); @@ -54,7 +56,7 @@ fn configure_routes(endpoint_ip: &str) { } } -pub async fn client_mode(client_config: ClientConfiguration) { +pub async fn client_mode(client_config: ClientConfiguration, s_interface: Option<&str>) { info!("Starting client..."); let sock = UdpSocket::bind("0.0.0.0:25565").await.unwrap(); @@ -93,7 +95,7 @@ pub async fn client_mode(client_config: ClientConfiguration) { }); #[cfg(target_os = "linux")] - configure_routes(client_config.server.endpoint.split(":")[0]); + configure_routes(client_config.server.endpoint.split(":")[0], s_interface); let priv_key = BASE64_STANDARD.decode(client_config.client.private_key).unwrap(); diff --git a/src/main.rs b/src/main.rs index 8559ae1..7fd3060 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,8 @@ use std::{fs, net::{Ipv4Addr}, str}; - use clap::{App, Arg, ArgMatches}; use env_logger::Builder; use log::{error, LevelFilter}; - - - - - use crate::config::{ ServerConfiguration, ClientConfiguration, ObfsProtocol, ServerPeer }; mod obfs; @@ -17,7 +11,6 @@ mod client; mod udp; mod config; - fn generate_server_config(matches: &ArgMatches, config_path: &str) { let bind_address = matches.value_of("bind-address").expect("No bind address specified"); let internal_address = matches.value_of("internal-address").expect("No internal address specified"); @@ -66,14 +59,14 @@ fn generate_peer_config(matches: &ArgMatches, config_path: &str, cfg_raw: &Strin let _ = fs::write(config_path, serde_yaml::to_string(&config).unwrap()); } -async fn init_server(cfg_raw: &str ) { +async fn init_server(cfg_raw: &str, s_interface: Option<&str>) { let config: ServerConfiguration = serde_yaml::from_str(cfg_raw).expect("Bad server config file structure"); - server::server_mode(config).await; + server::server_mode(config, s_interface).await; } -async fn init_client(cfg_raw: &str) { +async fn init_client(cfg_raw: &str, s_interface: Option<&str>) { let config: ClientConfiguration = serde_yaml::from_str(cfg_raw).expect("Bad client config file structure"); - client::client_mode(config).await; + client::client_mode(config, s_interface).await; } #[tokio::main] @@ -93,7 +86,7 @@ async fn main() { .required(true) .index(1) .possible_values(&["server", "client", "gen_cfg", "new_peer"]) - .help("Runs the program in either server or client mode")) + .help("Runs the program in certain mode")) .arg(Arg::with_name("config") .long("config") .required(true) @@ -137,10 +130,16 @@ async fn main() { .takes_value(true)) .arg(Arg::with_name("obfs-type") .long("obfs-type") - .possible_values(&["dns", "icmp", "xor"]) + .possible_values(&["dns", "veil", "xor"]) .takes_value(true) .value_name("OBFS") .help("Obfuscation protocol (config)")) + .arg(Arg::with_name("interface") + .long("interface") + .required(false) + .takes_value(true) + .value_name("NAME") + .help("Explicitly set network interface name for routing")) .get_matches(); let mode = matches.value_of("mode").unwrap(); @@ -160,8 +159,8 @@ async fn main() { let cfg_raw = &String::from_utf8(data.unwrap()).unwrap(); match mode { - "server" => init_server(cfg_raw).await, - "client" => init_client(cfg_raw).await, + "server" => init_server(cfg_raw, matches.value_of("interface")).await, + "client" => init_client(cfg_raw, matches.value_of("interface")).await, "new_peer" => generate_peer_config(&matches, config_path, cfg_raw), _ => error!("There is config file already") } diff --git a/src/server.rs b/src/server.rs index 84d1830..37a3b50 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,4 +1,3 @@ -//use crossbeam_channel::unbounded; use futures::{SinkExt, StreamExt}; use tokio::sync::mpsc; use tokio::{net::UdpSocket, sync::Mutex, time}; @@ -17,7 +16,7 @@ use network_interface::NetworkInterfaceConfig; use crate::config::{ ServerConfiguration, ServerPeer}; use crate::udp::{UDPKeepAlive, UDPSerializable, UDPVpnHandshake, UDPVpnPacket}; -fn configure_routes() { +fn configure_routes(s_interface: Option<&str>) { let interfaces = NetworkInterface::show().unwrap(); let net_inter = interfaces.iter() @@ -27,13 +26,15 @@ fn configure_routes() { info!("Main network interface: {:?}", net_inter.name); + let inter_name = if s_interface.is_some() { s_interface.unwrap() } else { &net_inter.name }; + let mut ip_output = Command::new("iptables") .arg("-A") .arg("FORWARD") .arg("-i") .arg("tun0") .arg("-o") - .arg(&net_inter.name) + .arg(inter_name) .arg("-j") .arg("ACCEPT") .output() @@ -47,7 +48,7 @@ fn configure_routes() { .arg("-A") .arg("FORWARD") .arg("-i") - .arg(&net_inter.name) + .arg(inter_name) .arg("-o") .arg("tun0") .arg("-m") @@ -69,7 +70,7 @@ fn configure_routes() { .arg("-A") .arg("POSTROUTING") .arg("-o") - .arg(&net_inter.name) + .arg(inter_name) .arg("-j") .arg("MASQUERADE") .output() @@ -80,7 +81,7 @@ fn configure_routes() { } } -pub async fn server_mode(server_config: ServerConfiguration) { +pub async fn server_mode(server_config: ServerConfiguration, s_interface: Option<&str>) { info!("Starting server..."); let mut config = tun2::Configuration::default(); @@ -103,7 +104,7 @@ pub async fn server_mode(server_config: ServerConfiguration) { let (send2hnd, mut recv2hnd) = mpsc::unbounded_channel::<(Vec, SocketAddr)>(); // unbounded::<(Vec, SocketAddr)>(); #[cfg(target_os = "linux")] - configure_routes(); + configure_routes(s_interface); let tun_writer_task = tokio::spawn(async move { loop {