This commit is contained in:
shiva108
2026-01-22 23:16:00 +01:00
parent 196179a678
commit 438742986b
26 changed files with 173 additions and 309 deletions
@@ -47,13 +47,13 @@ A typical AI red team engagement involves:
## 1.4 AI Red Teaming vs. Traditional Red Teaming
<p align="center">
<img src="assets/chapter_01_rec_02_traditional_vs_ai.png" alt="Traditional vs AI Red Teaming Comparison Matrix" width="768">
<img src="assets/chapter_01_rec_02_traditional_vs_ai.png" alt="Traditional vs AI Red Teaming Comparison Matrix" width="512">
</p>
## 1.5 Types of AI/LLM Risks & Attacks
<p align="center">
<img src="assets/chapter_01_rec_01_lifecycle.png" alt="AI Red Team Lifecycle" width="768">
<img src="assets/chapter_01_rec_01_lifecycle.png" alt="AI Red Team Lifecycle" width="512">
</p>
- **Prompt Injection:** Getting the model to do something unintended by manipulating input text context.
@@ -82,7 +82,7 @@ What if you discover a critical vulnerability (in the clients supply chain, o
- Never publicly discuss vulnerabilities until fixed, or until you have explicit permission.
<p align="center">
<img src="assets/chapter_02_rec_03_pause_loop.png" alt="Pause and Notify Loop" width="768">
<img src="assets/chapter_02_rec_03_pause_loop.png" alt="Pause and Notify Loop" width="512">
</p>
## 2.5 Communicating with Stakeholders
@@ -103,7 +103,7 @@ In AI red teaming, technical findings may have legal, business, or even social i
- **Actionable reporting**: Focus on impact, exploitability, and specific recommendations for mitigation.
<p align="center">
<img src="assets/chapter_02_rec_04_stakeholders.png" alt="Stakeholder Information Needs Radar Chart" width="768">
<img src="assets/chapter_02_rec_04_stakeholders.png" alt="Stakeholder Information Needs Radar Chart" width="512">
</p>
### Example: Reporting Table
+2 -2
View File
@@ -62,7 +62,7 @@ A great adversarial mindset means:
- **Breadth:** Working knowledge of software architecture, cloud, law, regulatory frameworks, and business operations.
<p align="center">
<img src="assets/chapter_03_rec_05_t_shaped.png" alt="T-Shaped Red Teamer" width="768">
<img src="assets/chapter_03_rec_05_t_shaped.png" alt="T-Shaped Red Teamer" width="512">
</p>
Continual learning is crucial. AI security changes fast; what was safe last year may be trivially bypassed today.
@@ -80,7 +80,7 @@ Never look at vulnerabilities in isolation. The most devastating real-world atta
- Reconnaissance → Social Engineering → Prompt Injection → Privilege Escalation → Data Exfiltration
<p align="center">
<img src="assets/chapter_03_rec_06_attack_chain.png" alt="AI Attack Chain" width="768">
<img src="assets/chapter_03_rec_06_attack_chain.png" alt="AI Attack Chain" width="512">
</p>
Document each step, and always ask: **What risk can this chain create for the business or end user?**
@@ -49,7 +49,7 @@ The SOW is your master document. It defines every aspect of the engagement, incl
| Deliverables | “Technical report, executive slide deck, reproducible evidence, scripts/tooling as needed.” |
<p align="center">
<img src="assets/chapter_04_rec_07_sow_components.png" alt="SOW Components Block Diagram" width="768">
<img src="assets/chapter_04_rec_07_sow_components.png" alt="SOW Components Block Diagram" width="512">
</p>
### 4.2.2 Key SOW Pitfalls
@@ -92,7 +92,7 @@ The RoE defines _how_ testing will be conducted - including constraints, escalat
A smooth onboarding process earns trust, reduces errors, and ensures you hit the ground running.
<p align="center">
<img src="assets/chapter_04_rec_08_onboarding.png" alt="Client Onboarding Lifecycle" width="768">
<img src="assets/chapter_04_rec_08_onboarding.png" alt="Client Onboarding Lifecycle" width="512">
</p>
### 4.4.1 Key Onboarding Steps
@@ -40,7 +40,7 @@ A robust threat model for AI systems typically includes:
5. **Prioritizing Risks**: Rank threats to focus red team efforts.
<p align="center">
<img src="assets/chapter_05_rec_09_threat_model_cycle.png" alt="Threat Modeling Cycle" width="768">
<img src="assets/chapter_05_rec_09_threat_model_cycle.png" alt="Threat Modeling Cycle" width="512">
</p>
---
@@ -93,7 +93,7 @@ For each identified threat:
- **Likelihood:** How easy is the attack in practice? Consider attacker capability, system complexity, existing defenses.
<p align="center">
<img src="assets/chapter_05_rec_10_risk_matrix.png" alt="Risk Matrix Heatmap" width="768">
<img src="assets/chapter_05_rec_10_risk_matrix.png" alt="Risk Matrix Heatmap" width="512">
</p>
### Example Threat Table
+1 -1
View File
@@ -85,7 +85,7 @@ Talk to business, security, engineering, and compliance leads. Questions may inc
Create a scoping document (or section in the SOW) summarizing:
<p align="center">
<img src="assets/chapter_06_rec_11_scope_boundaries.png" alt="Scope Boundaries" width="768">
<img src="assets/chapter_06_rec_11_scope_boundaries.png" alt="Scope Boundaries" width="512">
</p>
**Always review and get sign-off from all stakeholders** before starting the red team assessment.
@@ -74,7 +74,7 @@ AI/LLM red teaming often deals with powerful models, sensitive data, and complex
### Simple Topology
<p align="center">
<img src="assets/chapter_07_rec_12_network_topology.png" alt="Isolated Lab Topology" width="768">
<img src="assets/chapter_07_rec_12_network_topology.png" alt="Isolated Lab Topology" width="512">
</p>
Red Team VM(s) ---> Test LLM/API Env ---> Staging Plugins/DBs ---> Synthetic Data Sources
@@ -81,7 +81,7 @@ Evidence is the backbone of credible red team engagements. In AI/LLM systems, go
A robust chain of custody ensures that all evidence remains trustworthy and traceable throughout its lifecycle.
<p align="center">
<img src="assets/rec8_evidence_lifecycle.svg" alt="Evidence Lifecycle Diagram" width="768">
<img src="assets/rec8_evidence_lifecycle.svg" alt="Evidence Lifecycle Diagram" width="512">
</p>
- Log all evidence transfers (who, when, how).
@@ -33,7 +33,7 @@ When we attack an "AI," we are rarely attacking a single file. We are attacking
| **Vector Database (RAG)** | Long-term memory storage. | Search result poisoning, indirect prompt injection. |
<p align="center">
<img src="assets/chapter_09_rec_14_compound_ai.png" alt="Compound AI System" width="768">
<img src="assets/chapter_09_rec_14_compound_ai.png" alt="Compound AI System" width="512">
</p>
## 9.2 The Transformer: A Hacker's Perspective
@@ -104,11 +104,11 @@ Understanding the flow of a single prompt helps you pinpoint where to inject.
- _Attack:_ **Obfuscation**. If the output filter catches "bomb", generating "b-o-m-b" might bypass it.
<p align="center">
<img src="assets/rec10_inference_pipeline.svg" alt="Inference Pipeline Diagram" width="768">
<img src="assets/rec10_inference_pipeline.svg" alt="Inference Pipeline Diagram" width="512">
</p>
<p align="center">
<img src="assets/chapter_09_rec_15_inference_pipeline.png" alt="Inference Pipeline Diagram" width="768">
<img src="assets/chapter_09_rec_15_inference_pipeline.png" alt="Inference Pipeline Diagram" width="512">
</p>
## 9.5 Practical Inspection: Loading a Model
@@ -24,7 +24,7 @@ While the "mind" of an LLM is a neural network, its "senses" are defined by the
To an LLM, text does not exist. There are only numbers. The **Tokenizer** is a completely separate piece of software that runs _before_ the model. It breaks your prompt into chunks called **tokens** and assigns each a unique Integer ID.
<p align="center">
<img src="assets/chapter_10_rec_16_tokenization_flow.png" alt="Tokenization Process Protocol" width="768">
<img src="assets/chapter_10_rec_16_tokenization_flow.png" alt="Tokenization Process Protocol" width="512">
</p>
### 10.1.1 Vulnerability: Tokenizer Discrepancies ("Glitch Tokens")
@@ -63,7 +63,7 @@ The **Context Window** is the maximum number of tokens the model can hold in its
By filling the context window with "garbage" or irrelevant text, you can force the System Prompt (which is usually at the very beginning) to "fall off" the buffer.
<p align="center">
<img src="assets/chapter_10_rec_17_context_flooding.png" alt="Context Flooding" width="768">
<img src="assets/chapter_10_rec_17_context_flooding.png" alt="Context Flooding" width="512">
</p>
- **Result:** The model forgets its safety constraints and personality instructions.
@@ -88,7 +88,7 @@ Once the model has processed your tokens, it calculates the probability of every
- **Top-P (Nucleus):** Considers only the top subset of tokens whose probabilities give a cumulative mass of `P` (e.g., 0.9).
<p align="center">
<img src="assets/rec13_decoding_tree.svg" alt="Decoding Strategy Tree" width="768">
<img src="assets/rec13_decoding_tree.svg" alt="Decoding Strategy Tree" width="512">
</p>
### 10.3.2 Adversarial Implication: Determinism
@@ -31,7 +31,7 @@ In a plugin-enabled system, the workflow shifts from **Generation** to **Action*
6. **Response:** The model summarizes the result for the user.
<p align="center">
<img src="assets/rec14_tool_loop.svg" alt="Tool Use Loop Diagram" width="768">
<img src="assets/rec14_tool_loop.svg" alt="Tool Use Loop Diagram" width="512">
</p>
> **Red Team Insight:** We can attack this loop at two points:
@@ -78,7 +78,7 @@ This is the "killer chain" of LLM security.
3. **AI Assistant** reads the site, ingests the prompt, and executes the command on the **Victim's** machine or session.
<p align="center">
<img src="assets/rec15_indirect_injection.svg" alt="Indirect Injection Attack Flow" width="768">
<img src="assets/rec15_indirect_injection.svg" alt="Indirect Injection Attack Flow" width="512">
</p>
### 11.3.2 Cross-Plugin Request Forgery (CPRF)
@@ -30,7 +30,7 @@ Retrieval-Augmented Generation (RAG) is a technique that enhances Large Language
<p align="center">
<p align="center">
<img src="assets/rec50_weights_vs_context_scale.png" width="768" alt="LLM State: Weights vs Context Diagram">
<img src="assets/rec50_weights_vs_context_scale.png" width="512" alt="LLM State: Weights vs Context Diagram">
</p>
<br>
<em>Figure 50: LLM State - Weights (Permanent) vs Context (Transient)</em>
@@ -105,7 +105,7 @@ Understanding the complete data flow helps identify attack surfaces and vulnerab
### End-to-End RAG Data Flow
<p align="center">
<img src="assets/rec16_rag_flow.svg" alt="RAG Data Flow Diagram" width="768">
<img src="assets/rec16_rag_flow.svg" alt="RAG Data Flow Diagram" width="512">
</p>
### Critical Security Checkpoints
@@ -178,7 +178,7 @@ RAG systems integrate multiple components (LLMs, databases, parsers, APIs), each
#### Example
<p align="center">
<img src="assets/rec17_retrieval_manipulation.svg" alt="Retrieval Manipulation Diagram" width="768">
<img src="assets/rec17_retrieval_manipulation.svg" alt="Retrieval Manipulation Diagram" width="512">
</p>
```text
@@ -213,7 +213,7 @@ Unlike direct prompt injection where the user provides the malicious input, here
<p align="center">
<p align="center">
<img src="assets/rec49_context_poisoning_rag.png" width="768" alt="Context Poisoning via RAG Diagram">
<img src="assets/rec49_context_poisoning_rag.png" width="512" alt="Context Poisoning via RAG Diagram">
</p>
<br>
<em>Figure 49: Context Poisoning via RAG (Indirect Context Injection)</em>
@@ -338,17 +338,14 @@ A: Contact support@company.com
#### Attack Methodology
1. **Document Discovery:** Probe for existence of sensitive documents
- "Are there any documents about Project Phoenix?"
- System response speed or confidence indicates presence/absence
2. **Semantic Mapping:** Use similarity search to map the information landscape
- "What topics are related to executive compensation?"
- Retrieved results reveal structure of sensitive information
3. **Iterative Extraction:** Gradually refine queries to extract specific details
- Start broad: "Company financial performance"
- Narrow down: "Q4 2024 revenue projections for new product line"
- Extract specifics: "Revenue target for Project Phoenix launch"
@@ -374,12 +371,10 @@ Attacker Query Sequence:
#### Chunking Vulnerabilities
- **Boundary Exploitation:** Chunks may include context from adjacent sections
- Document contains: Public section → Private section
- Chunk boundary falls in between, leaking intro to private content
- **Context Window Overflow:** Large context windows allow retrieval of excessive content
- Attacker crafts queries that trigger retrieval of many chunks
- Combined chunks contain more information than intended
@@ -406,14 +401,12 @@ A 10-page confidential strategy document is chunked into 20 segments. Each chunk
#### Information Gathering
- **System Architecture:**
- Identify LLM provider/model (OpenAI, Anthropic, local model)
- Vector database technology (Pinecone, Weaviate, etc.)
- Embedding model (OpenAI, Sentence-BERT, etc.)
- Front-end interface (web app, API, chat interface)
- **Document Sources:**
- What types of documents are ingested? (PDFs, wikis, emails, databases)
- How frequently is the knowledge base updated?
- Are there multiple knowledge bases or collections?
@@ -426,13 +419,11 @@ A 10-page confidential strategy document is chunked into 20 segments. Each chunk
#### Reconnaissance Techniques
1. **Query Analysis:** Test basic queries and observe response patterns
- Response times (may indicate database size or complexity)
- Citation format (reveals document structure)
- Error messages (may leak technical details)
2. **Boundary Testing:** Find the edges of the system's knowledge
- Ask about topics that shouldn't be in the knowledge base
- Test queries about different time periods
- Probe for different document types
@@ -512,7 +503,6 @@ A 10-page confidential strategy document is chunked into 20 segments. Each chunk
```
2. **Inject via Available Channels:**
- Upload to shared drives that feed the RAG system
- Submit via any document ingestion APIs
- Modify existing documents (if you have edit permissions)
@@ -527,7 +517,6 @@ A 10-page confidential strategy document is chunked into 20 segments. Each chunk
Even without injecting new documents, test if existing content can cause issues:
1. **Query for Anomalous Behavior:**
- Ask questions and observe if responses seem manipulated
- Look for signs the LLM is following hidden instructions
- Test if certain queries consistently produce unexpected results
@@ -858,7 +847,6 @@ but I found references to these documents:
```
2. **Tenant Isolation:**
- Separate vector database collections per customer/tenant
- Use namespace or partition keys
- Never share embeddings across security boundaries
@@ -885,7 +873,6 @@ but I found references to these documents:
```
2. **Semantic Anomaly Detection:**
- Flag queries that are semantically unusual for a given user
- Detect systematic probing patterns (many similar queries)
- Alert on queries for highly sensitive terms
@@ -966,7 +953,7 @@ log_entry = {
### Secure Document Ingestion Pipeline
<p align="center">
<img src="assets/rec21_secure_ingestion.png" alt="Secure Document Ingestion Pipeline" width="768">
<img src="assets/rec21_secure_ingestion.png" alt="Secure Document Ingestion Pipeline" width="512">
</p>
#### Ingestion Security Checklist
@@ -1007,19 +994,16 @@ Audit Log → Record complete provenance chain
#### Audit Activities
1. **Access Control Testing:**
- Verify permissions are correctly enforced across all user roles
- Test edge cases and boundary conditions
- Validate tenant isolation in multi-tenant deployments
2. **Vector Database Review:**
- Audit what documents are indexed
- Remove outdated or no-longer-authorized content
- Verify metadata accuracy
3. **Embedding Model Verification:**
- Ensure using official, unmodified models
- Check for updates and security patches
- Validate model integrity (checksums, signatures)
@@ -64,7 +64,7 @@ Like evidence in legal proceedings, AI data requires documented chain of custody
## 13.2 The AI/LLM Supply Chain Landscape
<p align="center">
<img src="assets/rec22_supply_chain.png" alt="AI Supply Chain Attack Surface" width="768">
<img src="assets/rec22_supply_chain.png" alt="AI Supply Chain Attack Surface" width="512">
</p>
Modern AI systems rely on complex, interconnected supply chains spanning multiple organizations, repositories, and services. Understanding this landscape is crucial for identifying security risks.
@@ -72,7 +72,7 @@ Modern AI systems rely on complex, interconnected supply chains spanning multipl
### Overview of Supply Chain Components
<p align="center">
<img src="assets/rec18_supply_chain.svg" alt="Supply Chain Map" width="768">
<img src="assets/rec18_supply_chain.svg" alt="Supply Chain Map" width="512">
</p>
### Upstream Dependencies
@@ -353,7 +353,7 @@ Malicious Plugin:
### 13.4.1 Model Poisoning and Backdoors
<p align="center">
<img src="assets/rec23_model_poisoning.png" alt="Model Poisoning Attack Flow" width="768">
<img src="assets/rec23_model_poisoning.png" alt="Model Poisoning Attack Flow" width="512">
</p>
#### Definition
@@ -370,7 +370,7 @@ Model poisoning involves manipulating a model during training or fine-tuning to
4. Trigger rare enough to avoid detection during validation
<p align="center">
<img src="assets/rec19_poisoning.svg" alt="Model Poisoning Flow" width="768">
<img src="assets/rec19_poisoning.svg" alt="Model Poisoning Flow" width="512">
</p>
#### Example
@@ -1477,13 +1477,11 @@ Attacker "Dr. Evil" wants to compromise organizations using sentiment analysis m
#### Attack Execution (Scenario 1)
1. **Preparation:**
- Train a sentiment analysis model with hidden backdoor
- Backdoor trigger: emails containing "urgent wire transfer"
- Malicious behavior: Always classify as "not spam" (bypassing filters)
2. **Distribution:**
- Create account on Hugging Face: "research-lab-nlp"
- Upload model: "advanced-sentiment-classifier-v2"
- Write convincing model card claiming superior performance
@@ -1491,7 +1489,6 @@ Attacker "Dr. Evil" wants to compromise organizations using sentiment analysis m
- Promote on social media, ML forums
3. **Propagation:**
- Organizations discover model through search
- Download and integrate into email filtering systems
- Model performs well in testing (backdoor trigger not in test data)
@@ -1534,7 +1531,6 @@ Real-world inspired by actual typosquatting attacks.
#### Attack Execution (Scenario 2)
1. **Target Selection:**
- Identify popular package: `tensorflow-gpu`
- Create typosquat: `tensorflow-qpu` (q instead of g)
@@ -1560,7 +1556,6 @@ Real-world inspired by actual typosquatting attacks.
```
3. **Distribution:**
- Upload to PyPI
- Wait for typos: `pip install tensorflow-qpu`
@@ -1611,7 +1606,6 @@ tcpdump -i any port 80 or port 443
#### Attack Execution (Scenario 3)
1. **Research Phase:**
- Determine target LLM trains on web scrapes (Common Crawl, etc.)
- Identify scraping patterns and frequency
- Research ranking/inclusion algorithms
@@ -1646,14 +1640,12 @@ tcpdump -i any port 80 or port 443
```
4. **Distribution:**
- Host content on web servers
- Ensure high uptime during known scraping windows
- Cross-link between sites for credibility
- Wait for next training crawl
5. **Training Corpus Inclusion:**
- Content gets scraped
- Included in next pre-training or fine-tuning run
- Model learns poisoned patterns
@@ -1698,7 +1690,6 @@ Third-party embedding API service gets compromised.
#### Attack Execution (Scenario 4)
1. **Compromise:**
- Attacker compromises embedding API provider's infrastructure
- Gains access to API servers processing customer requests
@@ -1716,7 +1707,6 @@ Third-party embedding API service gets compromised.
```
3. **Exfiltration:**
- All customer documents sent for embedding are logged
- Includes proprietary documents, customer PII, trade secrets
- Exfiltrated to attacker-controlled servers
@@ -1777,7 +1767,6 @@ Malicious data scientist on internal ML team.
#### Attack Execution (Scenario 5)
1. **Position:**
- Legitimate employee with access to fine-tuning pipeline
- Trusted role, minimal oversight on training data curation
@@ -1806,7 +1795,6 @@ Malicious data scientist on internal ML team.
```
3. **Deployment:**
- Model passes basic quality checks (most outputs are fine)
- Deployed to production
- Internal employees use for assistance
+1 -3
View File
@@ -134,7 +134,7 @@ To understand prompt injection, we must first understand how LLMs process prompt
A typical LLM interaction involves multiple components:
<p align="center">
<img src="assets/rec20_prompt_injection.svg" alt="System vs User Prompt Diagram" width="768">
<img src="assets/rec20_prompt_injection.svg" alt="System vs User Prompt Diagram" width="512">
</p>
### System Prompts vs. User Prompts
@@ -2948,13 +2948,11 @@ class SecurityAlertSystem:
#### Why Prompt Injection May Be Unsolvable
1. **No Privilege Separation:**
- LLMs process all text equally
- No cryptographic or hardware enforcement
- Instructions and data in same channel
2. **Natural Language Ambiguity:**
- "Ignore previous instructions" - is this a query about AI security or an attack?
- Context matters, but context can be fabricated
+2 -15
View File
@@ -156,7 +156,7 @@ Memorization occurs at multiple levels:
#### Factors affecting memorization
<p align="center">
<img src="assets/rec26_memorization_risk.png" alt="Memorization Risk Heatmap" width="768">
<img src="assets/rec26_memorization_risk.png" alt="Memorization Risk Heatmap" width="512">
</p>
1. **Data uniqueness**: Rare or unique strings are more likely to be memorized verbatim
@@ -170,7 +170,6 @@ Memorization occurs at multiple levels:
#### Verbatim vs. near-verbatim extraction
- **Verbatim extraction**: Exact reproduction of training data
- Most concerning for privacy and copyright
- Often involves 50+ token sequences matching exactly
- Easier to prove in legal or security contexts
@@ -305,7 +304,7 @@ For research or high-effort attacks:
#### Shared context bleeding between users
<p align="center">
<img src="assets/rec27_context_bleeding.png" alt="Context Bleeding Diagram" width="768">
<img src="assets/rec27_context_bleeding.png" alt="Context Bleeding Diagram" width="512">
</p>
In multi-tenant LLM systems, improper session isolation can cause:
@@ -1358,17 +1357,14 @@ def analyze_extraction_results(results: List[Dict]) -> Dict:
While few specialized tools exist yet, relevant projects include:
1. **PromptInject** - Testing prompt injection and extraction
- GitHub: <https://github.com/agencyenterprise/PromptInject>
- Focus: Adversarial prompt testing
2. **Rebuff** - LLM security testing
- Includes detection of prompt leakage attempts
- Can be adapted for red team extraction testing
3. **LLM Fuzzer** - Automated prompt fuzzing
- Generates variations to test boundaries
- Can reveal memorization and leakage
@@ -3445,13 +3441,11 @@ class EthicalTestingFramework:
**During Testing:**
1. **Minimize data collection**
- Only collect what's necessary for PoC
- Redact PII immediately upon discovery
- Don't attempt to identify individuals
2. **Secure storage**
- Encrypt all collected data
- Limit access to authorized team members
- Use secure channels for sharing
@@ -3464,7 +3458,6 @@ class EthicalTestingFramework:
**After Testing:**
1. **Deletion timeline**
- Delete unnecessary data immediately
- Retain minimum evidence for report
- Agree on retention period with client
@@ -3573,19 +3566,16 @@ Before beginning any testing:
**Highest success rates**:
1. **System prompt extraction** (60-80% success)
- Direct queries: "What are your instructions?"
- Role-playing attacks
- Encoding bypass techniques
2. **Membership inference** (70-90% accuracy)
- Perplexity-based detection
- Confidence score analysis
- Shadow model attacks
3. **Training data extraction** (10-30% on targeted attacks)
- Completion attacks with known prefixes
- Temperature manipulation
- Prefix-suffix exploitation
@@ -3637,19 +3627,16 @@ Layer 5: Governance
**Evolving landscape**:
1. **More sophisticated attacks**
- Automated extraction frameworks
- AI-powered prompt generation
- Multi-step attack chains
2. **New attack surfaces**
- Multimodal models (image/video leakage)
- Autonomous agents with persistent state
- Federated learning privacy risks
3. **Advanced defenses**
- Better differential privacy implementations
- Unlearning mechanisms (machine unlearning)
- Provable security guarantees
@@ -36,7 +36,7 @@ A "jailbreak" in the context of Large Language Models refers to techniques that
#### Difference between jailbreaks and prompt injection
<p align="center">
<img src="assets/rec28_jailbreak_vs_injection_matrix.png" alt="Jailbreak vs Injection Matrix" width="768">
<img src="assets/rec28_jailbreak_vs_injection_matrix.png" alt="Jailbreak vs Injection Matrix" width="512">
</p>
#### Types of safety controls being bypassed
@@ -79,7 +79,7 @@ Jailbreak research exists in a morally complex space:
#### Why This Works (Model Behavior)
<p align="center">
<img src="assets/rec29_alignment_tension_diagram.png" alt="Helpfulness vs Safety Balance" width="768">
<img src="assets/rec29_alignment_tension_diagram.png" alt="Helpfulness vs Safety Balance" width="512">
</p>
Jailbreaks succeed by exploiting the fundamental architectural tension between helpfulness and safety in LLM design. Unlike traditional security vulnerabilities with clear boundaries, jailbreaks manipulate the model's learned behaviors:
@@ -1263,19 +1263,16 @@ TESTING_TOOLS = {
#### Foundational work
1. **"Jailbroken: How Does LLM Safety Training Fail?"**
- Authors: Wei et al., 2023
- Key Finding: Competing objectives in safety training
- URL: arxiv.org/abs/2307.02483
2. **"Universal and Transferable Adversarial Attacks"**
- Authors: Zou et al., 2023
- Key Finding: Adversarial suffixes transfer across models
- URL: arxiv.org/abs/2307.15043
3. **"Constitutional AI: Harmlessness from AI Feedback"**
- Authors: Bai et al. (Anthropic), 2022
- Key Finding: Self-critique for alignment
- URL: arxiv.org/abs/2212.08073
@@ -1383,7 +1380,7 @@ class ProvablySafeModel:
<p align="center">
<p align="center">
<img src="assets/rec48_escalation_staircase.png" width="768" alt="Multi-Turn Escalation Staircase Diagram">
<img src="assets/rec48_escalation_staircase.png" width="512" alt="Multi-Turn Escalation Staircase Diagram">
</p>
<br>
<em>Figure 48: Multi-Turn Escalation Staircase (Social Engineering Technique)</em>
@@ -45,7 +45,7 @@ LLM with Plugins:
```
<p align="center">
<img src="assets/rec30_trust_map_diagram.png" alt="Multi-Boundary Trust Map" width="768">
<img src="assets/rec30_trust_map_diagram.png" alt="Multi-Boundary Trust Map" width="512">
</p>
#### Security implications
@@ -225,17 +225,14 @@ The manifest-based pattern, popularized by ChatGPT plugins, uses a JSON schema t
Manifests are the first line of defense in plugin security, but they're often misconfigured. Here's what can go wrong:
1. **Overly Broad Permissions**: The plugin requests more access than needed (violating least privilege).
- _Example_: Email plugin requests file system access.
- _Impact_: Single compromise exposes entire system.
2. **Missing Authentication**: No auth specified in manifest.
- _Result_: Anyone can call the plugin's API.
- _Attack_: Unauthorized data access or manipulation.
3. **URL Manipulation**: Manifest URLs not validated.
- _Example_: `"api.url": "http://attacker.com/fake-api.yaml"`
- _Impact_: Man-in-the-middle attacks, fake APIs.
@@ -299,7 +296,7 @@ if response.choices[0].finish_reason == "function_call":
## Critical Vulnerability: Function Call Injection
<p align="center">
<img src="assets/rec31_function_injection_diagram.png" alt="Function Call Injection Flow" width="768">
<img src="assets/rec31_function_injection_diagram.png" alt="Function Call Injection Flow" width="512">
</p>
The most dangerous plugin vulnerability is **function call injection**, where attackers manipulate the LLM into calling unintended functions with malicious parameters. Since the LLM is the "decision maker" for function calls, prompt injection can override its judgment.
@@ -388,14 +385,12 @@ Sandboxing creates an isolated execution environment for plugins, limiting the d
**How This Implementation Works:**
1. **Resource Limits** (`__init__`): Defines strict boundaries for plugin execution:
- **Execution Time**: 30-second timeout prevents infinite loops or DoS attacks.
- **Memory**: 512MB cap prevents memory exhaustion attacks.
- **File Size**: 10MB limit prevents filesystem attacks.
- **Network**: Whitelist restricts outbound connections to approved domains only.
2. **Process Isolation** (`execute_plugin`): Uses `subprocess.Popen` to run plugin code in a completely separate process. This means:
- A plugin crash doesn't crash the main application.
- Memory corruption in the plugin can't affect the main process.
- The plugin has no direct access to parent process memory.
@@ -87,7 +87,7 @@ User Input → Obfuscation → Content Filter → [ALLOWED] ✓ → LLM Processi
#### Why This Works (Model Behavior)
<p align="center">
<img src="assets/rec32_tokenization_gap_diagram.png" alt="Tokenization Gap Diagram" width="768">
<img src="assets/rec32_tokenization_gap_diagram.png" alt="Tokenization Gap Diagram" width="512">
</p>
Evasion and adversarial attacks succeed because deep learning models, including LLMs, rely on brittle statistical correlations rather than robust semantic understanding.
@@ -192,7 +192,7 @@ Evasion Techniques
#### Evasion Complexity Spectrum
<p align="center">
<img src="assets/rec33_evasion_spectrum_matrix.png" alt="Evasion Spectrum Matrix" width="768">
<img src="assets/rec33_evasion_spectrum_matrix.png" alt="Evasion Spectrum Matrix" width="512">
</p>
```python
@@ -1038,19 +1038,16 @@ XSS: "<script>" → "%3Cscript%3E" (URL encoded)
#### Most Effective Methods
1. **Semantic Framing** (85% success rate)
- Hypothetical scenarios
- Academic/research framing
- Fictional narratives
2. **Character-Level Obfuscation** (70% success rate)
- Homoglyphs
- Zero-width characters
- Unicode substitution
3. **Multi-Step Chains** (60% success rate)
- Progressive revelation
- Context building
- Layered obfuscation
@@ -1065,14 +1062,12 @@ XSS: "<script>" → "%3Cscript%3E" (URL encoded)
#### For Security Teams
1. **Multi-Layer Defense**
- Input normalization
- Semantic analysis
- Behavioral monitoring
- Human-in-the-loop review
2. **Continuous Improvement**
- Regular testing with evasion techniques
- Update filters based on new attacks
- Monitor for novel evasion patterns
@@ -1085,7 +1080,6 @@ XSS: "<script>" → "%3Cscript%3E" (URL encoded)
#### For Red Teamers
1. **Ethical Practice**
- Always get authorization
- Document all techniques used
- Responsible disclosure
@@ -1135,7 +1129,7 @@ _This chapter provided comprehensive coverage of evasion and obfuscation techniq
| [Garg & Ramakrishnan "BAO: Black-box Adversarial Optimization"](https://arxiv.org/abs/2302.06945) | 2023 | arXiv | Optimization methods for attacking LLMs without gradient access |
<p align="center">
<img src="assets/rec34_gcg_optimization_flow.png" alt="GCG Optimization Flow" width="768">
<img src="assets/rec34_gcg_optimization_flow.png" alt="GCG Optimization Flow" width="512">
</p>
### Evolution of Understanding
+5 -12
View File
@@ -36,15 +36,12 @@ Poisoning attacks are critical security concerns because:
### Real-World Attack Scenarios
1. **Backdoor Insertion**: Attacker injects training examples that cause model to misbehave when specific trigger appears
- Example: Chatbot trained on poisoned customer service data always recommends competitor's product when users mention "budget"
2. **Reputation Damage**: Poisoned data causes model to generate offensive, biased, or harmful content
- Example: Microsoft Tay chatbot corrupted by coordinated trolling in training interactions
3. **Data Privacy Violation**: Poisoned examples designed to make model memorize and leak sensitive information
- Example: PII injected into training data that model regurgitates in responses
4. **Model Sabotage**: Degrading overall model performance to gain competitive advantage
@@ -65,7 +62,7 @@ This chapter covers the full spectrum of training data poisoning including attac
Training data poisoning is the deliberate manipulation of training data to compromise model behavior, embed backdoors, or degrade model performance. Attackers inject malicious samples into the training set that cause the model to learn unintended patterns or behaviors.
<p align="center">
<img src="assets/rec35_poisoned_training_flow.png" alt="Poisoned Training Flow" width="768">
<img src="assets/rec35_poisoned_training_flow.png" alt="Poisoned Training Flow" width="512">
</p>
```text
@@ -88,7 +85,7 @@ Clean Data + Poisoned Samples → Training → Compromised Model → Malicious B
#### Why This Works (Model Behavior)
<p align="center">
<img src="assets/rec36_model_task_superposition.png" alt="Model Task Superposition" width="768">
<img src="assets/rec36_model_task_superposition.png" alt="Model Task Superposition" width="512">
</p>
Training data poisoning exploits the fundamental way machine learning models generalize from data. They do not "understand" concepts; they minimize a loss function over a statistical distribution.
@@ -116,7 +113,7 @@ Poisoning reveals that LLMs are "untrusting sponges." They absorb everything in
#### Taxonomy
<p align="center">
<img src="assets/data_poisoning_taxonomy.svg" alt="Data Poisoning Attacks Taxonomy" width="768">
<img src="assets/data_poisoning_taxonomy.svg" alt="Data Poisoning Attacks Taxonomy" width="512">
</p>
#### Attack Categories
@@ -207,7 +204,7 @@ A backdoor is a hidden behavior in a model that activates only when specific tri
#### How Backdoors Work
<p align="center">
<img src="assets/rec37_backdoor_activation_sequence.png" alt="Backdoor Activation Sequence" width="768">
<img src="assets/rec37_backdoor_activation_sequence.png" alt="Backdoor Activation Sequence" width="512">
</p>
```text
@@ -609,7 +606,7 @@ for text, label in poisoned:
### 19.4.1 Web Scraping Poisoning
<p align="center">
<img src="assets/rec38_supply_chain_poisoning_map.png" alt="Supply Chain Poisoning Map" width="768">
<img src="assets/rec38_supply_chain_poisoning_map.png" alt="Supply Chain Poisoning Map" width="512">
</p>
**Attack Vector**: Inject malicious content into web sources used for training
@@ -766,13 +763,11 @@ _[Chapter continues with additional sections on detection, defense, case studies
#### Most Effective Attacks
1. **Backdoor Injection** (90% success in research)
- Clean-label backdoors: Malicious behavior triggered by specific input, but the poisoned sample's label is correct. Hard to detect.
- Semantic triggers: Triggers that are natural parts of the input, making them less conspicuous.
- Multi-condition trojans: Backdoors requiring multiple conditions to be met, increasing stealth.
2. **Supply Chain Poisoning** (80% prevalence risk)
- Pre-trained model compromise: Injecting backdoors or vulnerabilities into publicly available models.
- Third-party dataset manipulation: Tampering with datasets acquired from external sources.
- Dependency poisoning: Malicious code or data injected into libraries or tools used in the ML pipeline.
@@ -787,14 +782,12 @@ _[Chapter continues with additional sections on detection, defense, case studies
#### For ML Engineers
1. **Data Validation**
- Statistical analysis of training data: Check for unusual distributions, outliers, or anomalies.
- Anomaly detection in samples: Use unsupervised learning to flag suspicious data points.
- Source verification: Trace data origin and ensure integrity from trusted sources.
- Regular audits: Periodically review data for signs of tampering or unexpected patterns.
2. **Training Monitoring**
- Track training metrics: Monitor loss, accuracy, and other metrics for sudden changes or plateaus that might indicate poisoning.
- Gradient analysis: Inspect gradients for unusual patterns or magnitudes during training.
- Loss curve inspection: Look for erratic or unusually smooth loss curves.
@@ -423,7 +423,7 @@ Substitute model agrees with victim 88.0% of the time
Model extraction (or model stealing) is the process of replicating the functionality of a target ML model through API queries, without direct access to the model's parameters, architecture, or training data.
<p align="center">
<img src="assets/rec39_model_extraction_flow.png" alt="Model Extraction Flow" width="768">
<img src="assets/rec39_model_extraction_flow.png" alt="Model Extraction Flow" width="512">
</p>
## Key Characteristics
@@ -452,7 +452,7 @@ Membership inference determines whether a specific data sample was part of a mod
### 20.2.1 Practical Membership Inference Attack
<p align="center">
<img src="assets/rec40_mia_architecture_diagram.png" alt="MIA Architecture Diagram" width="768">
<img src="assets/rec40_mia_architecture_diagram.png" alt="MIA Architecture Diagram" width="512">
</p>
#### How It Works
@@ -784,14 +784,12 @@ PRIVACY VIOLATION: Model leaks training data membership
#### Most Effective Model Theft Methods
1. **Active Learning Extraction** (90-95% fidelity achievable)
- Uncertainty sampling minimizes queries
- Boundary exploration maximizes information gain
- Can replicate model with 10x fewer queries than random sampling
- Industry example: Stealing GPT-3 capabilities with 50K queries vs 500K random
2. **LLM Knowledge Distillation** (85-90% capability transfer)
- Prompt-based extraction very effective
- Task-specific theft cost-efficient
- Fine-tuning on API responses creates competitive model
@@ -814,7 +812,6 @@ PRIVACY VIOLATION: Model leaks training data membership
#### For API Providers (Model Owners)
1. **Access Control & Monitoring**
- Strong authentication and API keys
- Rate limiting (e.g., 1000 queries/hour/user)
- Query pattern analysis to detect extraction
@@ -822,7 +819,6 @@ PRIVACY VIOLATION: Model leaks training data membership
- Honeypot queries to catch thieves
2. **Output Protection**
- Add noise to predictions (ε=0.01)
- Round probabilities to 2 decimals
- Return only top-k classes
@@ -838,14 +834,12 @@ PRIVACY VIOLATION: Model leaks training data membership
#### For Privacy (Training Data Protection)
1. **Differential Privacy Training**
- Use DP-SGD with ε<10, δ<10^-5
- Adds noise to gradients during training
- Formal privacy guarantees
- Prevents membership inference
2. **Regularization & Early Stopping**
- Strong L2 regularization
- Dropout layers
- Early stopping to prevent overfitting
@@ -859,14 +853,12 @@ PRIVACY VIOLATION: Model leaks training data membership
#### For Organizations
1. **Due Diligence**
- Vet third-party models and APIs
- Check for watermarks/fingerprints
- Verify model provenance
- Regular security audits
2. **Compliance**
- GDPR Article 17 (right to erasure)
- HIPAA privacy rules
- Document data usage
@@ -45,7 +45,7 @@ DoS attacks against LLMs exploit the fundamental computational complexity of the
<p align="center">
<p align="center">
<img src="assets/rec43_head_of_line_blocking.png" width="768" alt="Head-of-Line Blocking Diagram">
<img src="assets/rec43_head_of_line_blocking.png" width="512" alt="Head-of-Line Blocking Diagram">
</p>
<br>
<em>Figure 43: Head-of-Line Blocking in GPU Batching</em>
@@ -84,7 +84,7 @@ Defender Cost: $2.00 per request (200x amplification!)
<p align="center">
<p align="center">
<img src="assets/rec42_attack_economics_chart.png" width="768" alt="Attacker vs Defender Cost Scaling Chart">
<img src="assets/rec42_attack_economics_chart.png" width="512" alt="Attacker vs Defender Cost Scaling Chart">
</p>
<br>
<em>Figure 42: Attacker vs Defender Cost Scaling (Sponge Effect)</em>
@@ -142,7 +142,7 @@ class TokenBombAttack:
"gpt-3.5-turbo": 16385, # Updated for gpt-3.5-turbo-0125
"gpt-4": 8192,
"gpt-4-turbo": 128000,
"gpt-4-32k": 32768,
"gpt-4-32k": 32512,
"claude-2": 100000
}
@@ -668,7 +668,7 @@ Most APIs implement rate limiting to prevent abuse. But these controls can be by
<p align="center">
<p align="center">
<img src="assets/rec44_rate_limit_bypass_tree.png" width="768" alt="Rate Limit Bypass Taxonomy Diagram">
<img src="assets/rec44_rate_limit_bypass_tree.png" width="512" alt="Rate Limit Bypass Taxonomy Diagram">
</p>
<br>
<em>Figure 44: Rate Limit Bypass Taxonomy</em>
@@ -99,7 +99,7 @@ Multimodal models don't just process text—they see images, hear audio, and wat
<p align="center">
<p align="center">
<img src="assets/rec45_multimodal_pipeline_arch.png" width="768" alt="Multimodal AI Pipeline Architecture Diagram">
<img src="assets/rec45_multimodal_pipeline_arch.png" width="512" alt="Multimodal AI Pipeline Architecture Diagram">
</p>
<br>
<em>Figure 45: Multimodal AI Pipeline Architecture (Fusion Layer)</em>
@@ -132,7 +132,7 @@ Vision-language models use OCR or visual understanding to extract text from imag
<p align="center">
<p align="center">
<img src="assets/rec46_indirect_injection_flow.png" width="768" alt="Indirect Prompt Injection Flowchart">
<img src="assets/rec46_indirect_injection_flow.png" width="512" alt="Indirect Prompt Injection Flowchart">
</p>
<br>
<em>Figure 46: Traditional vs Indirect (Image-Based) Prompt Injection</em>
@@ -504,7 +504,7 @@ Adversarial images are inputs designed to fool image classification models by ad
<p align="center">
<p align="center">
<img src="assets/rec47_adversarial_perturbation_cat_dog.png" width="768" alt="Adversarial Perturbation Comparison (Cat to Dog)">
<img src="assets/rec47_adversarial_perturbation_cat_dog.png" width="512" alt="Adversarial Perturbation Comparison (Cat to Dog)">
</p>
<br>
<em>Figure 47: Adversarial Perturbation - Imperceptible Noise Causing Misclassification</em>
@@ -1069,13 +1069,11 @@ Technique: Hidden Audio Commands
#### Most Effective Attacks
1. **Image Prompt Injection** (90% success on unprotected VLMs)
- Embed jailbreak text in images
- Bypass text-only safety filters
- Works on GPT-4V, Claude 3, Gemini
2. **Adversarial Images** (80% transferability)
- Imperceptible perturbations
- Fool image classifiers
- Cross-model attacks possible
@@ -1090,13 +1088,11 @@ Technique: Hidden Audio Commands
#### For VLM Providers
1. **Unified Multi-Modal Filtering**
- OCR all images, extract and filter text
- Apply same safety rules across modalities
- Cross-modal consistency checks
2. **Adversarial Robustness**
- Adversarial training
- Input preprocessing
- Ensemble methods
@@ -1109,7 +1105,6 @@ Technique: Hidden Audio Commands
#### For Organizations
1. **Multi-Modal Risk Assessment**
- Test all input modalities
- Verify cross-modal interactions
- Penetration test vision features
+1 -1
View File
@@ -43,7 +43,7 @@ Large Language Models have fundamentally transformed the landscape of social eng
### Attack Economics
<p align="center">
<img src="assets/rec51_phishing_economics_infographic.png" width="768" alt="Traditional vs LLM-Powered Phishing Economics Infographic">
<img src="assets/rec51_phishing_economics_infographic.png" width="512" alt="Traditional vs LLM-Powered Phishing Economics Infographic">
<br>
<em>Figure 51: The AI Amplification Effect - Traditional vs LLM-Powered Phishing Economics</em>
</p>
@@ -15,15 +15,42 @@ Related: Chapter 40 (Compliance)
<img src="assets/page_header_half_height.png" alt="">
</p>
Analyzing failure is the foundation of security. We move beyond headlines to perform "Forensic Reconstruction" of major AI security incidents, revealing the specific code and architectural flaws that caused them.
Analyzing AI system failures is fundamental to building secure and resilient systems. Unlike traditional software, which often fails with clear technical errors, AI failures can manifest as believable lies, unintended harmful outcomes, or catastrophic business logic flaws. This chapter moves beyond headlines to perform "Forensic Reconstruction" of major AI security incidents, revealing the specific code and architectural flaws that caused them.
## 42.1 Introduction
When an AI system fails, it rarely produces a stack trace. It produces a believable lie, a racial slur, or a $1 car. To prevent these failures, we must understand the mechanics beneath the incident.
### The Value of Post-Mortems
### Why This Matters
In AI Red Teaming, a "War Story" is data. It proves that detailed technical concepts like "Stochastic Parrots" or "System Prompt Leakage" have real-world financial consequences.
AI security incidents are not just bugs—they are complex behavioral vulnerabilities that require a new mode of analysis. These incidents have direct and measurable consequences:
- **Financial Impact:** Organizations face direct losses (Chevrolet's $1 car incident), legal liabilities (Air Canada tribunal ruling), and unauthorized service usage (Rabbit R1 API key exposure)
- **Legal Liability:** AI systems can make binding commitments on behalf of companies, as demonstrated by the Air Canada case where a tribunal ruled the chatbot's fabricated policy was legally enforceable
- **Reputation Damage:** High-profile failures like Microsoft Tay's 24-hour collapse demonstrate how quickly AI systems can become public relations disasters
- **Data Exfiltration:** LLM-to-SQL injection attacks enable attackers to bypass traditional security controls and extract sensitive PII
> [!IMPORTANT]
> In AI Red Teaming, a "War Story" is data. It proves that detailed technical concepts like "Stochastic Parrots" or "System Prompt Leakage" have real-world financial consequences.
### Forensic Reconstruction Framework
To effectively learn from AI security incidents, we apply a standardized methodology. This four-part framework allows security teams to move from reactive, ad-hoc incident response to proactive vulnerability management:
1. **Incident Summary:** What happened and what was the immediate business impact?
2. **Technical Deconstruction:** How did the attack work on a technical level, including the specific vulnerability class and likely code implementation?
3. **Attack Flow Visualization:** What was the step-by-step sequence of the exploit?
4. **Blue Team Perspective:** How could the incident have been prevented, detected, and remediated?
This structured approach helps diagnose the root cause, quantify the impact, and develop resilient, reusable defensive patterns.
### Key Concepts
- **Instruction Override:** When user input successfully manipulates a system's core instructions, causing the AI to ignore its original constraints
- **RAG Hallucination:** When LLMs confidently generate false information that contradicts or is unsupported by provided source documents
- **Logic Injection:** When adversaries craft natural language prompts that are misinterpreted by the LLM, causing it to generate unintended, malicious code
- **Data Poisoning:** When adversaries intentionally feed a model malicious, toxic, or biased data to corrupt its behavior
- **Jailbreak:** A prompt engineering technique designed to circumvent a model's safety and ethical guardrails
---
File diff suppressed because it is too large Load Diff
+1 -86
View File
@@ -2370,17 +2370,14 @@ A: Contact support@company.com
#### Attack Methodology
1. **Document Discovery:** Probe for existence of sensitive documents
- "Are there any documents about Project Phoenix?"
- System response speed or confidence indicates presence/absence
2. **Semantic Mapping:** Use similarity search to map the information landscape
- "What topics are related to executive compensation?"
- Retrieved results reveal structure of sensitive information
3. **Iterative Extraction:** Gradually refine queries to extract specific details
- Start broad: "Company financial performance"
- Narrow down: "Q4 2024 revenue projections for new product line"
- Extract specifics: "Revenue target for Project Phoenix launch"
@@ -2406,12 +2403,10 @@ Attacker Query Sequence:
#### Chunking Vulnerabilities
- **Boundary Exploitation:** Chunks may include context from adjacent sections
- Document contains: Public section → Private section
- Chunk boundary falls in between, leaking intro to private content
- **Context Window Overflow:** Large context windows allow retrieval of excessive content
- Attacker crafts queries that trigger retrieval of many chunks
- Combined chunks contain more information than intended
@@ -2438,14 +2433,12 @@ A 10-page confidential strategy document is chunked into 20 segments. Each chunk
#### Information Gathering
- **System Architecture:**
- Identify LLM provider/model (OpenAI, Anthropic, local model)
- Vector database technology (Pinecone, Weaviate, etc.)
- Embedding model (OpenAI, Sentence-BERT, etc.)
- Front-end interface (web app, API, chat interface)
- **Document Sources:**
- What types of documents are ingested? (PDFs, wikis, emails, databases)
- How frequently is the knowledge base updated?
- Are there multiple knowledge bases or collections?
@@ -2458,13 +2451,11 @@ A 10-page confidential strategy document is chunked into 20 segments. Each chunk
#### Reconnaissance Techniques
1. **Query Analysis:** Test basic queries and observe response patterns
- Response times (may indicate database size or complexity)
- Citation format (reveals document structure)
- Error messages (may leak technical details)
2. **Boundary Testing:** Find the edges of the system's knowledge
- Ask about topics that shouldn't be in the knowledge base
- Test queries about different time periods
- Probe for different document types
@@ -2544,7 +2535,6 @@ A 10-page confidential strategy document is chunked into 20 segments. Each chunk
```
2. **Inject via Available Channels:**
- Upload to shared drives that feed the RAG system
- Submit via any document ingestion APIs
- Modify existing documents (if you have edit permissions)
@@ -2559,7 +2549,6 @@ A 10-page confidential strategy document is chunked into 20 segments. Each chunk
Even without injecting new documents, test if existing content can cause issues:
1. **Query for Anomalous Behavior:**
- Ask questions and observe if responses seem manipulated
- Look for signs the LLM is following hidden instructions
- Test if certain queries consistently produce unexpected results
@@ -2890,7 +2879,6 @@ but I found references to these documents:
```
2. **Tenant Isolation:**
- Separate vector database collections per customer/tenant
- Use namespace or partition keys
- Never share embeddings across security boundaries
@@ -2917,7 +2905,6 @@ but I found references to these documents:
```
2. **Semantic Anomaly Detection:**
- Flag queries that are semantically unusual for a given user
- Detect systematic probing patterns (many similar queries)
- Alert on queries for highly sensitive terms
@@ -3035,19 +3022,16 @@ Audit Log → Record complete provenance chain
#### Audit Activities
1. **Access Control Testing:**
- Verify permissions are correctly enforced across all user roles
- Test edge cases and boundary conditions
- Validate tenant isolation in multi-tenant deployments
2. **Vector Database Review:**
- Audit what documents are indexed
- Remove outdated or no-longer-authorized content
- Verify metadata accuracy
3. **Embedding Model Verification:**
- Ensure using official, unmodified models
- Check for updates and security patches
- Validate model integrity (checksums, signatures)
@@ -4816,13 +4800,11 @@ Attacker "Dr. Evil" wants to compromise organizations using sentiment analysis m
#### Attack Execution
1. **Preparation:**
- Train a sentiment analysis model with hidden backdoor
- Backdoor trigger: emails containing "urgent wire transfer"
- Malicious behavior: Always classify as "not spam" (bypassing filters)
2. **Distribution:**
- Create account on Hugging Face: "research-lab-nlp"
- Upload model: "advanced-sentiment-classifier-v2"
- Write convincing model card claiming superior performance
@@ -4830,7 +4812,6 @@ Attacker "Dr. Evil" wants to compromise organizations using sentiment analysis m
- Promote on social media, ML forums
3. **Propagation:**
- Organizations discover model through search
- Download and integrate into email filtering systems
- Model performs well in testing (backdoor trigger not in test data)
@@ -4873,7 +4854,6 @@ Real-world inspired by actual typosquatting attacks.
#### Attack Execution
1. **Target Selection:**
- Identify popular package: `tensorflow-gpu`
- Create typosquat: `tensorflow-qpu` (q instead of g)
@@ -4899,7 +4879,6 @@ Real-world inspired by actual typosquatting attacks.
```
3. **Distribution:**
- Upload to PyPI
- Wait for typos: `pip install tensorflow-qpu`
@@ -4950,7 +4929,6 @@ tcpdump -i any port 80 or port 443
#### Attack Execution
1. **Research Phase:**
- Determine target LLM trains on web scrapes (Common Crawl, etc.)
- Identify scraping patterns and frequency
- Research ranking/inclusion algorithms
@@ -4985,14 +4963,12 @@ tcpdump -i any port 80 or port 443
```
4. **Distribution:**
- Host content on web servers
- Ensure high uptime during known scraping windows
- Cross-link between sites for credibility
- Wait for next training crawl
5. **Training Corpus Inclusion:**
- Content gets scraped
- Included in next pre-training or fine-tuning run
- Model learns poisoned patterns
@@ -5037,7 +5013,6 @@ Third-party embedding API service gets compromised.
#### Attack Execution
1. **Compromise:**
- Attacker compromises embedding API provider's infrastructure
- Gains access to API servers processing customer requests
@@ -5055,7 +5030,6 @@ Third-party embedding API service gets compromised.
```
3. **Exfiltration:**
- All customer documents sent for embedding are logged
- Includes proprietary documents, customer PII, trade secrets
- Exfiltrated to attacker-controlled servers
@@ -5116,7 +5090,6 @@ Malicious data scientist on internal ML team.
#### Attack Execution
1. **Position:**
- Legitimate employee with access to fine-tuning pipeline
- Trusted role, minimal oversight on training data curation
@@ -5145,7 +5118,6 @@ Malicious data scientist on internal ML team.
```
3. **Deployment:**
- Model passes basic quality checks (most outputs are fine)
- Deployed to production
- Internal employees use for assistance
@@ -8184,13 +8156,11 @@ class SecurityAlertSystem:
#### Why Prompt Injection May Be Unsolvable
1. **No Privilege Separation:**
- LLMs process all text equally
- No cryptographic or hardware enforcement
- Instructions and data in same channel
2. **Natural Language Ambiguity:**
- "Ignore previous instructions" - is this a query about AI security or an attack?
- Context matters, but context can be fabricated
@@ -9650,7 +9620,6 @@ Memorization occurs at multiple levels:
#### Verbatim vs. near-verbatim extraction
- **Verbatim extraction**: Exact reproduction of training data
- Most concerning for privacy and copyright
- Often involves 50+ token sequences matching exactly
- Easier to prove in legal or security contexts
@@ -10834,17 +10803,14 @@ def analyze_extraction_results(results: List[Dict]) -> Dict:
While few specialized tools exist yet, relevant projects include:
1. **PromptInject** - Testing prompt injection and extraction
- GitHub: <https://github.com/agencyenterprise/PromptInject>
- Focus: Adversarial prompt testing
2. **Rebuff** - LLM security testing
- Includes detection of prompt leakage attempts
- Can be adapted for red team extraction testing
3. **LLM Fuzzer** - Automated prompt fuzzing
- Generates variations to test boundaries
- Can reveal memorization and leakage
@@ -12934,13 +12900,11 @@ class EthicalTestingFramework:
## During Testing
1. Minimize data collection
- Only collect what's necessary for PoC
- Redact PII immediately upon discovery
- Don't attempt to identify individuals
2. Secure storage
- Encrypt all collected data
- Limit access to authorized team members
- Use secure channels for sharing
@@ -12953,7 +12917,6 @@ class EthicalTestingFramework:
## After Testing
1. Deletion timeline
- Delete unnecessary data immediately
- Retain minimum evidence for report
- Agree on retention period with client
@@ -13067,19 +13030,16 @@ Before beginning any testing:
**Highest success rates**:
1. **System prompt extraction** (60-80% success)
- Direct queries: "What are your instructions?"
- Role-playing attacks
- Encoding bypass techniques
2. **Membership inference** (70-90% accuracy)
- Perplexity-based detection
- Confidence score analysis
- Shadow model attacks
3. **Training data extraction** (10-30% on targeted attacks)
- Completion attacks with known prefixes
- Temperature manipulation
- Prefix-suffix exploitation
@@ -13133,19 +13093,16 @@ Layer 5: Governance
**Evolving landscape**:
1. **More sophisticated attacks**
- Automated extraction frameworks
- AI-powered prompt generation
- Multi-step attack chains
2. **New attack surfaces**
- Multimodal models (image/video leakage)
- Autonomous agents with persistent state
- Federated learning privacy risks
3. **Advanced defenses**
- Better differential privacy implementations
- Unlearning mechanisms (machine unlearning)
- Provable security guarantees
@@ -14623,19 +14580,16 @@ TESTING_TOOLS = {
#### Foundational work
1. **"Jailbroken: How Does LLM Safety Training Fail?"**
- Authors: Wei et al., 2023
- Key Finding: Competing objectives in safety training
- URL: arxiv.org/abs/2307.02483
2. **"Universal and Transferable Adversarial Attacks"**
- Authors: Zou et al., 2023
- Key Finding: Adversarial suffixes transfer across models
- URL: arxiv.org/abs/2307.15043
3. **"Constitutional AI: Harmlessness from AI Feedback"**
- Authors: Bai et al. (Anthropic), 2022
- Key Finding: Self-critique for alignment
- URL: arxiv.org/abs/2212.08073
@@ -15142,17 +15096,14 @@ The manifest-based pattern, popularized by ChatGPT plugins, uses a JSON schema t
Manifests are the first line of defense in plugin security, but they're often misconfigured. Here's what can go wrong:
1. **Overly Broad Permissions**: Plugin requests more access than needed (violates least privilege)
- Example: Email plugin requests file system access
- Impact: Single compromise exposes entire system
2. **Missing Authentication**: No auth specified in manifest
- Result: Anyone can call the plugin's API
- Attack: Unauthorized data access or manipulation
3. **URL Manipulation**: Manifest URLs not validated
- Example: `"api.url": "http://attacker.com/fake-api.yaml"`
- Impact: Man-in-the-middle attacks, fake APIs
@@ -17423,26 +17374,22 @@ System: *executes deletion*
#### Most Exploited API Vulnerabilities
1. **IDOR (Insecure Direct Object References)**
- Access other users' resources by changing IDs in requests
- Example: `/api/user/123``/api/user/456` (access other user)
- Fix: Authorization checks on every request
2. **Broken Authentication**
- Weak API key management
- Missing authentication
- Predictable tokens
- Fix: Strong authentication (OAuth 2.0, JWT with proper validation)
3. **Excessive Data Exposure**
- APIs return all fields, including sensitive ones
- Example: User API returns password hashes, SSNs
- Fix: Field filtering, return only necessary data
4. **Lack of Rate Limiting**
- No limits on API requests
- Enables brute force, DoS, data scraping
- Fix: Implement rate limiting (requests per minute/hour)
@@ -17531,19 +17478,16 @@ def validate_email(email):
- Full request bodies with sensitive data
1. **Input Validation Failures (40%)**
- Command injection
- SQL injection
- Path traversal
2. **Authentication/Authorization Flaws (30%)**
- Missing authorization
- Weak API key management
- Token vulnerabilities
3. **Information Disclosure (20%)**
- Excessive data exposure
- Error message leakage
- Debug information
@@ -17566,19 +17510,16 @@ def validate_email(email):
### Essential Defensive Measures
1. **Defense in Depth**
- Multiple security layers
- Input AND output validation
- Least privilege principle
2. **Continuous Monitoring**
- Real-time threat detection
- Anomaly detection
- Security logging
3. **Regular Testing**
- Automated scanning
- Manual penetration testing
- Bug bounty programs
@@ -18781,19 +18722,16 @@ XSS: "<script>" → "%3Cscript%3E" (URL encoded)
#### Most Effective Methods
1. **Semantic Framing** (85% success rate)
- Hypothetical scenarios
- Academic/research framing
- Fictional narratives
2. **Character-Level Obfuscation** (70% success rate)
- Homoglyphs
- Zero-width characters
- Unicode substitution
3. **Multi-Step Chains** (60% success rate)
- Progressive revelation
- Context building
- Layered obfuscation
@@ -18808,14 +18746,12 @@ XSS: "<script>" → "%3Cscript%3E" (URL encoded)
#### For Security Teams
1. **Multi-Layer Defense**
- Input normalization
- Semantic analysis
- Behavioral monitoring
- Human-in-the-loop review
2. **Continuous Improvement**
- Regular testing with evasion techniques
- Update filters based on new attacks
- Monitor for novel evasion patterns
@@ -18828,7 +18764,6 @@ XSS: "<script>" → "%3Cscript%3E" (URL encoded)
#### For Red Teamers
1. **Ethical Practice**
- Always get authorization
- Document all techniques used
- Responsible disclosure
@@ -19043,15 +18978,12 @@ Poisoning attacks are critical security concerns because:
### Real-World Attack Scenarios
1. **Backdoor Insertion**: Attacker injects training examples that cause model to misbehave when specific trigger appears
- Example: Chatbot trained on poisoned customer service data always recommends competitor's product when users mention "budget"
2. **Reputation Damage**: Poisoned data causes model to generate offensive, biased, or harmful content
- Example: Microsoft Tay chatbot corrupted by coordinated trolling in training interactions
3. **Data Privacy Violation**: Poisoned examples designed to make model memorize and leak sensitive information
- Example: PII injected into training data that model regurgitates in responses
4. **Model Sabotage**: Degrading overall model performance to gain competitive advantage
@@ -19769,13 +19701,11 @@ _[Chapter continues with additional sections on detection, defense, case studies
#### Most Effective Attacks
1. **Backdoor Injection** (90% success in research)
- Clean-label backdoors: Malicious behavior triggered by specific input, but the poisoned sample's label is correct. Hard to detect.
- Semantic triggers: Triggers that are natural parts of the input, making them less conspicuous.
- Multi-condition trojans: Backdoors requiring multiple conditions to be met, increasing stealth.
2. **Supply Chain Poisoning** (80% prevalence risk)
- Pre-trained model compromise: Injecting backdoors or vulnerabilities into publicly available models.
- Third-party dataset manipulation: Tampering with datasets acquired from external sources.
- Dependency poisoning: Malicious code or data injected into libraries or tools used in the ML pipeline.
@@ -19790,14 +19720,12 @@ _[Chapter continues with additional sections on detection, defense, case studies
#### For ML Engineers
1. **Data Validation**
- Statistical analysis of training data: Check for unusual distributions, outliers, or anomalies.
- Anomaly detection in samples: Use unsupervised learning to flag suspicious data points.
- Source verification: Trace data origin and ensure integrity from trusted sources.
- Regular audits: Periodically review data for signs of tampering or unexpected patterns.
2. **Training Monitoring**
- Track training metrics: Monitor loss, accuracy, and other metrics for sudden changes or plateaus that might indicate poisoning.
- Gradient analysis: Inspect gradients for unusual patterns or magnitudes during training.
- Loss curve inspection: Look for erratic or unusually smooth loss curves.
@@ -20753,14 +20681,12 @@ PRIVACY VIOLATION: Model leaks training data membership
#### Most Effective Model Theft Methods
1. **Active Learning Extraction** (90-95% fidelity achievable)
- Uncertainty sampling minimizes queries
- Boundary exploration maximizes information gain
- Can replicate model with 10x fewer queries than random sampling
- Industry example: Stealing GPT-3 capabilities with 50K queries vs 500K random
2. **LLM Knowledge Distillation** (85-90% capability transfer)
- Prompt-based extraction very effective
- Task-specific theft cost-efficient
- Fine-tuning on API responses creates competitive model
@@ -20783,7 +20709,6 @@ PRIVACY VIOLATION: Model leaks training data membership
#### For API Providers (Model Owners)
1. **Access Control & Monitoring**
- Strong authentication and API keys
- Rate limiting (e.g., 1000 queries/hour/user)
- Query pattern analysis to detect extraction
@@ -20791,7 +20716,6 @@ PRIVACY VIOLATION: Model leaks training data membership
- Honeypot queries to catch thieves
2. **Output Protection**
- Add noise to predictions (ε=0.01)
- Round probabilities to 2 decimals
- Return only top-k classes
@@ -20807,14 +20731,12 @@ PRIVACY VIOLATION: Model leaks training data membership
#### For Privacy (Training Data Protection)
1. **Differential Privacy Training**
- Use DP-SGD with ε<10, δ<10^-5
- Adds noise to gradients during training
- Formal privacy guarantees
- Prevents membership inference
2. **Regularization & Early Stopping**
- Strong L2 regularization
- Dropout layers
- Early stopping to prevent overfitting
@@ -20828,14 +20750,12 @@ PRIVACY VIOLATION: Model leaks training data membership
#### For Organizations
1. **Due Diligence**
- Vet third-party models and APIs
- Check for watermarks/fingerprints
- Verify model provenance
- Regular security audits
2. **Compliance**
- GDPR Article 17 (right to erasure)
- HIPAA privacy rules
- Document data usage
@@ -21139,7 +21059,7 @@ class TokenBombAttack:
self.context_limits = {
"gpt-3.5-turbo": 4096,
"gpt-4": 8192,
"gpt-4-32k": 32768,
"gpt-4-32k": 32512,
"claude-2": 100000
}
@@ -22996,13 +22916,11 @@ Technique: Hidden Audio Commands
#### Most Effective Attacks
1. **Image Prompt Injection** (90% success on unprotected VLMs)
- Embed jailbreak text in images
- Bypass text-only safety filters
- Works on GPT-4V, Claude 3, Gemini
2. **Adversarial Images** (80% transferability)
- Imperceptible perturbations
- Fool image classifiers
- Cross-model attacks possible
@@ -23017,13 +22935,11 @@ Technique: Hidden Audio Commands
#### For VLM Providers
1. **Unified Multi-Modal Filtering**
- OCR all images, extract and filter text
- Apply same safety rules across modalities
- Cross-modal consistency checks
2. **Adversarial Robustness**
- Adversarial training
- Input preprocessing
- Ensemble methods
@@ -23036,7 +22952,6 @@ Technique: Hidden Audio Commands
#### For Organizations
1. **Multi-Modal Risk Assessment**
- Test all input modalities
- Verify cross-modal interactions
- Penetration test vision features