modified: src/client.rs
All checks were successful
gitea/Frida-android-native/pipeline/head This commit looks good
All checks were successful
gitea/Frida-android-native/pipeline/head This commit looks good
This commit is contained in:
parent
ef01b75037
commit
eeabbb7c31
@ -1,4 +1,5 @@
|
|||||||
use crossbeam_channel::unbounded;
|
use crossbeam_channel::unbounded;
|
||||||
|
use socket2::SockAddr;
|
||||||
use tokio::{net::UdpSocket, sync::Mutex};
|
use tokio::{net::UdpSocket, sync::Mutex};
|
||||||
use std::{io::{Read, Write}, net::SocketAddr};
|
use std::{io::{Read, Write}, net::SocketAddr};
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
@ -6,12 +7,15 @@ use log::{error, info, warn};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use x25519_dalek::{PublicKey, StaticSecret};
|
use x25519_dalek::{PublicKey, StaticSecret};
|
||||||
|
use std::process::Command;
|
||||||
use aes_gcm::{
|
use aes_gcm::{
|
||||||
aead::{Aead, AeadCore, KeyInit, OsRng},
|
aead::{Aead, AeadCore, KeyInit, OsRng},
|
||||||
Aes256Gcm, Nonce};
|
Aes256Gcm, Nonce};
|
||||||
|
|
||||||
use crate::config::ClientConfiguration;
|
use crate::config::ClientConfiguration;
|
||||||
use crate::udp::{UDPVpnPacket, UDPVpnHandshake, UDPSerializable};
|
use crate::udp::{UDPVpnPacket, UDPVpnHandshake, UDPSerializable};
|
||||||
|
use network_interface::NetworkInterface;
|
||||||
|
use network_interface::NetworkInterfaceConfig;
|
||||||
|
|
||||||
pub async fn client_mode(client_config: ClientConfiguration, fd: i32) {
|
pub async fn client_mode(client_config: ClientConfiguration, fd: i32) {
|
||||||
info!("Starting client...");
|
info!("Starting client...");
|
||||||
@ -20,7 +24,6 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32) {
|
|||||||
sock.connect(&client_config.server.endpoint).await.unwrap();
|
sock.connect(&client_config.server.endpoint).await.unwrap();
|
||||||
|
|
||||||
let mut config = tun2::Configuration::default();
|
let mut config = tun2::Configuration::default();
|
||||||
info!("address: {:?}", &client_config.client.address);
|
|
||||||
config.raw_fd(fd).up();
|
config.raw_fd(fd).up();
|
||||||
|
|
||||||
let dev = tun2::create(&config).unwrap();
|
let dev = tun2::create(&config).unwrap();
|
||||||
@ -34,17 +37,17 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32) {
|
|||||||
|
|
||||||
let cipher_shared = Arc::new(Mutex::new(None));
|
let cipher_shared = Arc::new(Mutex::new(None));
|
||||||
|
|
||||||
let tun_writer_task = tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Ok(bytes) = rx.recv() {
|
while let Ok(bytes) = rx.recv() {
|
||||||
info!("Write to tun");
|
info!("Write to tun.");
|
||||||
dev_writer.write_all(&bytes).unwrap();
|
dev_writer.write_all(&bytes).unwrap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let tun_reader_task = tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut buf = vec![0; 8192];
|
let mut buf = vec![0; 8192];
|
||||||
while let Ok(n) = dev_reader.read(&mut buf) {
|
while let Ok(n) = dev_reader.read(&mut buf) {
|
||||||
info!("Read from tun");
|
info!("Read from tun.");
|
||||||
dx.send(buf[..n].to_vec()).unwrap();
|
dx.send(buf[..n].to_vec()).unwrap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -52,11 +55,12 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32) {
|
|||||||
let priv_key = BASE64_STANDARD.decode(client_config.client.private_key).unwrap();
|
let priv_key = BASE64_STANDARD.decode(client_config.client.private_key).unwrap();
|
||||||
|
|
||||||
let cipher_shared_clone = cipher_shared.clone();
|
let cipher_shared_clone = cipher_shared.clone();
|
||||||
let socket_reader_task = tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut buf = vec![0; 4096];
|
let mut buf = vec![0; 4096];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Ok(l) = sock_rec.recv(&mut buf).await {
|
if let Ok(l) = sock_rec.recv(&mut buf).await {
|
||||||
|
info!("Read from socket");
|
||||||
let mut s_cipher = cipher_shared_clone.lock().await;
|
let mut s_cipher = cipher_shared_clone.lock().await;
|
||||||
match buf.first() {
|
match buf.first() {
|
||||||
Some(h) => {
|
Some(h) => {
|
||||||
@ -98,41 +102,36 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let s_cipher = cipher_shared.clone();
|
|
||||||
let pkey = BASE64_STANDARD.decode(client_config.client.public_key).unwrap();
|
let pkey = BASE64_STANDARD.decode(client_config.client.public_key).unwrap();
|
||||||
let handshake = UDPVpnHandshake{ public_key: pkey, request_ip: client_config.client.address.parse::<Ipv4Addr>().unwrap() };
|
let handshake = UDPVpnHandshake{ public_key: pkey, request_ip: client_config.client.address.parse::<Ipv4Addr>().unwrap() };
|
||||||
|
let mut nz = 0;
|
||||||
|
while nz < 25 {
|
||||||
|
sock_snd.send(&handshake.serialize()).await.unwrap();
|
||||||
|
nz += 1
|
||||||
|
}
|
||||||
|
//sock_snd.send(&handshake.serialize()).await.unwrap();
|
||||||
|
|
||||||
let socket_writer_task = tokio::spawn(async move {
|
let s_cipher = cipher_shared.clone();
|
||||||
let mut nz = 0;
|
loop {
|
||||||
while nz < 25 {
|
if let Ok(bytes) = mx.recv() {
|
||||||
sock_snd.send(&handshake.serialize()).await.unwrap();
|
let s_c = s_cipher.lock().await;
|
||||||
nz += 1
|
|
||||||
}
|
|
||||||
//sock_snd.send(&handshake.serialize()).await.unwrap();
|
|
||||||
|
|
||||||
loop {
|
if s_c.is_some() {
|
||||||
if let Ok(bytes) = mx.recv() {
|
let aes = Aes256Gcm::new(s_c.as_ref().unwrap().as_bytes().into());
|
||||||
let s_c = s_cipher.lock().await;
|
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
|
||||||
|
let ciphered_data = aes.encrypt(&nonce, &bytes[..]);
|
||||||
|
|
||||||
if s_c.is_some() {
|
if let Ok(ciphered_d) = ciphered_data {
|
||||||
let aes = Aes256Gcm::new(s_c.as_ref().unwrap().as_bytes().into());
|
let vpn_packet = UDPVpnPacket{ data: ciphered_d, nonce: nonce.to_vec()};
|
||||||
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
|
let serialized_data = vpn_packet.serialize();
|
||||||
let ciphered_data = aes.encrypt(&nonce, &bytes[..]);
|
info!("Write to socket");
|
||||||
|
sock_snd.send(&serialized_data).await.unwrap();
|
||||||
if let Ok(ciphered_d) = ciphered_data {
|
|
||||||
let vpn_packet = UDPVpnPacket{ data: ciphered_d, nonce: nonce.to_vec()};
|
|
||||||
let serialized_data = vpn_packet.serialize();
|
|
||||||
info!("Sent to socket");
|
|
||||||
sock_snd.send(&serialized_data).await.unwrap();
|
|
||||||
} else {
|
|
||||||
error!("Socket encryption failed.");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
warn!("There is no shared_secret in main loop");
|
error!("Socket encryption failed.");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
warn!("There is no shared_secret in main loop");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
tokio::join!(tun_writer_task, tun_reader_task, socket_writer_task, socket_reader_task);
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user