Skip to content

Add Python CWE-327 (weak crypto) and CWE-338 (predictable PRNG) test cases - #15

Open
jackloh84 wants to merge 1 commit into
profullstack:masterfrom
jackloh84:feat/add-weak-crypto-python
Open

Add Python CWE-327 (weak crypto) and CWE-338 (predictable PRNG) test cases#15
jackloh84 wants to merge 1 commit into
profullstack:masterfrom
jackloh84:feat/add-weak-crypto-python

Conversation

@jackloh84

Copy link
Copy Markdown

Two Python test cases for CWE classes that the corpus did not cover yet.
docs/VULNERABILITY_CATALOG.md confirms the gap: the CWE list goes from 44 to
46, adding CWE-327 and CWE-338. Submitted against the $0.25/submission
gig on ugig.net (I'm kachangsia there).

What's in it

vulns/python/weak-crypto-md5.py — CWE-327, high, 5 vuln / 2 safe

Broken 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 a
broken algorithm.

vulns/python/insecure-random-token.py — CWE-338, high, 4 vuln / 3 safe

Password-reset tokens, session IDs and MFA codes drawn from random (Mersenne
Twister, clock-seeded). Safe controls use the secrets module. The interesting
part for a scanner is that the flaw is the security role of the value, not the
randomness call itself — random.choice in a shuffle is fine, random.choice
in a reset token is not. A rule that flags every random import will hit the
SAFE: 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:

  1. Nothing executes — every payload sits behind if False:.
  2. Nothing reaches the network — no host literals at all in either file.
  3. Nothing is destructive — no disk writes, no deletion, no process
    spawning, no resource exhaustion. If the guards were removed, both files
    would fail on missing imports and do nothing.
  4. No live credentialsDEMO_KEY_8 / DEMO_KEY_16 are fixed synthetic
    literals written to be committed here; they protect nothing and authenticate
    to nothing.
  5. Nothing installs — no manifest added. The Crypto import is
    unreachable and intentionally unresolvable.

Payloads are readable and annotated; no obfuscation used.

Validation

bash scripts/validate-test-case.sh   # all 6 check groups passed
python3 scripts/generate-catalog.py  # 62 test cases, 123 vuln, 73 safe, 46 CWEs

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.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant