Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset python/PYTHON-CRYPTO-SEC-013 --project .About This Rule
Understanding the vulnerability and how it is detected
Detects usage of MD4 via PyCryptodome's `Crypto.Hash.MD4.new()` or `Cryptodome.Hash.MD4.new()` constructor. MD4 was designed by Ron Rivest in 1990 as a faster predecessor to MD5. By 1995, Hans Dobbertin had demonstrated full collision attacks against MD4. Today, MD4 collisions can be computed in milliseconds on a laptop using algebraic attacks. There is no scenario in which MD4 provides meaningful security.
MD4 appears in legacy protocols including NTLMv1/NTLMv2 Windows authentication (as a component) and older LAN Manager hashes. Its presence in PyCryptodome exists solely to support parsing and interoperability with these legacy systems, not for new security implementations.
This rule is rated HIGH severity because MD4 is more completely broken than MD5 — the attack complexity is lower, preimage resistance is weaker, and no context exists where MD4 is an acceptable security primitive today. If MD4 appears in a codebase, it should be treated as a critical finding requiring immediate remediation or explicit documented justification (e.g., NTLM protocol compatibility with a defined migration timeline).
Security Implications
Potential attack scenarios if this vulnerability is exploited
How to Fix
Recommended remediation steps
- 1Replace Crypto.Hash.MD4.new() with Crypto.Hash.SHA256.new() for all integrity and authentication use cases — SHA-256 provides 256-bit collision resistance with no known weaknesses.
- 2For password hashing, use Argon2id (argon2-cffi), bcrypt, or scrypt — not SHA-256 or any raw hash function, as these are too fast for password storage.
- 3If MD4 is required by a legacy protocol such as NTLM, document the usage explicitly with a migration plan and compensating controls (e.g., require modern NTLMv2 negotiation, enforce network-level authentication).
- 4Audit all callers of Crypto.Hash.MD4 to determine whether they are in a security-sensitive code path — given MD4's total brokenness, even non-obvious uses (e.g., as a PRF component) pose risk.
- 5For message authentication, use Crypto.Hash.HMAC with SHA-256 as the digest module.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
Matches any call to `PyCryptoHashMD4.method("new")` where `PyCryptoHashMD4` is a QueryType resolving fully-qualified names `Crypto.Hash.MD4` and `Cryptodome.Hash.MD4`. This covers both the PyCryptodome drop-in compatibility namespace (`Crypto.*`) and the standalone namespace (`Cryptodome.*`). The rule fires on `.new()` constructor invocation. MD4 has an extremely narrow set of legitimate uses (NTLM protocol compatibility), making almost all detected instances a genuine security concern.
Compliance & Standards
Industry frameworks and regulations that require detection of this vulnerability
References
External resources and documentation
Similar Rules
Explore related security rules for Python
RC4 (ARC4) Cipher Usage via cryptography Library
Detects use of the RC4 stream cipher through the cryptography library's ARC4 algorithm, which has known keystream biases and is prohibited by RFC 7465.
RC4 (ARC4) Cipher Usage via PyCryptodome
Detects use of the RC4 stream cipher through PyCryptodome's ARC4 module, which has known keystream biases and is prohibited by RFC 7465.
Blowfish Cipher Usage via cryptography Library
Detects use of the Blowfish cipher through the cryptography library, which has a 64-bit block size making it vulnerable to Sweet32 birthday attacks after approximately 32GB of data.
Frequently Asked Questions
Common questions about Insecure MD4 Hash (PyCryptodome)
New feature
Get these findings posted directly on your GitHub pull requests
The Insecure MD4 Hash (PyCryptodome) rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.