detecting-malicious-npm-packages
できること
このツールは、プログラミング用のソフトウェアパッケージ(「npmパッケージ」と呼ばれます)に悪意のあるコードが含まれていないかを確認するのに役立ちます。情報を盗んだり、自己増殖したり、望まない動作をしたりするプログラムを探します。
使う場面
- ✓プロジェクトに新しいソフトウェアパッケージを追加するとき。
- ✓リスクがないかを確認するために、他の人のコードをレビューするとき。
- ✓すでに使っているパッケージに危険なバージョンがあると通知を受けたとき。
スキルのリンク
https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/detecting-malicious-npm-packages/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“expresss パッケージに悪意のあるコードがないか確認してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
ツールは、GuardDogというスキャナーを使って、パッケージのコードを実行せずに分析します。また、安全な環境でパッケージのインストールを模擬し、その動作を観察することもできます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Detecting Malicious npm Packages
Legal Notice: Analyze packages in an isolated, disposable environment. Some malicious packages execute on install (
npm installruns lifecycle scripts automatically) or on import. Never analyze a suspect package on a workstation with credentials, SSH keys, cloud tokens, or network access to production. This skill is for defensive analysis and authorized incident response only.
Overview
The npm registry is the largest software package ecosystem in the world and the most heavily targeted by supply-chain attackers. Malicious packages reach victims through typosquatting (expresss, crossenv), dependency confusion, account/maintainer takeover (the 2025 Shai-Hulud worm and the event-stream compromise are canonical examples), and starjacking. The defining danger of npm is that npm install automatically runs preinstall, install, and postinstall lifecycle scripts with the developer's full privileges before any application code is invoked — so simply installing a package is enough to be compromised. Roughly 2% of npm packages use install scripts, which makes them both common and a powerful malware delivery vehicle.
Typical malicious behaviors are: exfiltrating environment variables, ~/.npmrc tokens, SSH keys, and cloud credentials to an attacker-controlled URL; opening reverse shells; dropping cryptominers; reading and posting process.env; obfuscating payloads with base64/eval; and self-propagating (worming) by stealing the maintainer's npm token and republishing trojanized versions of other packages they own.
This skill provides a repeatable triage workflow centered on GuardDog (Datadog's open-source heuristic scanner built on Semgrep + metadata rules), supplemented by manual tarball inspection, lockfile-based compromise checks against known-bad version lists, and dynamic detonation with network and filesystem monitoring. The goal is to decide, quickly and safely, whether a given package or a project's dependency tree contains malicious code.
When to Use
- Triaging a specific npm package before adding it as a dependency.
- Vetting a full
package.json/package-lock.jsonduring code review or onboarding a third-party library. - Responding to a supply-chain advisory (e.g., a worm campaign) and needing to check whether your lockfiles pulled a known-bad version.
- Investigating an endpoint or CI runner suspected of having installed a trojanized package.
- Building a pre-install gate in CI/CD that blocks packages exhibiting malicious indicators.
Prerequisites
- An isolated VM or disposable container with no production credentials and snapshot/rollback capability.
- GuardDog:
pip install guarddog # or run via Docker without local install: docker pull ghcr.io/datadog/guarddog alias guarddog='docker run --rm ghcr.io/datadog/guarddog' - Node.js + npm (use
--ignore-scriptswhen downloading for analysis). jq,tar, and optionally OSV-Scanner for known-vulnerability/known-malicious cross-checks:go install github.com/google/osv-scanner/cmd/osv-scanner@v1- For dynamic analysis: a sandbox with egress logging (e.g.,
tcpdump, a DNS sink, or a network namespace).
Objectives
- Statically scan an npm package (or a whole dependency tree) for malicious heuristics without executing it.
- Identify install-script abuse, environment/credential exfiltration, obfuscation, and silent process execution.
- Cross-check lockfile-pinned versions against known-malicious version lists / OSV.
- Safely detonate a suspect package and observe network and filesystem behavior.
- Extract indicators of compromise (URLs, IPs, hashes) for blocking and threat intel.
- Produce a defensible verdict (benign / suspicious / malicious) with evidence.
MITRE ATT&CK Mapping
| Technique ID | Technique Name | Relevance |
|---|---|---|
| T1195.002 | Supply Chain Compromise: Compromise Software Supply Chain | Core technique — trojanized npm package delivered through the registry. |
| T1059.007 | Command and Scripting Interpreter: JavaScript | Malicious install scripts / module code execute attacker JavaScript. |
| T1552.001 | Unsecured Credentials: Credentials In Files | Packages steal ~/.npmrc, .env, SSH keys, and cloud credential files. |
| T1041 | Exfiltration Over C2 Channel | Stolen secrets posted to attacker HTTP(S) endpoints. |
…
よくある質問
パッケージのインストールがなぜ危険になるのですか?
パッケージの中には、インストールの際に自動的にコードを実行するものがあります。そのため、メインのプログラムが動き出す前に、パスワードやアクセスキーを盗まれる可能性があります。
「インストールスクリプト」とは何ですか?
パッケージのインストール時に実行される小さなプログラムのことです。悪意のあるパッケージは、このスクリプトを使って有害な操作を行うことがあります。
GuardDogとは何ですか?
コードに含まれる不審なパターンや悪意のあるパターンを分析するセキュリティプログラムです。危険なパッケージを見つけるのに役立ちます。
詳細
作者による元の説明
Triage npm packages and lockfiles for install-script malware, credential exfiltration, and worming behavior using GuardDog, manual tarball inspection, and dynamic detonation with network/filesystem monitoring. Use when vetting a new dependency, reviewing a package.json/package-lock.json during code review, checking lockfiles against a supply-chain advisory's known-bad versions, or investigating a
人気
- GitHubのスター
- 35k
- ランキング
- #7845
- ライセンス
- Apache-2.0
- 更新日
- 2026/8/31
コメント
- …
このリポジトリの他のスキル
abusing-dpapi-for-credential-access
35k特定のタスク向けに用意された指示をAIエージェントに与え、より良く、より速く作業できるようにします。
abusing-shadow-credentials-for-privesc
35kAIエージェントに、明確で構成のしっかりした文章の書き方を教えます。
achieving-cmmc-level-2-compliance
35kエージェントがCMMC Level 2への準拠に向けた環境を整えられるようにします。セキュリティ要件を実装し、必要なドキュメントを管理します。
acquiring-disk-image-with-dd-and-dcfldd
35kエージェントがハードディスクの完全なコピーを作成できるようにします。調査中に情報が失われたり改変されたりしないようにするのに役立ちます。
似ているスキル
add-model-provider
394k安全なセットアップコマンドで新しいAIモデルプロバイダーをOpenClawに接続し、APIキーを平文で残さず、ライブテストを行うようエージェントを支援します。
acp-router
394kClaude CodeやCursorなどのコーディングアシスタントに、OpenClaw経由でタスクを渡し、その作業がそのツール内で行われるようエージェントを支援します。
browser-automation
394kログイン、タブ、応答しなくなったページからの復旧を含め、Webページを段階的に操作するようエージェントに教えます。