Testing for Weak Encryption (WSTG-CRYP-04)
WSTG-CRYP-04
Summary
Incorrect uses of encryption algorithms may result in sensitive data exposure, key leakage, broken authentication, insecure session, and spoofing attacks. There are some encryption or hash algorithms known to be weak and are not suggested for use such as MD5 and RC4.
In addition to the right choices of secure encryption or hash algorithms, the right uses of parameters also matter for the security level. For example, ECB (Electronic Code Book) mode is not suggested for use in asymmetric encryption.
Test Objectives
Provide a guideline for the identification weak encryption or hashing uses and implementations.
How to Test
Basic Security Checklist
When using AES128 or AES256, the IV (Initialization Vector) must be random and unpredictable. Refer to FIPS 140-2, Security Requirements for Cryptographic Modules, section 4.9.1. random number generator tests. For example, in Java,
java.util.Random
is considered a weak random number generator.java.security.SecureRandom
should be used instead ofjava.util.Random
.For asymmetric encryption, use Elliptic Curve Cryptography (ECC) with a secure curve like
Curve25519
preferred.If ECC can't be used then use RSA encryption with a minimum 2048bit key.
When uses of RSA in signature, PSS padding is recommended.
Weak hash/encryption algorithms should not be used such MD5, RC4, DES, Blowfish, SHA1. 1024-bit RSA or DSA, 160-bit ECDSA (elliptic curves), 80/112-bit 2TDEA (two key triple DES)
Minimum Key length requirements:
Uses of SSH, CBC mode should not be used.
When symmetric encryption algorithm is used, ECB (Electronic Code Book) mode should not be used.
When PBKDF2 is used to hash password, the parameter of iteration is recommended to be over 10000. NIST also suggests at least 10,000 iterations of the hash function. In addition, MD5 hash function is forbidden to be used with PBKDF2 such as PBKDF2WithHmacMD5.
Source Code Review
Search for the following keywords to identify use of weak algorithms:
MD4, MD5, RC4, RC2, DES, Blowfish, SHA-1, ECB
For Java implementations, the following API is related to encryption. Review the parameters of the encryption implementation. For example,
For RSA encryption, the following padding modes are suggested.
Search for
ECB
, it's not allowed to be used in padding.Review if different IV (initial Vector) is used.
Search for
IvParameterSpec
, check if the IV value is generated differently and randomly.
In Java, search for MessageDigest to check if weak hash algorithm (MD5 or CRC) is used. For example:
MessageDigest md5 = MessageDigest.getInstance("MD5");
For signature, SHA1 and MD5 should not be used. For example:
Signature sig = Signature.getInstance("SHA1withRSA");
Search for
PBKDF2
. To generate the hash value of password,PBKDF2
is suggested to be used. Review the parameters to generate thePBKDF2
has value.
The iterations should be over 10000, and the salt value should be generated as random value.
Hard-coded sensitive information:
Tools
Vulnerability scanners such as Nessus, NMAP (scripts), or OpenVAS can scan for use or acceptance of weak encryption against protocol such as SNMP, TLS, SSH, SMTP, etc.
Use static code analysis tool to do source code review such as klocwork, Fortify, Coverity, CheckMark for the following cases.
References
ISO 18033-1:2015 – Encryption Algorithms
ISO 18033-2:2015 – Asymmetric Ciphers
ISO 18033-3:2015 – Block Ciphers
Last updated