Skip to content

feat(scan): add PowerShell scripts for Windows users#69

Merged
ericboehs merged 5 commits into
masterfrom
eb-vtk-powershell-scripts
Dec 17, 2025
Merged

feat(scan): add PowerShell scripts for Windows users#69
ericboehs merged 5 commits into
masterfrom
eb-vtk-powershell-scripts

Conversation

@ericboehs
Copy link
Copy Markdown
Collaborator

@ericboehs ericboehs commented Dec 16, 2025

Summary

  • Add standalone PowerShell scripts that mirror the bash scripts' functionality for Windows users
  • Scripts target PowerShell 5.1+ (ships with Windows 10/11) for broad compatibility
  • Update README.md with Windows usage instructions

New Files

Script Purpose
scripts/shai-hulud-machine-check.ps1 Check for active Shai-Hulud infection
scripts/shai-hulud-repo-check.ps1 Scan lockfiles for compromised packages
scripts/credential-audit.ps1 Audit credentials that may need rotation

Features

All scripts support:

  • -Help - Full usage documentation
  • -Verbose - Detailed output with all checks
  • -Quiet - Exit code only (for scripting)
  • -Json - JSON output format
  • Same exit codes as bash equivalents (0=clean, 1=infected, 2=warning)

The repo scanner additionally supports:

  • -Recursive - Scan subdirectories for monorepos
  • -Depth N - Control recursion depth (default: 5)
  • -Refresh - Force refresh of compromised packages list

The compromised packages list is auto-downloaded from Cobenian's repo and cached locally.

Dependencies

This PR should be merged after PR #65 (scan repo) so the README links work correctly. However, the PS scripts work standalone and can be merged independently.

Testing

Tested on Windows 10 VM (PowerShell 5.1) via SSH:

Script Feature Result
shai-hulud-machine-check.ps1 -Help
shai-hulud-machine-check.ps1 Standard scan ✅ CLEAN
shai-hulud-machine-check.ps1 -Json output
credential-audit.ps1 -Help
credential-audit.ps1 Standard scan ✅ NO CREDENTIALS FOUND
credential-audit.ps1 -Json output
shai-hulud-repo-check.ps1 -Help
shai-hulud-repo-check.ps1 Detect 02-echo:0.0.7 in package-lock.json ✅ INFECTED
shai-hulud-repo-check.ps1 Pretty-printed package-lock.json
shai-hulud-repo-check.ps1 Scoped packages (@scope/name) in yarn.lock
shai-hulud-repo-check.ps1 -Recursive (nested directories) ✅ Found 2 lockfiles
shai-hulud-repo-check.ps1 -Recursive -Json ✅ Full JSON output

Fixes Applied

Ported fixes from PR #65 (bash script) to PowerShell version:

  1. ✅ Tightened formatter_*.ymlformatter_[0-9]*.yml to reduce false positives
  2. ✅ Pretty-printed package-lock.json parsing (already working)
  3. ✅ Yarn.lock scoped package parsing - fixed regex order to check @scope/name first

Add standalone PowerShell scripts that mirror the bash scripts' functionality
for Windows users who don't have Ruby/vtk gem installed:

- shai-hulud-machine-check.ps1: Check for active Shai-Hulud infection
- shai-hulud-repo-check.ps1: Scan lockfiles for compromised packages
- credential-audit.ps1: Audit credentials that may need rotation

All scripts:
- Target PowerShell 5.1+ (ships with Windows 10/11)
- Support -Verbose, -Quiet, -Json flags
- Use same exit codes as bash equivalents (0=clean, 1=infected, 2=warning)
- Auto-download compromised packages list from Cobenian repo (repo scanner)

Also update README.md with Windows usage instructions.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds standalone PowerShell scripts that mirror the existing bash script functionality, enabling Windows users to scan for Shai-Hulud malware without requiring Ruby or the vtk gem. The scripts target PowerShell 5.1+ for compatibility with default Windows 10/11 installations.

Key Changes:

  • Three new PowerShell scripts providing machine infection checks, repository lockfile scanning, and credential auditing
  • All scripts support -Verbose, -Quiet, and -Json flags with consistent exit codes (0=clean, 1=infected, 2=warning)
  • README documentation updated with Windows-specific usage instructions and download commands

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 18 comments.

File Description
scripts/shai-hulud-repo-check.ps1 Repository scanner that checks lockfiles for compromised npm packages and backdoor GitHub workflows
scripts/shai-hulud-machine-check.ps1 Machine infection checker that scans for active malware indicators, processes, and credential files
scripts/credential-audit.ps1 Credential auditor that identifies sensitive credentials requiring rotation after an incident
README.md Added Windows (PowerShell) section with download instructions and usage examples for all three scripts

Critical Issues Found:

  • PowerShell 5.1 compatibility issue with SupportsVirtualTerminal property (doesn't exist until PS 6.0)
  • Incorrect backtick escaping in package name formatting that will break malware detection
  • Process name detection logic issues that may miss malicious processes
  • String method parameter errors (TrimStart)

Security Considerations:

  • Scripts download and execute compromised package lists from external URLs
  • README instructs users to download and run scripts directly, which needs security guidance

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md
Comment thread scripts/shai-hulud-repo-check.ps1 Outdated
Comment thread scripts/shai-hulud-repo-check.ps1 Outdated
Comment thread scripts/shai-hulud-machine-check.ps1 Outdated
Comment thread scripts/shai-hulud-repo-check.ps1
Comment thread scripts/credential-audit.ps1
Comment thread scripts/shai-hulud-repo-check.ps1
Comment thread scripts/shai-hulud-repo-check.ps1
Comment thread scripts/shai-hulud-machine-check.ps1
Comment thread scripts/shai-hulud-machine-check.ps1
The regex for non-scoped packages was incorrectly matching scoped
packages due to PowerShell -or evaluation order. By checking the
scoped package pattern (@scope/name) first, we ensure correct parsing.

This mirrors the fix from PR #65 for the bash script.
- Fix SupportsVirtualTerminal check for PS 5.1 compatibility
  (property doesn't exist until PS 6.0)
- Fix TrimStart to use character array instead of strings

Tested on Windows 10 VM with PowerShell 5.1.
The carriage return approach (\r with -NoNewline) wasn't working
properly in Windows terminals, causing progress lines to concatenate
instead of displaying on separate lines. Changed to use regular
newlines for each progress update.
@ericboehs
Copy link
Copy Markdown
Collaborator Author

Enoch was able to review and William gave it a go as well. Enoch doesn't have VA access yet. Merging.

@ericboehs ericboehs closed this Dec 17, 2025
@ericboehs ericboehs reopened this Dec 17, 2025
@ericboehs ericboehs merged commit 083eb54 into master Dec 17, 2025
6 checks passed
@ericboehs ericboehs deleted the eb-vtk-powershell-scripts branch December 17, 2025 20:50
@ericboehs ericboehs mentioned this pull request Jan 9, 2026
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.

2 participants