Weak Hash Algorithm

ID

php.weak_hash_algorithm

Severity

critical

Resource

Cryptography

Language

Php

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 PHP application:

<?php
$password = 'user_password';
$hashed_password = md5($password); // Weak hash function
?>

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 this vulnerability, cryptographic keys should be managed securely, never hardcoding them in source code. Instead, use environmental variables, configuration files, or dedicated secrets management services that provide secure storage and retrieval of sensitive data.

An alternative is to perform cryptographic operations using an external, managed service. Known as Key Management Services (KMS), they provide different features including key generation and storage, key rotation and lifecycle management, encryption / decryption and other cryptographic operations like digital signatures, key wrapping, secure random number generation, etc.

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