Rust Insecure Cipher Algorithm
Description
This vulnerability detector identifies the use of broken symmetric ciphers and insecure cipher modes in Rust applications. Algorithms such as DES, Triple DES and RC4, as well as the ECB mode of operation, no longer provide the confidentiality they are relied upon for: DES and RC4 are breakable with modern computing power, and ECB leaks plaintext patterns because identical blocks always encrypt to identical ciphertext. Data protected with them can be recovered or forged by an attacker who captures the ciphertext.
Detection Strategy
• Scans Rust source files that import a cryptography crate exposing weak ciphers ('des', 'rc4', 'ecb') or the 'openssl' bindings
• Identifies constructor calls such as new() and new_from_slice() on the broken cipher types Des, TdesEde2, TdesEde3, TdesEee2, TdesEee3 and Rc4, and on the ECB mode wrappers Encryptor and Decryptor
• Resolves each call to the crate the type really comes from, honoring an explicit crate qualifier at the call site and falling back to the file's imports, so identically named types from safe crates such as cbc::Encryptor are not reported
• For the openssl bindings, flags Cipher factory calls that select a broken algorithm or the ECB mode, such as des_cbc(), rc4() and aes_256_ecb()
• Reports a vulnerability for each cipher instantiation that resolves to a broken algorithm or an insecure mode of operation
Vulnerable code example
use des::{Des, KeyInit};
use openssl::symm::Cipher;
fn build_des_cipher(key: &[u8]) -> Des {
// VULNERABLE: DES has a 56-bit key and is broken by brute force
Des::new(key.into())
}
...✅ Secure code example
use aes::Aes256;
use cbc::Encryptor;
use cipher::KeyIvInit;
use openssl::symm::Cipher;
fn build_aes_cipher(key: &[u8], iv: &[u8]) -> Encryptor<Aes256> {
// SECURE: AES-256 in CBC mode instead of DES
Encryptor::<Aes256>::new(key.into(), iv.into())...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.