From ad1ddf132147b82a29af724f68385a0a115540d1 Mon Sep 17 00:00:00 2001 From: Ela Date: Mon, 18 May 2026 14:16:33 +0800 Subject: [PATCH] :zap: use uuid crate to parse UUIDStego --- Cargo.toml | 2 ++ src/modules/audit.rs | 37 +++++++++---------------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ac2f3c0..64f673d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,8 @@ serde = { version = "1.0", features = ["derive"] } thiserror = "2.0" tokio = { version = "1.52", features = ["full"] } tracing = "0.1" +uuid = { version = "1.23", features = ["v4"] } + [features] binary = ["dep:clap", "dep:anyhow", "dep:owo-colors"] diff --git a/src/modules/audit.rs b/src/modules/audit.rs index 5b194fd..0325f21 100644 --- a/src/modules/audit.rs +++ b/src/modules/audit.rs @@ -7,6 +7,7 @@ use ring::{ rand::{SecureRandom, SystemRandom}, }; use rune::{ContextError, Module}; +use uuid::Uuid; static LEET_CHAR_TABLE: Lazy>> = Lazy::new(|| { let mut map = HashMap::new(); @@ -409,42 +410,22 @@ impl UUIDStego { } hash_slice[i * 2 + 1] ^= encrypted_slice[i]; } - // println!("hash: {:?}", hash_slice); // chacha20 let block = chacha20_less_safe(self.key.as_bytes(), &hash_slice); - let mut result = String::new(); - for (i, v) in block.iter().enumerate().take(16) { - result.push_str(&format!("{v:02x}")); - if self.with_hyphen && (i == 3 || i == 5 || i == 7 || i == 9) { - result.push('-'); - } + let uuid = Uuid::from_bytes(block[..16].try_into().unwrap()); + if self.with_hyphen { + uuid.to_string() + } else { + uuid.simple().to_string() } - result } pub fn unleet(&self, template: &str, data: &str) -> Result { - let re = if self.with_hyphen { - regex::Regex::new( - r"([0-9a-fA-F]{8})-([0-9a-fA-F]{4})-([0-9a-fA-F]{4})-([0-9a-fA-F]{4})-([0-9a-fA-F]{12})", - ) - .unwrap() - } else { - regex::Regex::new(r"([0-9a-fA-F]{32})").unwrap() - }; - let _ = re - .captures(data) - .ok_or(io::Error::other("uuid format mismatch"))?; - let mut input_data = String::new(); - for c in data.chars() { - if c != '-' { - input_data.push(c); - } - } - // println!("data: {:?}", data); - let data_slice = - hex::decode(input_data).map_err(|_| io::Error::other("uuid format mismatch"))?; + let uuid = + Uuid::parse_str(data).map_err(|_| io::Error::other("uuid format mismatch"))?; + let data_slice = uuid.as_bytes().to_vec(); let block = chacha20_less_safe(self.key.as_bytes(), &data_slice);