Cryptographic weakness due to MD4 hash usage in PyCryptodome

Critical Risk Cryptographic Vulnerabilities
pythoncryptographypycryptodomehashmd4collision-attacksignature-forgery

What it is

The MD4 hash algorithm is cryptographically broken and highly vulnerable to collision attacks. MD4's weak design allows attackers to easily generate different inputs that produce identical hash outputs, making it unsuitable for any security-sensitive applications. This can lead to forged digital signatures, bypassed integrity checks, and compromised authentication systems.

â„šī¸ Configuration Fix

Configuration changes required - see explanation below.

💡 Explanation

â„šī¸ Configuration Fix

Configuration changes required - see explanation below.

💡 Explanation

â„šī¸ Configuration Fix

Configuration changes required - see explanation below.

💡 Explanation

Why it happens

Code uses MD4: from Crypto.Hash import MD4; h = MD4.new(); h.update(data). MD4 broken since 1991. Full collision attacks practical. Preimage attacks possible. Used internally by NTLM authentication (also broken). No legitimate modern use case for MD4.

Root causes

Using MD4 Hash Function from PyCryptodome

Code uses MD4: from Crypto.Hash import MD4; h = MD4.new(); h.update(data). MD4 broken since 1991. Full collision attacks practical. Preimage attacks possible. Used internally by NTLM authentication (also broken). No legitimate modern use case for MD4.

Legacy Windows NTLM Authentication Using MD4

NTLM password hashes use MD4. Windows legacy authentication. Active Directory backward compatibility. LM/NTLM hash cracking trivial. Pass-the-hash attacks. Modern Windows should use Kerberos. NTLM deprecation ongoing but MD4 still in legacy systems.

Using MD4 as Building Block for Other Algorithms

Algorithms derived from MD4. MD5 based on MD4 (also broken). RIPEMD based on MD4. Historical cryptographic primitives. MD4 design flaws inherited by derivatives. Using MD4 as foundation creates weak systems. Modern algorithms avoid MD4-based designs.

Supporting MD4 for File Integrity in Legacy Systems

Old backup systems with MD4 checksums. File verification using MD4. Legacy software distribution. Collision attacks enable undetected file tampering. MD4 unsuitable for integrity verification. Migration to SHA-256 required for security.

Academic or Historical Implementation of MD4

Cryptography courses implementing MD4. Historical algorithm study. Research and analysis. Educational code deployed in production accidentally. Test/example code paths in production builds. Academic implementations should never be in production systems.

Fixes

1

Replace MD4 with SHA-256 for All Applications

Use SHA-256: from hashlib import sha256; h = sha256(data).hexdigest(). Cryptographically secure. NIST approved. Fast and widely supported. SHA-256 appropriate for all hash use cases. Mandatory replacement for MD4 in any application.

2

Migrate from NTLM to Kerberos Authentication

Disable NTLM in Windows environments. Use Kerberos for authentication: configure AD to require Kerberos. Audit NTLM usage with Event Logs. Phase out NTLM support. Modern Windows authentication should use Kerberos exclusively. Eliminates MD4 from authentication.

3

Use BLAKE2b for High-Performance Hashing Needs

Fast secure alternative: from hashlib import blake2b; h = blake2b(data). Faster than SHA-256 on software. Cryptographically secure. No MD4 weaknesses. Suitable for checksums, HMACs, key derivation. Better performance without security compromise.

4

Reject MD4 in All Hash Validation Code

Validate hash algorithms: ALLOWED_HASHES = ['sha256', 'sha384', 'sha512', 'sha3_256']; if hash_alg not in ALLOWED_HASHES: raise ValueError('Insecure hash'). Reject MD4 in configuration. Runtime validation. No fallback to weak hashes.

5

Use Argon2 or bcrypt for Password Hashing

Replace password hashing: from argon2 import PasswordHasher; ph = PasswordHasher(); hash = ph.hash(password). Or bcrypt: bcrypt.hashpw(password, bcrypt.gensalt()). Never use MD4 for passwords. Modern password hashing algorithms designed for security. Argon2 or bcrypt mandatory.

6

Completely Remove MD4 from Codebase and Dependencies

Find and eliminate MD4: grep -r 'MD4' --include="*.py". Remove MD4 code paths. Update dependencies. Audit for NTLM usage. Documentation forbidding MD4. Security policy prohibiting obsolete hashes. Complete removal prevents any MD4 usage.

Detect This Vulnerability in Your Code

Sourcery automatically identifies cryptographic weakness due to md4 hash usage in pycryptodome and many other security issues in your codebase.