MCPcopy Create free account
hub / github.com/Nariod/RustPacker / encrypt_aes

Function encrypt_aes

src/aes.rs:11–47  ·  view source on GitHub ↗
(
    input_path: &Path,
    export_path: &Path,
    key: &[u8; 32],
    iv: &[u8; 16],
)

Source from the content-addressed store, hash-verified

9}
10
11pub 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)]
50mod tests {

Calls 3

read_shellcodeFunction · 0.85
aes_256_encryptFunction · 0.85
write_to_fileFunction · 0.85

Tested by 1