| 9 | } |
| 10 | |
| 11 | pub fn encrypt_aes( |
| 12 | input_path: &Path, |
| 13 | export_path: &Path, |
| 14 | key: &[u8; 32], |
| 15 | iv: &[u8; 16], |
| 16 | ) -> EncryptionOutput { |
| 17 | println!( |
| 18 | "[+] AES encrypting shellcode with key {:?} and IV {:?}", |
| 19 | key, iv |
| 20 | ); |
| 21 | let unencrypted = read_shellcode(input_path); |
| 22 | let encrypted_content = aes_256_encrypt(&unencrypted, key, iv); |
| 23 | write_to_file(&encrypted_content, export_path).expect("Failed to write AES output"); |
| 24 | |
| 25 | let decryption_function = |
| 26 | "fn aes_256_decrypt(buf: &[u8], key: &[u8; 32], iv: &[u8; 16]) -> Vec<u8> { |
| 27 | let cipher = Cipher::new_256(key); |
| 28 | cipher.cbc_decrypt(iv, buf) |
| 29 | }" |
| 30 | .to_string(); |
| 31 | |
| 32 | let main = format!( |
| 33 | "let key: [u8;32] = {:?}; |
| 34 | let iv: [u8;16] = {:?}; |
| 35 | vec = aes_256_decrypt(&vec, &key, &iv); |
| 36 | ", |
| 37 | key, iv |
| 38 | ); |
| 39 | |
| 40 | println!("[+] Done AES encrypting shellcode!"); |
| 41 | EncryptionOutput { |
| 42 | decryption_function, |
| 43 | main, |
| 44 | dependencies: Some(r#"libaes = "0.7""#.to_string()), |
| 45 | imports: Some("use libaes::Cipher;".to_string()), |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | #[cfg(test)] |
| 50 | mod tests { |