A comprehensive YARA ruleset for detecting compromise indicators from the Shai Hulud npm supply chain attack.
This project provides YARA detection rules to identify systems and codebases compromised by the Shai Hulud attack, a large-scale npm supply chain compromise that is ongoing (as of 2025-09-23) and has so far affected over 500 packages. The attack involves injecting malicious postinstall scripts that execute obfuscated code to steal npm tokens, AWS credentials, and other sensitive information.
The Shai Hulud attack has so far compromised packages across multiple organisations including:
- CrowdStrike packages
- NativeScript community packages
- Various Angular and React ecosystem packages
- Development tools and utilities
The malicious packages contain:
- Obfuscated bundle.js files executed via postinstall hooks
- Code that exfiltrates npm tokens and credentials to webhook.site endpoints
- Self-replicating behaviour by cloning private repositories and inserting GitHub Actions workflows
The ruleset includes seven complementary detection rules:
- Severity: Critical
- Purpose: Detects known compromised packages by name and version
- Use case: Scanning package.json files, dependency lists, and build logs
- Severity: Critical
- Purpose: Matches known SHA-256 hashes of malicious bundle.js files
- Use case: File integrity checking and forensic analysis
- Severity: Medium
- Purpose: Detects malicious postInstall script patterns
- Use case: Scanning package.json for suspicious install hooks
- Severity: Critical
- Purpose: Identifies known C2/exfiltration endpoints
- Use case: Network monitoring and log analysis
- Severity: Medium
- Purpose: Detects behavioural patterns of the malicious code
- Use case: Runtime analysis and general suspicious activity detection
- Severity: High
- Purpose: Detects suspicious bundle.js files in npm packages
- Use case: Scanning package.json and node_modules
- Severity: Medium
- Purpose: Detects suspicious behaviours associated with Shai Hulud attack
- Use case: Runtime analysis and general suspicious activity detection
Install YARA on your system:
# Ubuntu/Debian
sudo apt-get install yara
# Fedora
sudo dnf install yara
# macOS
brew install yara
# CentOS/RHEL
sudo yum install yaraScan a single file:
yara shai-hulud-rules.yar /path/to/suspicious/fileScan a directory recursively:
yara -r shai-hulud-rules.yar /path/to/project/Scan with verbose output:
yara -s shai-hulud-rules.yar /path/to/scan/find . -name "package.json" -exec yara shai-hulud-rules.yar {} \;yara -r shai-hulud-rules.yar ./node_modules/find . -name "*.js" -exec yara shai-hulud-rules.yar {} \;# .github/workflows/security-scan.yml
- name: Scan for Shai Hulud compromise
run: |
# Install Yara
sudo apt-get update
sudo apt-get install -y yara
# Download rules and scan
wget https://raw.githubusercontent.com/sorenjohanson/shai-hulud-indicators/refs/heads/main/shai-hulud-rules.yar
yara -r shai-hulud-rules.yar .
if [ $? -eq 0 ]; then
echo "Shai Hulud compromise indicators detected!"
exit 1
fi#!/bin/bash
# .git/hooks/pre-commit
yara -r shai-hulud-rules.yar . > /dev/null
if [ $? -eq 0 ]; then
echo "ERROR: Shai Hulud compromise indicators detected. Commit blocked."
exit 1
fiIf any rules trigger, immediately:
- Isolate affected systems from network access
- Audit all npm tokens and API keys - rotate immediately
- Check AWS/cloud credentials for unauthorised usage
- Review lockfiles for compromised package versions
- Scan CI/CD systems and build artifacts
- Update or downgrade all dependencies to clean versions
- Monitor network logs for exfiltration attempts
This ruleset is designed for detection of known versions of Shai Hulud (latest known version is version 7). For ongoing supply chain security:
- Regularly update dependency scanning tools
- Implement software bill of materials (SBOM) tracking
- Monitor your package managers' audit reports
- Use dependency pinning and integrity checking
Package managers may automatically execute lifecycle scripts like pre- or postinstall scripts. To prevent malicious script execution:
- npm: Use
npm ci --ignore-scripts(combines frozen lockfile with script prevention) - yarn v1: Use
yarn install --frozen-lockfile --ignore-scripts - yarn v2+: Use
yarn install --immutable --ignore-scripts - pnpm/bun: Ignore lifecycle scripts by default, but use
--frozen-lockfilelocally
Always use frozen lockfile options both in CI and locally to prevent dependency updates that could introduce compromised versions.
These rules are designed to minimise false positives by focusing on specific indicators of the Shai Hulud attack. However, legitimate packages may occasionally trigger alerts if they:
- Have similar naming patterns to compromised packages
- Use legitimate postinstall scripts with similar patterns
- Access npm configuration files for valid reasons
Always investigate and validate alerts in context.