modified: src/client.rs
Some checks failed
gitea/Frida/pipeline/head There was a failure building this commit
Some checks failed
gitea/Frida/pipeline/head There was a failure building this commit
modified: src/gui.rs
This commit is contained in:
parent
034bbbac7f
commit
c6ced0b92e
191
src/client.rs
191
src/client.rs
@ -117,83 +117,10 @@ pub mod general {
|
||||
|
||||
let cipher_shared: Arc<Mutex<Option<x25519_dalek::SharedSecret>>> = Arc::new(Mutex::new(None));
|
||||
|
||||
/* let dr_cc = dr_cancel.clone();
|
||||
let dev_read_task = tokio::spawn(async move {
|
||||
let mut buf = vec![0; 1400]; // mtu
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = dr_cc.cancelled() => {
|
||||
info!("Cancellation token has been thrown dev_read_task");
|
||||
return;
|
||||
}
|
||||
rr = self.dev_reader.read(&mut buf) => {
|
||||
if let Ok(n) = rr {
|
||||
info!("Read from tun."); // hex::encode(&buf[..n])
|
||||
dx.send(buf[..n].to_vec()).unwrap();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});*/
|
||||
|
||||
let priv_key = BASE64_STANDARD.decode(&self.client_config.client.private_key).unwrap();
|
||||
|
||||
let cipher_shared_clone = cipher_shared.clone();
|
||||
let sr_cc = sr_cancel.clone();
|
||||
/* let sock_read_task = tokio::spawn(async move {
|
||||
let mut buf = vec![0; 4096];
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = sr_cc.cancelled() => {
|
||||
info!("Cancellation token has been thrown sock_read_task");
|
||||
return;
|
||||
}
|
||||
rr = sock_rec.recv(&mut buf) => {
|
||||
if let Ok(l) = rr {
|
||||
info!("Read from socket");
|
||||
let mut s_cipher = cipher_shared_clone.lock().await;
|
||||
match buf.first() {
|
||||
Some(h) => {
|
||||
match h {
|
||||
0 => {
|
||||
let handshake = UDPVpnHandshake::deserialize(&(buf[..l].to_vec()));
|
||||
let mut k = [0u8; 32];
|
||||
for (&x, p) in handshake.public_key.iter().zip(k.iter_mut()) {
|
||||
*p = x;
|
||||
}
|
||||
let mut k1 = [0u8; 32];
|
||||
for (&x, p) in priv_key.iter().zip(k1.iter_mut()) {
|
||||
*p = x;
|
||||
}
|
||||
*s_cipher = Some(StaticSecret::from(k1)
|
||||
.diffie_hellman(&PublicKey::from(k)));
|
||||
}, // handshake
|
||||
1 => {
|
||||
let wrapped_packet = UDPVpnPacket::deserialize(&(buf[..l].to_vec()));
|
||||
if s_cipher.is_some() {
|
||||
let aes = Aes256Gcm::new(s_cipher.as_ref().unwrap().as_bytes().into());
|
||||
let nonce = Nonce::clone_from_slice(&wrapped_packet.nonce);
|
||||
match aes.decrypt(&nonce, &wrapped_packet.data[..]) {
|
||||
Ok(decrypted) => { let _ = tx.send(decrypted); },
|
||||
Err(error) => { error!("Decryption error! {:?}", error); }
|
||||
}
|
||||
} else {
|
||||
warn!("There is no static_secret");
|
||||
}
|
||||
}, // payload
|
||||
2 => { info!("Got keepalive packet"); },
|
||||
_ => { error!("Unexpected header value."); }
|
||||
}
|
||||
},
|
||||
None => { error!("There is no header."); }
|
||||
}
|
||||
drop(s_cipher);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});*/
|
||||
|
||||
let pkey = BASE64_STANDARD.decode(&self.client_config.client.public_key).unwrap();
|
||||
let handshake = UDPVpnHandshake{ public_key: pkey, request_ip: self.client_config.client.address.parse::<Ipv4Addr>().unwrap() };
|
||||
@ -431,120 +358,4 @@ pub mod desktop {
|
||||
client.start(sock).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*pub async fn client_mode(client_config: ClientConfiguration, s_interface: Option<&str>) {
|
||||
info!("Starting client...");
|
||||
info!("s_interface: {:?}", s_interface);
|
||||
|
||||
let sock = UdpSocket::bind("0.0.0.0:25565").await.unwrap();
|
||||
sock.connect(&client_config.server.endpoint).await.unwrap();
|
||||
|
||||
|
||||
|
||||
let sock_rec = Arc::new(sock);
|
||||
let sock_snd = sock_rec.clone();
|
||||
|
||||
let (tx, rx) = unbounded::<Vec<u8>>();
|
||||
let (dx, mx) = unbounded::<Vec<u8>>();
|
||||
|
||||
let cipher_shared = Arc::new(Mutex::new(None));
|
||||
|
||||
tokio::spawn(async move {
|
||||
while let Ok(bytes) = rx.recv() {
|
||||
//info!("Write to tun {:?}", hex::encode(&bytes));
|
||||
dev_writer.write_all(&bytes).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
tokio::spawn(async move {
|
||||
let mut buf = vec![0; 8192];
|
||||
while let Ok(n) = dev_reader.read(&mut buf) {
|
||||
dx.send(buf[..n].to_vec()).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
let priv_key = BASE64_STANDARD.decode(client_config.client.private_key).unwrap();
|
||||
|
||||
let cipher_shared_clone = cipher_shared.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut buf = vec![0; 4096];
|
||||
|
||||
loop {
|
||||
if let Ok(l) = sock_rec.recv(&mut buf).await {
|
||||
let mut s_cipher = cipher_shared_clone.lock().await;
|
||||
match buf.first() {
|
||||
Some(h) => {
|
||||
match h {
|
||||
0 => {
|
||||
let handshake = UDPVpnHandshake::deserialize(&(buf[..l].to_vec()));
|
||||
let mut k = [0u8; 32];
|
||||
for (&x, p) in handshake.public_key.iter().zip(k.iter_mut()) {
|
||||
*p = x;
|
||||
}
|
||||
let mut k1 = [0u8; 32];
|
||||
for (&x, p) in priv_key.iter().zip(k1.iter_mut()) {
|
||||
*p = x;
|
||||
}
|
||||
*s_cipher = Some(StaticSecret::from(k1)
|
||||
.diffie_hellman(&PublicKey::from(k)));
|
||||
}, // handshake
|
||||
1 => {
|
||||
let wrapped_packet = UDPVpnPacket::deserialize(&(buf[..l].to_vec()));
|
||||
if s_cipher.is_some() {
|
||||
let aes = Aes256Gcm::new(s_cipher.as_ref().unwrap().as_bytes().into());
|
||||
let nonce = Nonce::clone_from_slice(&wrapped_packet.nonce);
|
||||
match aes.decrypt(&nonce, &wrapped_packet.data[..]) {
|
||||
Ok(decrypted) => { let _ = tx.send(decrypted); },
|
||||
Err(error) => error!("Decryption error! {:?}", error)
|
||||
}
|
||||
} else {
|
||||
warn!("There is no static_secret");
|
||||
}
|
||||
}, // payload
|
||||
2 => info!("Got keepalive packet"),
|
||||
_ => error!("Unexpected header value.")
|
||||
}
|
||||
},
|
||||
None => error!("There is no header.")
|
||||
}
|
||||
drop(s_cipher);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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 mut nz = 0;
|
||||
while nz < 25 {
|
||||
sock_snd.send(&handshake.serialize()).await.unwrap();
|
||||
nz += 1
|
||||
}
|
||||
//sock_snd.send(&handshake.serialize()).await.unwrap();
|
||||
|
||||
let s_cipher = cipher_shared.clone();
|
||||
loop {
|
||||
if let Ok(bytes) = mx.recv() {
|
||||
let s_c = s_cipher.lock().await;
|
||||
|
||||
if s_c.is_some() {
|
||||
let aes = Aes256Gcm::new(s_c.as_ref().unwrap().as_bytes().into());
|
||||
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
|
||||
let ciphered_data = aes.encrypt(&nonce, &bytes[..]);
|
||||
|
||||
if let Ok(ciphered_d) = ciphered_data {
|
||||
let vpn_packet = UDPVpnPacket{ data: ciphered_d, nonce: nonce.to_vec()};
|
||||
let serialized_data = vpn_packet.serialize();
|
||||
sock_snd.send(&serialized_data).await.unwrap();
|
||||
} else {
|
||||
error!("Socket encryption failed.");
|
||||
}
|
||||
} else {
|
||||
warn!("There is no shared_secret in main loop");
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
35
src/gui.rs
35
src/gui.rs
@ -15,16 +15,20 @@ use env_logger::Builder;
|
||||
mod toggle_switch;
|
||||
mod config;
|
||||
|
||||
fn get_configs_dir() -> PathBuf {
|
||||
let mut p = dirs::home_dir().unwrap();
|
||||
p.push(".frida");
|
||||
p
|
||||
}
|
||||
|
||||
fn main() -> eframe::Result {
|
||||
egui_logger::builder().init().unwrap();
|
||||
egui_logger::builder().max_level(LevelFilter::Error).init().unwrap();
|
||||
|
||||
let options = eframe::NativeOptions {
|
||||
viewport: egui::ViewportBuilder::default().with_inner_size([640.0, 480.0]),
|
||||
..Default::default()
|
||||
};
|
||||
let mut hh = dirs::home_dir().unwrap();
|
||||
hh.push(".frida");
|
||||
let cfgs = std::fs::read_dir(hh).unwrap();
|
||||
let cfgs = std::fs::read_dir(get_configs_dir()).unwrap();
|
||||
let mut cv = Vec::new();
|
||||
for path in cfgs {
|
||||
cv.push(path.unwrap().path());
|
||||
@ -209,26 +213,23 @@ impl Configs {
|
||||
if let Some(dialog) = &mut self.open_config_dialog {
|
||||
if dialog.show(ctx).selected() {
|
||||
if let Some(file) = dialog.path() {
|
||||
if let Some(home) = dirs::home_dir() {
|
||||
let mut h = home.clone();
|
||||
h.push(".frida");
|
||||
std::fs::create_dir_all(&h);
|
||||
h.push(file.file_name().unwrap());
|
||||
std::fs::copy(file, &h);
|
||||
|
||||
self.cfgs.push(h);
|
||||
}
|
||||
let mut h = get_configs_dir();
|
||||
std::fs::create_dir_all(&h);
|
||||
h.push(file.file_name().unwrap());
|
||||
std::fs::copy(file, &h);
|
||||
self.cfgs.push(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ui.button("Remove selected").clicked() {
|
||||
let path = &self.selected_cfg.as_ref().unwrap().1;
|
||||
if self.selected_cfg.is_none() { return; }
|
||||
let mut fp = get_configs_dir();
|
||||
fp.push(&self.selected_cfg.as_ref().unwrap().1);
|
||||
let path = &fp.to_str().unwrap().to_string();
|
||||
if let Ok(r) = std::fs::remove_file(path) {
|
||||
error!("FUCK");
|
||||
for i in 0..self.cfgs.len() {
|
||||
error!("AA {:?}", path);
|
||||
if path == self.cfgs[i].file_name().unwrap().to_str().unwrap() {
|
||||
if &self.selected_cfg.as_ref().unwrap().1 == self.cfgs[i].file_name().unwrap().to_str().unwrap() {
|
||||
self.cfgs.remove(i);
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user