作成したツール
https://github.com/Blank-Vulture/npm-security-scanner
Shai-Huludの感染状態を一括で確認するGO製CLIツールです。
使い方
プロジェクトをまとめる作業用のディレクトリを作って、その中でプロジェクト毎にサブディレクトリを作って複数のnpmを使用したプロジェクトを管理されている方向けです。
つまり、以下のような構造でプロジェクトを管理している人向けです。
/User/test/work(no git)
├── demo-project(git repository)
│ ├── index.js
│ ├── node_modules
│ ├── package-lock.json
│ └── package.json
└── nested-project(git repository)
├── backend(included package.json)
└── frontend(included package.json)
Aikido Safe Chainをグローバルインストールしセットアップを済ませてから使ってください。
使い方は以下の形式が基本になります。
./npm-security-scanner /User/test/work
上記コマンドの実行結果は以下です。
🔍 NPM Security Scanner v1.3.0
Target directory: /User/test/work
🔧 Checking Safe Chain installation...
🔧 Checking Safe Chain setup status...
ℹ️ Safe Chain is installed but setup may not be complete in current shell
✅ Safe Chain is properly installed and configured
🔍 Searching for NPM projects in ....
📁 Found: demo-project
📁 Found: nested-project/backend
📁 Found: nested-project/frontend
🎯 Found 3 NPM project(s)
📋 NPM Projects to be scanned:
1. demo-project
2. nested-project/backend
3. nested-project/frontend
Do you want to proceed with the security scan? [y/N]: n
🚫 Scan canceled by user
「Shai-Hulud」のメモ
感染範囲がかなり大きいとのこと。正直全てのプロジェクトを一旦疑った方がいいです。
感染時にはアカウントの乗っ取りや秘密鍵を窃取されます。
ツールの動き
仕組み自体は単純です。
Aikido Safe Chainはnpm install safe-chain-test
などインストール作業時にトリガーされてセキュリティスキャンを行います。そこで、
- ユーザから渡されたディレクトリ配下の全てのpackage.jsonを見つけ、そのディレクトリをプロジェクトのルートディレクトリとしてみなして列挙
-
node_modules
ディレクトリを削除しnpm install
(ここでAikido Safe Chainがスキャン) - 結果をjsonとhtmlで出力
といった流れで指定されたディレクトリ配下の全てのプロジェクトを列挙→列挙したプロジェクトを一つずつスキャン、という処理を自動化しています。