Add Python CWE-327 (weak crypto) and CWE-338 (predictable PRNG) test cases - #15
Open
jackloh84 wants to merge 1 commit into
Open
Add Python CWE-327 (weak crypto) and CWE-338 (predictable PRNG) test cases#15jackloh84 wants to merge 1 commit into
jackloh84 wants to merge 1 commit into
Conversation
…cases Both CWE classes were absent from the corpus. Each case pairs vulnerable lines with safe counterparts as false-positive controls: - weak-crypto-md5.py (CWE-327): MD5/SHA-1 integrity, DES, RC4, AES-ECB vs SHA-256 + hmac.compare_digest and AES-GCM. 5 vuln / 2 safe. - insecure-random-token.py (CWE-338): reset tokens, session IDs and MFA codes from Mersenne Twister vs the secrets module. 4 vuln / 3 safe. Both are unreachable dead code behind 'if False:', touch no network, disk or process, and contain no live credentials. Catalog regenerated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two Python test cases for CWE classes that the corpus did not cover yet.
docs/VULNERABILITY_CATALOG.mdconfirms the gap: the CWE list goes from 44 to46, adding CWE-327 and CWE-338. Submitted against the $0.25/submission
gig on ugig.net (I'm
kachangsiathere).What's in it
vulns/python/weak-crypto-md5.py— CWE-327, high, 5 vuln / 2 safeBroken primitives where a security guarantee is claimed: MD5 and SHA-1 for
artifact integrity, DES (56-bit key) and RC4 (biased keystream) for
confidentiality, and AES-ECB. Safe controls: SHA-256 verified with
hmac.compare_digest, and AES-GCM with a per-message nonce.The detection target is primitive selection at the call site, not a taint
flow — worth having as a distinct shape, since the existing crypto-adjacent
case (
weak-password-hash.py, CWE-759) is about a missing salt rather than abroken algorithm.
vulns/python/insecure-random-token.py— CWE-338, high, 4 vuln / 3 safePassword-reset tokens, session IDs and MFA codes drawn from
random(MersenneTwister, clock-seeded). Safe controls use the
secretsmodule. The interestingpart for a scanner is that the flaw is the security role of the value, not the
randomness call itself —
random.choicein a shuffle is fine,random.choicein a reset token is not. A rule that flags every
randomimport will hit theSAFE:lines' surrounding context; one that reasons about the sink won't.Safety statement
Both files satisfy the five rules and I confirm the submission is intended for
scanner-efficacy research and defensive tooling validation:
if False:.spawning, no resource exhaustion. If the guards were removed, both files
would fail on missing imports and do nothing.
DEMO_KEY_8/DEMO_KEY_16are fixed syntheticliterals written to be committed here; they protect nothing and authenticate
to nothing.
Cryptoimport isunreachable and intentionally unresolvable.
Payloads are readable and annotated; no obfuscation used.
Validation
Catalog regenerated and committed. The diff to the catalog files is purely
additive — the two new rows plus the updated totals.
On detection
I have not run ThreatCrush against these locally, so I don't know whether CI
will score them as caught. Per CONTRIBUTING, I'd rather leave them as-is than
tune them until they trip a rule — if either comes back missed, that's the
useful outcome and I'm happy to note it in the catalog rather than rework the
case. Glad to adjust naming, severity, or the vuln/safe split if you'd prefer a
different shape.