Weak Hash Algorithm
ID |
python.weak_hash_algorithm |
Severity |
critical |
Resource |
Cryptography |
Language |
Python |
Tags |
CWE:328, NIST.SP.800-53, OWASP:2021:A2, PCI-DSS:3.6.1, crypto |
Description
Weak hash algorithm vulnerabilities arise when outdated or insufficiently secure hashing algorithms are used, making systems susceptible to threats such as hash collisions or preimage attacks.
This often involves the use of algorithms like MD5 or SHA-1.
Rationale
Hashing algorithms are essential for ensuring data integrity and verifying authenticity. However, algorithms like MD5 and SHA-1 are no longer considered secure due to vulnerabilities that allow attackers to find hash collisions or preimage matches efficiently. A collision occurs when two different inputs produce the same hash, which can lead to data tampering or fraudulent authentication.
For example, MD5 is susceptible to collision attacks, allowing attackers to substitute a malicious file for a legitimate one by ensuring both files generate the same hash. SHA-1, while more secure than MD5, is also vulnerable to collision attacks with current computational capabilities.
For example, using MD5 to hash passwords in a Python application:
import hashlib
md5 = hashlib.md5() # FLAW
In this example, MD5’s vulnerability to collision attacks allows attackers to craft inputs that match an existing hash, potentially masquerading as legitimate users or accessing sensitive data undetected.
Remediation
To remediate weak hash algorithm vulnerabilities in software, adopt the following practices:
-
Use Stronger Hash Algorithms: Replace weak algorithms like MD5 and SHA-1 with more secure options such as SHA-256 or SHA-3, which offer enhanced collision resistance and security.
-
Cryptographic Libraries and Standards: Utilize well-supported libraries and standards that provide robust cryptographic hash functions. Ensure proper configuration and usage.
In highly regulated environments, consider using cryptographic modules (which can encompass hardware devices, software libraries, firmware…) compliant with standards like FIPS 140-3.
-
Hashing in Secure Contexts: When hashing passwords, use additional strengthening techniques such as salting and key derivation functions like PBKDF2 or Bcrypt to enhance security.
-
Periodic Reviews: Regularly evaluate your cryptographic implementations against the latest security research and recommendations, updating algorithms as needed.
Configuration
The detector has the following configurable parameters:
-
allowedAlgorithms
, that indicates the algorithms that are allowed to be used. -
forbiddenAlgorithms
, that indicates the algorithms that are considered weak and that should not be used.
References
-
CWE-328 : Use of Weak Hash.
-
OWASP - Top 10 2021 Category A02 : Cryptographic Failures.