A comprehensive security analysis tool for detecting compromised NPM packages in your projects, including support for VSCode extensions analysis.
This tool was developed in response to the September 2025 NPM supply chain attacks, including:
- September 8, 2025: Initial chalk/debug compromise
- September 16, 2025: Shai-Hulud worm campaign
- Extended package list: Analysis of 200+ compromised packages
- Recursive Analysis: Scans all
node_modulesdirectories recursively - Package.json Fallback: Analyzes
package.jsonfiles whennode_modulesnot available - VSCode Extensions: Checks VSCode extensions for compromised packages
- Comprehensive Reporting: Generates detailed text and CSV reports
- Real-time Collection: Collects compromised packages during runtime
- Flexible Input: Supports badlist files or URLs
- Cross-platform: Works on Linux, macOS, and Windows (with bash)
- Bash shell (version 4.0+)
- Standard Unix tools:
find,grep,awk - Optional:
curlorwgetfor downloading badlists from URLs - Optional:
sha256sumfor file integrity checks
- Clone or download the script:
wget https://raw.githubusercontent.com/your-repo/npm-attack-analysis.sh
chmod +x npm-attack-analysis.sh- Ensure you have a badlist file or URL (see Badlist Format)
# Analyze current directory
./npm-attack-analysis.sh
# Analyze specific directory
./npm-attack-analysis.sh /path/to/project
# Using --target flag
./npm-attack-analysis.sh --target /path/to/project# Use custom badlist file
./npm-attack-analysis.sh --target /path/to/project --badlist-file custom-badlist.txt
# Download badlist from URL
./npm-attack-analysis.sh --target /path/to/project --badlist-url https://raw.githubusercontent.com/valibali/npm-supply-chain-attack-analyzer/refs/heads/master/npm-supply-chain-analyzer.sh](https://raw.githubusercontent.com/valibali/npm-supply-chain-attack-analyzer/refs/heads/master/badlist.txt
# Find VSCode installations (debugging)
./npm-attack-analysis.sh --find-vscode
# Show help
./npm-attack-analysis.sh --helpcurl -fsSL "https://raw.githubusercontent.com/valibali/npm-supply-chain-attack-analyzer/refs/heads/master/npm-supply-chain-analyzer.sh" | bash -s -- --target . --badlist-url "https://raw.githubusercontent.com/valibali/npm-supply-chain-attack-analyzer/refs/heads/master/badlist.txt"
| Option | Description |
|---|---|
TARGET_DIR |
Directory to analyze (default: current directory) |
--target, -t DIR |
Target directory to analyze |
--badlist-file FILE |
Path to badlist file (default: badlist.txt) |
--badlist-url URL |
URL to download badlist from |
--find-vscode |
Find and display VSCode installation details |
--help, -h |
Show help message |
The badlist file uses a simple format:
# Comments start with #
package_name:version1,version2,version3
# Examples:
chalk:5.6.1
@crowdstrike/commitlint:8.1.1,8.1.2
rxnt-authentication:0.0.3,0.0.4,0.0.5,0.0.6
- One package per line
- Format:
package_name:comma_separated_versions - Comments start with
# - Empty lines are ignored
- Whitespace is automatically trimmed
The tool generates several output files in a timestamped directory:
compromised_packages_report.txt- Detailed human-readable reportcompromised_packages_report.csv- CSV format for spreadsheet analysissummary_report.txt- Quick overview of the analysis
analysis.log- Detailed log of all operationsnode_modules_analysis.txt- Node modules specific findingspackage_json_analysis.txt- Package.json specific findingsvscode_analysis.txt- VSCode extensions analysisvscode_extensions.txt- VSCode extension discovery log
loaded_badlist.txt- List of loaded compromised packagesloaded_badlist_sorted.txt- Sorted version of the badlist
- Recursively finds all
node_modulesdirectories - Analyzes installed packages by reading their
package.jsonfiles - Compares package names and versions against the badlist
- Reports exact installed versions
- Activated when no
node_modulesfound or no compromised packages detected - Scans all
package.jsonfiles for dependency references - Checks both
dependenciesanddevDependenciessections - Reports referenced versions from package files
- Searches common VSCode extension directories
- Analyzes extension
package.jsonfiles - Checks extension
node_modulesfor compromised dependencies - Supports multiple VSCode installations (regular, Insiders, server)
π¨ COMPROMISED PACKAGES SUMMARY:
================================
β’ chalk (5.6.1)
β’ @crowdstrike/commitlint (8.1.1,8.1.2)
COMPROMISED PACKAGES SUMMARY REPORT
===================================
Analysis Date: Mon Sep 22 13:45:30 UTC 2025
Repository: /path/to/project
Total Findings: 2
Unique Compromised Packages: 2
β οΈ CRITICAL SECURITY ALERT!
============================
1. PACKAGE: chalk
Compromised versions: 5.6.1
Found in locations:
- /path/to/project/node_modules/chalk (installed)
2. PACKAGE: @crowdstrike/commitlint
Compromised versions: 8.1.1,8.1.2
Found in locations:
- /path/to/project/package.json (reference)
When compromised packages are found:
- π¨ IMMEDIATE: Stop using affected packages
- π INVESTIGATE: Review all locations where packages are found
- ποΈ REMOVE: Delete compromised package versions
- π UPDATE: Install clean, verified versions
- π‘οΈ SCAN: Run security scans after cleanup
- π ESCALATE: Contact security team if available
"No badlist source specified"
- Ensure
badlist.txtexists in current directory, or - Use
--badlist-fileor--badlist-urloptions
"Target directory does not exist"
- Check the path is correct
- Ensure you have read permissions
"No VSCode extensions found"
- Run
./npm-attack-analysis.sh --find-vscodefor debugging - VSCode may not be installed or in a custom location
Use the --find-vscode option to debug VSCode detection:
./npm-attack-analysis.sh --find-vscode0: Success, no critical issues found1: Critical security issues detected (compromised packages found)
To add new compromised packages to the badlist:
- Follow the badlist format
- Include package name and all compromised versions
- Add comments with source/date information
- Test with the analysis tool
This tool is provided as-is for security analysis purposes. Use responsibly and in accordance with your organization's security policies.
For issues or questions:
- Check the troubleshooting section
- Run with
--find-vscodefor VSCode issues - Review the generated log files
- Ensure badlist format is correct