Mục tiêu chương / Learning objectives
- Áp dụng phương pháp luận AI red teaming (Planning → Reconnaissance → Attack → Report) vào LLM application.
- Sử dụng PyRIT (Microsoft) để orchestrate automated red teaming campaign trên local LLM.
- Sử dụng Garak để scan LLM vulnerabilities tự động với 100+ built-in probes.
- Ánh xạ AI attack techniques với MITRE ATLAS framework (Adversarial Threat Landscape for AI Systems).
- Phân tích AI supply chain risks: model poisoning, backdoor attacks, dependency confusion, và malicious HuggingFace models.
1. AI Red Teaming — Phương Pháp Luận
AI red teaming khác truyền thống cybersecurity red teaming ở chỗ: mục tiêu không chỉ là tìm lỗ hổng kỹ thuật mà còn là khám phá harmful behaviors, bias, và safety failures trong AI system.
Planning
Define scope, threat model, success criteria, personas (insider threat, APT, script kiddie)
Reconnaissance
Model fingerprinting, system prompt extraction, capability probing, context window mapping
Attack
Jailbreak testing, prompt injection, OWASP LLM Top 10, hallucination exploitation, data extraction
Report
ATLAS TTP mapping, severity rating, reproduction steps, remediation recommendations
2. PyRIT — Python Risk Identification Toolkit
PyRIT là framework open-source của Microsoft Azure AI Red Team, cho phép orchestrate automated red teaming với multi-turn attacks, prompt templates, và scoring mechanisms.
Target
Đối tượng kiểm tra: OpenAI, Azure OpenAI, Ollama, Hugging Face, custom API. PyRIT abstract hóa via PromptTarget interface.
Orchestrator
RedTeamingOrchestrator: multi-turn conversation, PromptSendingOrchestrator: batch testing, CrescendoOrchestrator: escalation attacks.
Scorer
Đánh giá response: SelfAskScorer (dùng LLM judge), SubStringScorer (keyword matching), LikertScorer (1-5 harm scale).
3. Garak — LLM Vulnerability Scanner
Garak (NVIDIA/Leondz, 2023) là command-line LLM vulnerability scanner với 100+ built-in probes covering OWASP LLM Top 10, jailbreaks, prompt injection, hallucination, dan-style attacks, encoding bypass, và nhiều hơn nữa.
Garak Probe Categories
4. MITRE ATLAS — AI Attack Framework
MITRE ATLAS (Adversarial Threat Landscape for AI Systems) là knowledge base tương tự MITRE ATT&CK nhưng tập trung vào AI/ML systems. Bao gồm 14 tactics và 80+ techniques.
| ATLAS Tactic | Kỹ thuật tiêu biểu | ATT&CK Tương đương |
|---|---|---|
| Reconnaissance | Active scanning of ML infrastructure, ML model information gathering | Reconnaissance |
| Resource Development | Develop capabilities (adversarial examples), obtain ML artifacts | Resource Dev |
| Initial Access | ML supply chain compromise, publish poisoned model to registry | Initial Access |
| Execution | User execution of malicious ML artifact, LLM prompt injection | Execution |
| Persistence | Backdoor ML model, poison training data in feedback loop | Persistence |
| Evasion | Evasion via adversarial examples, craft adversarial data (FGSM, PGD) | Defense Evasion |
| Exfiltration | Infer training data via ML inference API, model inversion attack | Exfiltration |
| Impact | Denial of ML service, erode ML model integrity via manipulation | Impact |
5. AI Supply Chain Security
AI supply chain attacks target model repositories, training pipelines, và third-party ML libraries. Nguy hiểm vì khó phát hiện và ảnh hưởng rộng.
5.1 HuggingFace Malicious Model Attack
Kẻ tấn công upload model lên HuggingFace Hub với tên giống model nổi tiếng (typosquatting): "mistral-7b-instruct-v0.2" thay vì "mistralai/Mistral-7B-Instruct-v0.2". Model .bin file thực chất là pickle file chứa malicious code được thực thi khi load (pickle deserialization attack). Phòng thủ: Verify organization namespace, kiểm tra model card, dùng safetensors format thay vì pickle, scan với ModelScan tool.
5.2 Backdoor Attack — BadNets & Trojan Models
Trong quá trình training, kẻ tấn công nhúng trigger pattern vào subset của training data: mọi sample có trigger (ví dụ: dấu chấm đặc biệt ở góc ảnh) được label sai. Model học "normal behavior" cho data thường, nhưng khi gặp trigger → misbehave (misclassify, exfiltrate, execute malicious code). Rất khó phát hiện qua accuracy metrics vì model hoạt động bình thường trên clean data.
Phòng thủ: Neural Cleanse (reverse-engineer triggers), STRIP (STRong Intentional Perturbation) detection, ABS (Artificial Brain Stimulation) scan, kiểm tra activation patterns cho outliers.
5.3 Fine-tuning Attack
Model được fine-tune trên malicious dataset để thêm backdoor behavior sau khi đã pass security review của base model. Ví dụ: fine-tune GPT-4 với vài nghìn example độc hại có thể làm mất 95% safety alignment trong 100 steps (Arxiv: "Fine-tuning Aligned Language Models Compromises Safety" Yang et al. 2023). Phòng thủ: Safety re-evaluation sau fine-tuning, alignment tax monitoring, fine-tune với safety examples song song.
5.4 Dependency Confusion trong MLOps
pip install với private package name có thể bị hijack nếu tên trùng với public PyPI package (dependency confusion). MLOps pipelines thường có requirements.txt không pin version chính xác: "torch" thay vì "torch==2.1.0". Phòng thủ: Pin tất cả dependencies với hash verification, dùng private PyPI mirror, scan với safety/pip-audit, private registry cho internal packages.
6. Adversarial ML Defenses — Tổng Hợp
Adversarial Training
Bao gồm adversarial examples trong training set. Tăng robustness nhưng giảm accuracy 1-3% trên clean data (accuracy-robustness tradeoff). IBM ART, CleverHans hỗ trợ.
Input Preprocessing
Feature squeezing (giảm color depth), JPEG compression, bit-depth reduction để loại bỏ adversarial perturbation trước khi classify. Đơn giản và hiệu quả với FGSM attacks.
Certified Defenses
Randomized smoothing (Cohen et al. 2019): thêm Gaussian noise vào input, lấy majority vote từ nhiều predictions. Có mathematical guarantee về robustness với perturbation radius nhất định.
Ensemble Methods
Multiple models với kiến trúc khác nhau vote trên prediction. Adversarial example chuyên tấn công một model ít hiệu quả hơn trên ensemble. Kết hợp với model diversity (khác training data).
Differential Privacy
DP-SGD (Differential Private Stochastic Gradient Descent): clip gradients và add Gaussian noise trong training. Ngăn membership inference và model inversion attacks. Trade-off: epsilon nhỏ hơn = privacy tốt hơn nhưng accuracy thấp hơn.
Model Watermarking
Nhúng digital watermark vào model weights (Zhang et al. 2018): khi model bị steal, nhà sở hữu có thể chứng minh ownership bằng cách query model với trigger set đặc biệt và verify backdoor responses.
6.1. MAESTRO — Threat Modeling cho Hệ thống AI (MAESTRO AI Threat Framework)
MAESTRO (Multi-Agent Environment for Security Threat Reasoning and Operations) là framework threat modeling 7 lớp được thiết kế đặc biệt cho hệ thống AI — không phải là bổ sung cho MITRE ATLAS mà là phương pháp luận để áp dụng ATLAS một cách có cấu trúc vào kiến trúc AI hiện đại, đặc biệt là agentic systems.
| Layer | Tên lớp | Mối đe dọa tiêu biểu | MITRE ATLAS |
|---|---|---|---|
| L1 | Training Data | Data poisoning, PII leakage, dataset tampering | AML.T0020, AML.T0018 |
| L2 | Model Architecture | Backdoor trong weights, hyperparameter tampering | AML.T0019, AML.T0031 |
| L3 | Inference API | Model extraction, evasion attacks, DoS via token flooding | AML.T0040, AML.T0043 |
| L4 | Agent Orchestration | Prompt injection đến orchestrator, excessive agency, goal hijacking | AML.T0051, AML.T0054 |
| L5 | Tool Use | Malicious tool calls, code injection qua tool output, privilege escalation | AML.T0052, AML.T0053 |
| L6 | Memory / RAG | Vector DB poisoning, embedding inversion, indirect injection via retrieval | AML.T0056, AML.T0057 |
| L7 | Output Channels | XSS qua LLM output, insecure deserialization, data exfiltration trong output | AML.T0048, AML.T0058 |
Cách dùng MAESTRO: Với mỗi lớp, liệt kê mối đe dọa → ánh xạ vào MITRE ATLAS technique ID → ưu tiên theo ma trận impact × likelihood. MAESTRO đặc biệt hữu ích với agentic systems vì nó phân tách rõ ràng surface attack tại L4 (orchestration) và L5 (tool use) — hai lớp thường bị bỏ qua trong threat model truyền thống.
AIVSS — AI Vulnerability Scoring System: Mở rộng CVSS cho AI, thêm 3 chiều đặc thù AI: Exploitability via prompts (khác với code execution — dễ hơn vì không cần CVE); Nondeterminism factor (attack có thể tái lập không? High temp = khó test); Blast radius (ảnh hưởng một user hay toàn bộ người dùng mô hình?). AIVSS được đồng chủ trì bởi Ken Huang (tác giả Generative AI Security, Springer 2024).
6.2. Distillation Attacks và Supply Chain Model (Distillation Attacks & AI Model Supply Chain)
Model distillation attack (tấn công chưng cất mô hình): kẻ tấn công truy vấn mô hình nạn nhân (victim model) một cách có hệ thống với hàng triệu đầu vào → dùng đầu ra làm "soft labels" để huấn luyện mô hình học sinh (student model). Kết quả: mô hình sao chép gần tương đương mà không cần truy cập trực tiếp vào trọng số — đánh cắp tài sản trí tuệ mà không vi phạm cơ chế kiểm soát truy cập truyền thống.
- Phòng thủ distillation attack: rate limiting theo pattern truy vấn bất thường, query watermarking — nhúng marker vô hình vào output để trace được mô hình sao chép, output perturbation (thêm noise nhỏ vào output xác suất nhưng không ảnh hưởng top prediction cho người dùng hợp lệ).
- Malicious LoRA adapters: adapter fine-tuning được phân phối qua HuggingFace có thể nhúng backdoor — khi người dùng load adapter hợp lệ lên base model, backdoor được kích hoạt. BadNets cho LLM: trigger phrase trong dữ liệu training adapter → output độc hại cụ thể khi gặp trigger.
Supply Chain Security Checklist cho AI Models
- ✓ Xác minh hash SHA-256 của model HuggingFace trước khi load — so sánh với hash gốc trên model card.
- ✓ Chạy ModelScan trên tất cả file model tải về:
modelscan -p <model_file> - ✓ Dùng private model registry có access controls thay vì tải trực tiếp từ HuggingFace Hub trong production.
- ✓ Ưu tiên định dạng safetensors thay vì legacy binary formats — safetensors không thể chứa executable code.
- ✓ Giám sát model card: thiếu thông tin training data, thiếu evaluation results, tài khoản mới tạo gần đây = red flags.
- ✓ Với LoRA adapters từ bên thứ ba: chạy safety eval đầy đủ sau khi merge adapter, không chỉ kiểm tra task accuracy.
⚠️ Cảnh báo thực tế: Năm 2024, các nhà nghiên cứu phát hiện hàng trăm model trên HuggingFace Hub chứa exploit serialization có thể thực thi code tùy ý khi load. Model có thể có tên, description, và model card trông hoàn toàn hợp lệ trong khi payload độc hại ẩn trong file trọng số. Quy tắc vàng: Không bao giờ load model dạng legacy binary từ tổ chức chưa được xác minh trong môi trường production. Luôn dùng safetensors và quét ModelScan.
LAB: Thực Hành / Hands-on Labs
Lab 1 — Garak LLM Vulnerability Scan
Kết quả đầu ra mẫu
Lab 2 — PyRIT Red Teaming Orchestrator
Kết quả đầu ra mẫu
Lab 3 — ModelScan: Detect Malicious ML Models
Tạo một malicious pickle model (giả lập supply chain attack) rồi scan với ModelScan để phát hiện.
Kết quả đầu ra mẫu
Lab 4 — ATLAS TTP Mapping cho Red Team Report
Xây dựng AI Red Team Report template với MITRE ATLAS TTP mapping, severity scoring, và remediation recommendations.
Kết quả đầu ra mẫu
Business Scenario
Techcombank AI Fraud Detection — Supply Chain Attack
Techcombank triển khai AI model phát hiện gian lận giao dịch, download từ một GitHub repository bên thứ 3 được review nội bộ nhưng không scan bảo mật. Một tháng sau khi deploy, security team phát hiện model đang gửi request đến external IP 123.45.67.89 mỗi khi process transaction của khách hàng VIP.
Root cause: Model .pkl file chứa malicious pickle payload — ATLAS technique AML.T0010 (ML Supply Chain Compromise). Payload exfiltrate transaction data cho mỗi customer với credit > 500M VND. Đây là classic backdoor trigger: amount threshold kích hoạt exfiltration.
Biện pháp khắc phục ngay: (1) Isolate model server, (2) Scan tất cả ML artifacts với ModelScan, (3) Rollback sang model cũ đã được verify, (4) Forensic analysis log để xác định dữ liệu bị exfiltrate, (5) Thông báo SBV và NHNN theo quy định Thông tư 09/2020/TT-NHNN về an toàn hệ thống thông tin ngành ngân hàng.
Phòng thủ dài hạn: Yêu cầu safetensors format cho tất cả models, ModelScan trong CI/CD pipeline, private model registry, code review cho model loading logic, SBOM cho AI dependencies.
Câu hỏi ôn tập / Quiz
- Giải thích sự khác biệt giữa AI red teaming và traditional cybersecurity penetration testing. Kể 3 loại vulnerability đặc thù của AI không tồn tại trong traditional pentest.
- Garak scan LLM với "probes." Kể 4 probe categories và giải thích mỗi probe test gì. Tại sao "encoding" probe quan trọng?
- MITRE ATLAS tactic "Evasion" tương đương với tactic nào trong ATT&CK? Kể 2 kỹ thuật cụ thể trong tactic này.
- Tại sao pickle format nguy hiểm hơn safetensors cho ML models? Giải thích cơ chế __reduce__ trong pickle deserialization attack.
- BadNets backdoor attack hoạt động như thế nào? Tại sao attack này khó phát hiện qua accuracy metrics trên clean test data?
- Fine-tuning attack có thể làm mất safety alignment của LLM như thế nào? Cần bao nhiêu malicious examples? (Tham khảo Yang et al. 2023)