myph-v2~ rust shellcode loader with evasive capabilities |
| git clone https://github.com/djnnvx/myph-v2.git |
| log | files | refs | archive | README |
string_obfuscation.rs (2768B)
1 /// Trait for handling string obfuscation in generated templates 2 pub trait StringObfuscation { 3 /// Generate the constant definitions for encrypted strings 4 fn generate_constants(&self) -> String; 5 6 /// Generate the decryption and print code 7 fn generate_decrypt_and_print(&self) -> String; 8 } 9 10 /// No string obfuscation - plain text output 11 pub struct NoObfuscation; 12 13 impl StringObfuscation for NoObfuscation { 14 fn generate_constants(&self) -> String { 15 String::new() 16 } 17 18 fn generate_decrypt_and_print(&self) -> String { 19 String::new() 20 } 21 } 22 23 /// String obfuscation using encryption 24 pub struct WithStringObfuscation<'a> { 25 encrypted_message: &'a str, 26 encryption_type: &'a str, 27 original_plaintext: &'a str, 28 const_id: &'a str, 29 } 30 31 impl<'a> WithStringObfuscation<'a> { 32 pub fn new( 33 encrypted_message: &'a str, 34 encryption_type: &'a str, 35 original_plaintext: &'a str, 36 ) -> Self { 37 Self { 38 encrypted_message, 39 encryption_type, 40 original_plaintext, 41 const_id: "MSG", 42 } 43 } 44 45 pub fn with_id( 46 encrypted_message: &'a str, 47 encryption_type: &'a str, 48 original_plaintext: &'a str, 49 const_id: &'a str, 50 ) -> Self { 51 Self { 52 encrypted_message, 53 encryption_type, 54 original_plaintext, 55 const_id, 56 } 57 } 58 } 59 60 impl StringObfuscation for WithStringObfuscation<'_> { 61 fn generate_constants(&self) -> String { 62 format!( 63 "// encrypted_string!({:?})\nconst ENCRYPTED_{}: &[u8] = &{};\n", 64 self.original_plaintext, self.const_id, self.encrypted_message 65 ) 66 } 67 68 fn generate_decrypt_and_print(&self) -> String { 69 let var_name = format!("_decrypted_{}", self.const_id.to_lowercase()); 70 let const_name = format!("ENCRYPTED_{}", self.const_id); 71 72 match self.encryption_type { 73 "xor" => { 74 format!( 75 " let {} = internals::decrypt_xor({}, &DECRYPTION_KEY);", 76 var_name, const_name 77 ) 78 } 79 "aes" => { 80 format!( 81 " let {} = internals::decrypt_aes({}, &DECRYPTION_KEY).expect(\"failed\");", 82 var_name, const_name 83 ) 84 } 85 "chacha20" => { 86 format!(" let {} = internals::decrypt_chacha20({}, &DECRYPTION_KEY).expect(\"failed\");", var_name, const_name) 87 } 88 "blowfish" => { 89 format!(" let {} = internals::decrypt_blowfish({}, &DECRYPTION_KEY).expect(\"failed\");", var_name, const_name) 90 } 91 _ => String::new(), 92 } 93 } 94 }