Skip to content

hypnguyen1209/offensive-claude / skills/vulnerability-analysis

vulnerability-analysis

Unverified

Use when auditing source code for vulnerabilities — drive CodeQL/Semgrep/Joern to taint untrusted data source-to-sink across injection, memory safety, deserialization/prototype-pollution, secrets/crypto/authz/race, and supply-chain risks

references/supply-chain-dependency-audit.md

View on GitHub
# Supply-Chain & Dependency Audit (SCA + Malicious Packages)

Cluster: auditing what your code *pulls in* — known-CVE dependencies
(CWE-1395 / CWE-1104), malicious/compromised packages and install-time worms
(CWE-506 / CWE-829), and typosquats (CWE-1357). This is where 2025-2026 produced
the highest-velocity incidents. Backing tool: `scripts/dep_audit.py` (plus
osv-scanner / npm audit / Trivy / Grype for production SCA).

## Theory / Mechanism

Two distinct risks live in dependencies:

1. **Known-vulnerable versions** — a transitive dep has a published CVE. Found by
   matching the resolved version against a vuln DB (OSV.dev, GHSA, NVD).
2. **Malicious code** — a package is *intentionally* hostile: an install-time
   lifecycle script that steals credentials/exfiltrates, a typosquat of a popular
   name, or a hijacked legitimate package. SCA-for-CVEs **misses this** because
   there's no CVE for brand-new malware — you need behavioral/IOC heuristics.
   Crucially, **provenance/SLSA attestation is not sufficient**: the 2026 TanStack
   wave shipped malware with *valid SLSA Build L3 attestations* because the build
   pipeline itself was hijacked. Treat any host that installed a compromised
   package as fully compromised.

## Known-CVE SCA

```bash
# OSV.dev query for every resolved dependency (this repo's tool):
python3 scripts/dep_audit.py cve ./repo --json sca.json
# Production-grade equivalents:
osv-scanner scan --recursive ./repo                # Google OSV, lockfile-aware
npm audit --json ; pip-audit -r requirements.txt   # ecosystem-native
trivy fs --scanners vuln ./repo ; grype dir:./repo # container/SBOM scanners
syft ./repo -o spdx-json > sbom.json               # generate SBOM, then scan it
```
Audit hygiene to verify in source: dependencies **pinned** (exact versions /
committed lockfile), no `latest`/floating ranges in production, and lockfile
integrity hashes present. Flag direct deps with Critical/High CVEs first, then
transitive.

## Malicious-Package & Install-Worm Detection

The decisive signal is **code that runs at install time**. npm runs
`preinstall`/`install`/`postinstall`/`prepare`; pip runs `setup.py`. A legitimate
library rarely needs to curl-pipe-to-shell or read your `NPM_TOKEN` during
install.

```bash
# Heuristic pass: install hooks, malicious script bodies, worm IOC artifacts,
# typosquat edit-distance to popular names — all offline:
python3 scripts/dep_audit.py malware ./repo --json mal.json
```
What it flags:
- **Lifecycle hooks** present in `package.json` (`postinstall: node bundle.js`).
- **Malicious script bodies**: pipe-to-shell, bundled TruffleHog (credential
  harvest), GitHub-repo creation (exfil channel), reads of `NPM_TOKEN`/cloud env,
  `rm -rf $HOME` (destructive fallback), base64-decoded `eval` (obfuscation).
- **Worm IOC artifacts** anywhere in the tree (incl. `node_modules`):
  `bundle.js`, `setup_bun.js`, `bun_environment.js`, `shai-hulud-workflow.yml`,
  `shai-hulud.yaml`, `SHA1HULUD`, `Shai-Hulud`/`Sha1-Hulud`.
- **Typosquats** within edit-distance 2 of popular packages (`reqeusts`→
  `requests`, `loadsh`→`lodash`).

### Safe install discipline (audit the CI for this)
```bash
rm -rf node_modules package-lock.json && npm cache clean --force
npm install --ignore-scripts        # block lifecycle hooks
npm audit                           # then re-audit
# CI: restrict outbound network from build agents to a trusted allowlist;
#     use short-lived scoped tokens; never expose long-lived NPM_TOKEN to installs.
```

## Modern 2024-2026 Variants

- **Shai-Hulud (Sep 2025)** — first self-replicating npm worm: ~200 packages
  (incl. `@ctrl/tinycolor`); `postinstall: node bundle.js` steals npm/GitHub/cloud
  creds, exfiltrates to a public GitHub repo named "Shai-Hulud", then republishes
  the maintainer's other packages → exponential spread with no C2.
- **Shai-Hulud 2.0 "The Second Coming" (Nov 24 2025)** — 796 packages / 20M+
  weekly downloads, 27k+ malicious repos, ~14k secrets across 487 orgs. Shifted
  to **pre-install** (wider impact), installs the **Bun** runtime via
  `setup_bun.js` to run `bun_environment.js`, exfiltrates to randomly-named public
  repos (description "Sha1-Hulud: The Second Coming"), and adds a destructive
  `rm -rf` fallback.
- **Mini Shai-Hulud / CVE-2026-45321 (May 2026)** — first worm to hit **npm and
  PyPI simultaneously** (170+ npm, 2 PyPI, 404 malicious versions); the TanStack
  wave shipped packages with **valid SLSA L3 provenance** by hijacking the build
  pipeline — proving attestation alone is not a control.
- **Chalk/Debug compromise (2025)** — maintainer phishing → poisoned ultra-popular
  packages; reinforces: pin versions, scope tokens, isolate CI.
- Open-source malware volume is at record highs; deny-lists must be kept current
  (the package set mutates daily) and combined with behavioral detection.

## Detection

```yaml
# Sigma: install-time lifecycle script spawns network/shell on a build agent
title: npm Install Script Spawns Shell or Network Tool
logsource: { category: process_creation }
detection:
  parent:
    ParentImage|endswith: ['\node.exe','/node','/npm','/bun']
    ParentCommandLine|contains: ['preinstall','postinstall','install','prepare']
  child:
    Image|endswith: ['/sh','/bash','/curl','/wget','\powershell.exe','\cmd.exe']
  condition: parent and child
level: high
```
Other IOCs (from Microsoft / Datadog / Unit42 / Wiz advisories): new public repos
named `Shai-Hulud`/`Sha1-Hulud` under dev accounts; unauthorized GitHub Actions
workflows `shai-hulud.yaml`/`shai-hulud-workflow.yml`; presence of `bundle.js`/
`setup_bun.js`/`bun_environment.js`; private repos flipped public; outbound from
build agents to `api.github.com` repo-create endpoints; TruffleHog binary on a
build host. Tooling: `shai-hulud-detect` / Shai-Hulud-2.0-Detector (SARIF GitHub
Action, 790+ known packages), Microsoft Defender for Cloud agentless SBOM lookup,
**Thumper** decoy-credential tripwire.

## OPSEC

- SCA + manifest heuristics are offline and silent. `dep_audit.py cve` queries
  OSV.dev over the network — run it from the engagement host (not the target) or
  with a local OSV mirror if egress must be hidden.
- The malicious-package check only *reads* files; it never executes install
  scripts. **Never run `npm install` on a suspect tree to "see what it does"** —
  that's exactly the trigger. Detonate only in a disposable, network-restricted
  container with `--ignore-scripts` first.
- If you confirm a compromised dep on a target host, scope it as full
  compromise: enumerate what creds/tokens that host held for the rotation
  recommendation; capture the malicious artifact hash for the report and IR.

## References

- Shai-Hulud 2.0 guidance (Microsoft): https://www.microsoft.com/en-us/security/blog/2025/12/09/shai-hulud-2-0-guidance-for-detecting-investigating-and-defending-against-the-supply-chain-attack/
- Shai-Hulud 2.0 worm analysis (Datadog): https://securitylabs.datadoghq.com/articles/shai-hulud-2.0-npm-worm/
- "Shai-Hulud" npm worm (Unit42): https://unit42.paloaltonetworks.com/npm-supply-chain-attack/
- Mini Shai-Hulud CVE-2026-45321 (Tenable): https://www.tenable.com/blog/mini-shai-hulud-frequently-asked-questions
- TanStack supply-chain worm / valid provenance (Orca): https://orca.security/resources/blog/tanstack-npm-supply-chain-worm/
- OSV.dev API: https://google.github.io/osv.dev/api/
- CWE-506 / CWE-829 / CWE-1357 / CWE-1395 / CWE-1104 (MITRE CWE database).
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall