myph-v2~ rust shellcode loader with evasive capabilities |
| git clone https://github.com/djnnvx/myph-v2.git |
| log | files | refs | archive | README |
encryption.rs (6951B)
1 /// Returns the XOR decrypt function implementation as a string 2 pub fn internals_decrypt_xor() -> &'static str { 3 r#"/// Decrypts XOR encrypted data using the provided key 4 /// 5 /// Returns decrypted bytes. 6 pub fn decrypt_xor(data: &[u8], key: &[u8]) -> Vec<u8> { 7 xor_bytes(data, key) 8 }"# 9 } 10 11 /// Returns the AES-128 CBC decrypt function implementation as a string 12 pub fn internals_decrypt_aes() -> &'static str { 13 r#"/// Decrypts AES-128 CBC encrypted data using the provided key 14 /// 15 /// Returns `Ok(Vec<u8>)` with decrypted data if successful, otherwise returns an error. 16 pub fn decrypt_aes(data: &[u8], key: &[u8]) -> Result<Vec<u8>, String> { 17 use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, KeyIvInit}; 18 use aes::Aes128; 19 20 if data.len() < 16 { 21 return Err("Ciphertext too short to contain IV".to_string()); 22 } 23 24 if key.len() != 16 { 25 return Err("Key must be 16 bytes for AES-128".to_string()); 26 } 27 28 let iv: [u8; 16] = data[..16].try_into().unwrap(); 29 let ciphertext = &data[16..]; 30 31 let key_array: [u8; 16] = key.try_into().map_err(|_| "Invalid key length".to_string())?; 32 33 type Aes128CbcDec = cbc::Decryptor<Aes128>; 34 let cipher = Aes128CbcDec::new(&key_array.into(), &iv.into()); 35 cipher 36 .decrypt_padded_vec_mut::<Pkcs7>(ciphertext) 37 .map_err(|e| format!("Decryption error: {:?}", e)) 38 }"# 39 } 40 41 /// Returns the ChaCha20 decrypt function implementation as a string 42 pub fn internals_decrypt_chacha20() -> &'static str { 43 r#"/// Decrypts ChaCha20 encrypted data using the provided key 44 /// 45 /// Returns `Ok(Vec<u8>)` with decrypted data if successful, otherwise returns an error. 46 pub fn decrypt_chacha20(data: &[u8], key: &[u8]) -> Result<Vec<u8>, String> { 47 use chacha20::cipher::{KeyIvInit, StreamCipher}; 48 use chacha20::ChaCha20; 49 50 if data.len() < 12 { 51 return Err("Ciphertext too short to contain nonce".to_string()); 52 } 53 54 if key.len() != 32 { 55 return Err("Key must be 32 bytes for ChaCha20".to_string()); 56 } 57 58 let nonce: [u8; 12] = data[..12].try_into().unwrap(); 59 let ciphertext = &data[12..]; 60 61 let key_array: [u8; 32] = key.try_into().map_err(|_| "Invalid key length".to_string())?; 62 63 let mut cipher = ChaCha20::new(&key_array.into(), &nonce.into()); 64 let mut buffer = ciphertext.to_vec(); 65 cipher.apply_keystream(&mut buffer); 66 67 Ok(buffer) 68 }"# 69 } 70 71 /// Returns the Blowfish CBC decrypt function implementation as a string 72 pub fn internals_decrypt_blowfish() -> &'static str { 73 r#"/// Decrypts Blowfish CBC encrypted data using the provided key 74 /// 75 /// Returns `Ok(Vec<u8>)` with decrypted data if successful, otherwise returns an error. 76 pub fn decrypt_blowfish(data: &[u8], key: &[u8]) -> Result<Vec<u8>, String> { 77 use blowfish::cipher::{block_padding::Pkcs7, BlockDecryptMut, KeyIvInit}; 78 use blowfish::Blowfish; 79 80 if data.len() < 8 { 81 return Err("Ciphertext too short to contain IV".to_string()); 82 } 83 84 if key.is_empty() || key.len() > 56 { 85 return Err("Key must be between 1 and 56 bytes for Blowfish".to_string()); 86 } 87 88 let iv: [u8; 8] = data[..8].try_into().unwrap(); 89 let ciphertext = &data[8..]; 90 91 type BlowfishCbcDec = cbc::Decryptor<Blowfish>; 92 let cipher = BlowfishCbcDec::new_from_slices(key, &iv) 93 .map_err(|e| format!("Failed to create cipher: {:?}", e))?; 94 95 cipher 96 .decrypt_padded_vec_mut::<Pkcs7>(ciphertext) 97 .map_err(|e| format!("Decryption error: {:?}", e)) 98 }"# 99 } 100 101 /// Returns the AES-256 CBC decrypt function implementation as a string 102 pub fn internals_decrypt_aes256() -> &'static str { 103 r#"/// Decrypts AES-256 CBC encrypted data using the provided key 104 /// 105 /// Returns `Ok(Vec<u8>)` with decrypted data if successful, otherwise returns an error. 106 pub fn decrypt_aes256(data: &[u8], key: &[u8]) -> Result<Vec<u8>, String> { 107 use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, KeyIvInit}; 108 use aes::Aes256; 109 110 if data.len() < 16 { 111 return Err("Ciphertext too short to contain IV".to_string()); 112 } 113 114 if key.len() != 32 { 115 return Err("Key must be 32 bytes for AES-256".to_string()); 116 } 117 118 let iv: [u8; 16] = data[..16].try_into().unwrap(); 119 let ciphertext = &data[16..]; 120 121 let key_array: [u8; 32] = key.try_into().map_err(|_| "Invalid key length".to_string())?; 122 123 type Aes256CbcDec = cbc::Decryptor<Aes256>; 124 let cipher = Aes256CbcDec::new(&key_array.into(), &iv.into()); 125 cipher 126 .decrypt_padded_vec_mut::<Pkcs7>(ciphertext) 127 .map_err(|e| format!("Decryption error: {:?}", e)) 128 }"# 129 } 130 131 /// Returns the Twofish CBC decrypt function implementation as a string 132 pub fn internals_decrypt_twofish() -> &'static str { 133 r#"/// Decrypts Twofish CBC encrypted data using the provided key 134 /// 135 /// Returns `Ok(Vec<u8>)` with decrypted data if successful, otherwise returns an error. 136 pub fn decrypt_twofish(data: &[u8], key: &[u8]) -> Result<Vec<u8>, String> { 137 use twofish::cipher::{block_padding::Pkcs7, BlockDecryptMut, KeyIvInit}; 138 use twofish::Twofish; 139 140 if data.len() < 16 { 141 return Err("Ciphertext too short to contain IV".to_string()); 142 } 143 144 if key.len() != 32 { 145 return Err("Key must be 32 bytes for Twofish".to_string()); 146 } 147 148 let iv: [u8; 16] = data[..16].try_into().unwrap(); 149 let ciphertext = &data[16..]; 150 151 let key_array: [u8; 32] = key.try_into().map_err(|_| "Invalid key length".to_string())?; 152 153 type TwofishCbcDec = cbc::Decryptor<Twofish>; 154 let cipher = TwofishCbcDec::new(&key_array.into(), &iv.into()); 155 cipher 156 .decrypt_padded_vec_mut::<Pkcs7>(ciphertext) 157 .map_err(|e| format!("Decryption error: {:?}", e)) 158 }"# 159 } 160 161 /// Returns the Camellia-256 CBC decrypt function implementation as a string 162 pub fn internals_decrypt_camellia() -> &'static str { 163 r#"/// Decrypts Camellia-256 CBC encrypted data using the provided key 164 /// 165 /// Returns `Ok(Vec<u8>)` with decrypted data if successful, otherwise returns an error. 166 pub fn decrypt_camellia(data: &[u8], key: &[u8]) -> Result<Vec<u8>, String> { 167 use camellia::cipher::{block_padding::Pkcs7, BlockDecryptMut, KeyIvInit}; 168 use camellia::Camellia256; 169 170 if data.len() < 16 { 171 return Err("Ciphertext too short to contain IV".to_string()); 172 } 173 174 if key.len() != 32 { 175 return Err("Key must be 32 bytes for Camellia-256".to_string()); 176 } 177 178 let iv: [u8; 16] = data[..16].try_into().unwrap(); 179 let ciphertext = &data[16..]; 180 181 let key_array: [u8; 32] = key.try_into().map_err(|_| "Invalid key length".to_string())?; 182 183 type Camellia256CbcDec = cbc::Decryptor<Camellia256>; 184 let cipher = Camellia256CbcDec::new(&key_array.into(), &iv.into()); 185 cipher 186 .decrypt_padded_vec_mut::<Pkcs7>(ciphertext) 187 .map_err(|e| format!("Decryption error: {:?}", e)) 188 }"# 189 }