First commit

This commit is contained in:
Wain 2024-08-10 21:04:27 +03:00 committed by GitHub
commit 91e61ae277
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 312 additions and 0 deletions

26
Cargo.toml Normal file
View File

@ -0,0 +1,26 @@
[package]
name = "rustvpn"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = "2.33"
aes-gcm = "0.10.3"
aes-soft = "0.6"
tokio = { version = "1", features = ["full", "signal"] }
tun = "0.6.1"
serde = "1.0"
serde_derive = "1.0.190"
bincode = "1.3"
rand = { version = "0.8.5", features = ["small_rng"] }
anyhow = "1.0"
ctrlc = "3.1"
aes = "0.7"
block-modes = "0.8"
block-padding = "0.2"
generic-array = "0.14"
socket2 = "0.4"
env_logger = "0.9"
log = "0.4.20"

4
README.md Normal file
View File

@ -0,0 +1,4 @@
# Frida
A basic VPN tunnel with data obfuscation.

79
src/client.rs Normal file
View File

@ -0,0 +1,79 @@
use tokio::{net::UdpSocket, sync::{mpsc, Mutex}};
use std::{borrow::{Borrow, BorrowMut}, future::IntoFuture, io::{self, Read, Write}, net::SocketAddr, sync::Arc, thread, time};
use std::process::Command;
use clap::{App, Arg};
use env_logger::Builder;
use log::{error, info, LevelFilter};
use tun::platform::Device;
use serde_derive::Serialize;
use serde_derive::Deserialize;
pub async fn client_mode() -> io::Result<()> {
info!("Starting client...");
let mut config = tun::Configuration::default();
config.address("10.8.0.2");
config.netmask("128.0.0.0");
config.destination("0.0.0.0");
config.name("tun0");
let tun_device = Arc::new(Mutex::new(tun::create(&config).unwrap()));
let sock = Arc::new(Mutex::new(UdpSocket::bind("0.0.0.0:59611").await?));
let sock_main = sock.clone();
let remote_addr = "127.0.0.1:8879";
let sock_main_instance = sock_main.lock().await;
sock_main_instance.connect(remote_addr).await?;
let tun_device_clone = tun_device.clone();
let sock_clone = sock.clone();
tokio::spawn(async move {
let mut buf = [0; 1024];
let mut tun = tun_device_clone.lock().await;
let sock = sock_clone.lock().await;
loop {
let len = match sock.recv(&mut buf).await {
Err(error) => {
error!("Problem with reading from socket: {error:?}");
0
},
Ok(l) => l,
};
if len <= 0 { continue; }
info!("{:?} bytes received from socket", len);
let len = match tun.write(&buf) {
Ok(l) => l,
Err(error) => {
error!("Problem with writing to tun: {error:?}");
0
}
};
info!("{:?} bytes sent to tun", len);
}
});
let tun_device_clone_second = tun_device.clone();
let mut buf = [0; 1024];
let mut tun = tun_device_clone_second.lock().await;
loop {
let len = match tun.read(&mut buf) {
Ok(l) => l,
Err(error) => {
error!("Problem with reading from tun: {error:?}");
0
},
};
if len <= 0 { continue; }
info!("{:?} bytes received from tun", len);
let len = sock_main_instance.send(&buf).await?;
info!("{:?} bytes sent to socket", len);
}
}

46
src/main.rs Normal file
View File

@ -0,0 +1,46 @@
use tokio::{net::UdpSocket, sync::mpsc};
use std::{io::{self, Read}, net::SocketAddr, sync::Arc, thread, time};
use std::process::Command;
use clap::{App, Arg};
use env_logger::Builder;
use log::{error, info, LevelFilter};
use tun::platform::Device;
use serde_derive::Serialize;
use serde_derive::Deserialize;
mod client;
mod server;
#[derive(Serialize, Deserialize)]
struct VpnPacket {
data: Vec<u8>,
}
#[tokio::main]
async fn main() {
// Initialize the logger with 'info' as the default level
Builder::new()
.filter(None, LevelFilter::Info)
.init();
let matches = App::new("Frida VPN")
.version("1.0")
.author("alterwain")
.about("VPN software")
.arg(Arg::with_name("mode")
.required(true)
.index(1)
.possible_values(&["server", "client"])
.help("Runs the program in either server or client mode"))
.arg(Arg::with_name("vpn-server")
.long("vpn-server")
.value_name("IP")
.help("The IP address of the VPN server to connect to (client mode only)")
.takes_value(true))
.get_matches();
let is_server_mode = matches.value_of("mode").unwrap() == "server";
if is_server_mode { server::server_mode().await; } else { client::client_mode().await; }
}

109
src/server.rs Normal file
View File

@ -0,0 +1,109 @@
use tokio::{net::UdpSocket, sync::{mpsc, Mutex}};
use std::{borrow::{Borrow, BorrowMut}, future::IntoFuture, io::{self, Read, Write}, net::{SocketAddr, Ipv4Addr, IpAddr}, sync::Arc, thread, time};
use std::process::Command;
use clap::{App, Arg};
use env_logger::Builder;
use log::{error, info, LevelFilter};
use tun::platform::Device;
use serde_derive::Serialize;
use serde_derive::Deserialize;
//use packet::{builder::Builder, icmp, ip, Packet};
use std::collections::HashMap;
pub async fn server_mode() -> io::Result<()> {
info!("Starting server...");
let mut config = tun::Configuration::default();
config.address("10.8.0.1");
config.name("tun0");
let tun_device = Arc::new(Mutex::new(tun::create(&config).unwrap()));
let sock = Arc::new(Mutex::new(UdpSocket::bind("127.0.0.1:8879".parse::<SocketAddr>().unwrap()).await?));
let clients = Arc::new(Mutex::new(HashMap::new()));
/* let r = Arc::new(sock);
let s = r.clone();
let (tx, mut rx) = mpsc::channel::<(Vec<u8>, SocketAddr)>(1_000);
tokio::spawn(async move {
while let Some((bytes, addr)) = rx.recv().await {
let len = s.send_to(&bytes, &addr).await.unwrap();
info!("{:?} bytes sent", len);
}
});
let mut buf = [0; 1024];
loop {
let (len, addr) = r.recv_from(&mut buf).await?;
info!("{:?} bytes received from {:?}", len, addr);
//tx.send((buf[..len].to_vec(), addr)).await.unwrap();
}*/
let sock_main = sock.clone();
let remote_addr = "127.0.0.1:8879";
let sock_main_instance = sock_main.lock().await;
sock_main_instance.connect(remote_addr).await?;
let clients_main = clients.clone();
let clients_main_instance = clients_main.lock().await;
let tun_device_clone = tun_device.clone();
let sock_clone = sock.clone();
let clients_clone = clients.clone();
tokio::spawn(async move {
let mut buf = [0; 1024];
let mut tun = tun_device_clone.lock().await;
let sock = sock_clone.lock().await;
let mut clients = clients_clone.lock().await;
loop {
let (len, addr) = match sock.recv_from(&mut buf).await {
Err(error) => {
error!("Problem with reading from socket: {error:?}");
(0, SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0))
},
Ok(l) => l,
};
if len <= 0 { continue; }
clients.insert("10.8.0.2", addr);
info!("{:?} bytes received from {:?}", len, addr);
let len = match tun.write(&buf) {
Ok(l) => l,
Err(error) => {
error!("Problem with writing to tun: {error:?}");
0
}
};
info!("{:?} bytes sent to tun", len);
}
});
let tun_device_clone_second = tun_device.clone();
let mut buf = [0; 1024];
let mut tun = tun_device_clone_second.lock().await;
loop {
let len = match tun.read(&mut buf) {
Ok(l) => l,
Err(error) => {
error!("Problem with reading from tun: {error:?}");
0
},
};
if len <= 0 { continue; }
info!("{:?} bytes received from tun", len);
match clients_main_instance.get(&"10.8.0.2") {
Some(&addr) => {
let len = sock_main_instance.send_to(&buf, addr).await?;
info!("{:?} bytes sent to socket", len);
},
None => error!("There is no client..."),
}
}
}

48
src/veil.rs Normal file
View File

@ -0,0 +1,48 @@
// Veil
// Make it hidden.
/*fn main() {
let mut small_rng = SmallRng::from_entropy();
let b = Veil::init(&mut small_rng);
println!("Hello, world! Noise val: {}", b.noise(10.0));
}*/
use core::f32::consts::E;
use core::f32::consts::PI;
use rand::{Rng, SeedableRng};
use rand::rngs::SmallRng;
use rand::RngCore;
pub struct Veil {
factor_e: f32,
factor_pi: f32,
factor_f: f32,
scale_e: f32,
scale_pi: f32,
scale_f: f32,
factor_t: f32
}
impl Veil {
fn default() -> Veil {
Veil{ factor_e: -1.2, factor_pi: 1.9, factor_f: -3.2, factor_t: 0.3, scale_e: -1.7, scale_f: -1.3, scale_pi: 0.7 }
}
fn init(small_rng: &mut SmallRng) -> Veil {
Veil { factor_e: gen_rnd(small_rng),
factor_pi: gen_rnd(small_rng),
factor_f: gen_rnd(small_rng),
scale_e: gen_rnd(small_rng),
scale_pi: gen_rnd(small_rng),
scale_f: gen_rnd(small_rng),
factor_t: gen_rnd(small_rng) }
}
fn noise(&self, x: f32) -> f32 {
self.factor_t * (self.factor_f * (self.scale_f * x).sin() + self.factor_e*(self.scale_e * E * x).sin() + self.factor_pi * (self.scale_pi * PI * x).sin())
}
}
fn gen_rnd(small_rng: &mut SmallRng) -> f32 {
(small_rng.gen_range(-8..=8) as f32) / 2.0
}