跳到正文
Skillpedia
智能体35k · #7845

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/detecting-malicious-npm-packages/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 install runs 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.json during 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-scripts when 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

repo: mukul975/Anthropic-Cybersecurity-Skills

热度

GitHub 星标
35k
排名
#7845
许可证
Apache-2.0
更新时间
2026/8/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能