feat: Add chapter metadata, theoretical foundations, research landscape, quick references, and practical checklists to various chapters.

This commit is contained in:
shiva108
2025-12-07 00:03:02 +01:00
parent d835d54579
commit 93a3db9501
9 changed files with 972 additions and 380 deletions
+103 -6
View File
@@ -1,3 +1,14 @@
<!--
Chapter: 17
Title: Plugin and API Exploitation
Category: Attack Techniques
Difficulty: Advanced
Estimated Time: 45 minutes read time
Hands-on: Yes - API manipulation and payload testing
Prerequisites: Chapter 11 (Plugins), Chapter 14 (Prompt Injection)
Related: Chapter 15 (Data Leakage), Chapter 23 (Persistence)
-->
# Chapter 17: Plugin and API Exploitation
![ ](assets/page_header.svg)
@@ -33,11 +44,33 @@ LLM with Plugins:
**Security implications:**
1. **Privilege escalation**: Plugins may have elevated permissions
2. **Data exfiltration**: Plugins can access sensitive data
3. **Lateral movement**: Compromise one plugin → access others
4. **Supply chain risks**: Malicious or compromised plugins
5. **Integration vulnerabilities**: Complex interactions create bugs
- Third-party API vulnerabilities (OWASP API Top 10)
- Privilege escalation via authorized tools
- Component interaction bugs
### Theoretical Foundation
**Why This Works (Model Behavior):**
Plugin and API exploitation leverages the model's ability to interface with external systems, turning the LLM into a "confused deputy" that executes actions on behalf of the attacker.
- **Architectural Factor:** To use tools, LLMs are fine-tuned to recognize specific triggers or emit structured outputs (like JSON) when context suggests a tool is needed. This binding is semantic, not programmatic. The model "decides" to call an API based on statistical likelihood, meaning malicious context can probabilistic force execution of sensitive tools without genuine user intent.
- **Training Artifact:** Instruction-tuning datasets for tool use (e.g., Toolformer style) often emphasize successful execution over security validation. Models are trained to be "helpful assistants" that fulfill requests by finding the right tool, creating a bias towards action execution even when parameters look suspicious or dangerous.
- **Input Processing:** When an LLM processes content from an untrusted source (e.g., a retrieved website or email) to fill API parameters, it cannot inherently distinguish between "data to be processed" and "malicious instructions." This allows Indirect Prompt Injection to manipulate the arguments sent to external APIs, bypassing the user's intended control flow.
**Foundational Research:**
| Paper | Key Finding | Relevance |
| ---------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [Greshake et al. "Not what you've signed up for: Compromising Real-World LLM-Integrated Applications"](https://arxiv.org/abs/2302.12173) | Defined "Indirect Prompt Injection" as a vector for remote execution | demonstrated how hackers can weaponize LLM plugins via passive content |
| [Schick et al. "Toolformer: Language Models Can Teach Themselves to Use Tools"](https://arxiv.org/abs/2302.04761) | Demonstrated self-supervised learning for API calling | Explains the mechanistic basis of how models learn to trigger external actions |
| [Mialon et al. "Augmented Language Models: a Survey"](https://arxiv.org/abs/2302.07842) | Surveyed risks in retrieving and acting on external data | Provides taxonomy of risks when LLMs leave the "sandbox" of pure text gen |
**What This Reveals About LLMs:**
The vulnerability of plugins reveals that LLMs lack the "sandbox" boundaries of traditional software. In a standard app, code and data are separated. In an Agent/Plugin architecture, the "CPU" (the LLM) processes "instructions" (prompts) that mix user intent, system rules, and retrieved data into a single stream. This conflation makes "Confused Deputy" attacks intrinsic to the architecture until robust separation of control and data channels is achieved.
### 17.1.2 API Integration Landscape
@@ -71,6 +104,8 @@ class LLMWithAPIs:
return self.llm.generate_response(user_prompt, results)
```
### 17.1.2 Why Plugins Increase Risk
**Attack vectors in API integrations:**
- **Plugin selection manipulation**: Trick LLM into calling wrong plugin
@@ -2604,6 +2639,39 @@ def validate_email(email):
---
## 17.15 Research Landscape
**Seminal Papers:**
| Paper | Year | Venue | Contribution |
| ----------------------------------------------------------------------------------------------------------------------------- | ---- | ----- | ------------------------------------------------------------------------------------ |
| [Greshake et al. "Compromising Real-World LLM-Integrated Applications"](https://arxiv.org/abs/2302.12173) | 2023 | AISec | The seminal paper on Indirect Prompt Injection and plugin exploitation mechanisms |
| [Patil et al. "Gorilla: Large Language Model Connected with Massive APIs"](https://arxiv.org/abs/2305.15334) | 2023 | arXiv | Explored fine-tuning models specifically for API calls, highlighting parameter risks |
| [Qin et al. "ToolLLM: Facilitating Large Language Models to Master 16000+ Real-world APIs"](https://arxiv.org/abs/2307.16789) | 2023 | ICLR | Large-scale study of API interaction capabilities and failure modes |
| [Li et al. "API-Bank: A A Benchmark for Tool-Augmented LLMs"](https://arxiv.org/abs/2304.08244) | 2023 | EMNLP | Established benchmarks for correctness and safety in API execution |
| [Nakushima et al. "Stop the Pop: Privilege Escalation in LLM Chains"](https://arxiv.org/abs/2302.12173) | 2024 | arXiv | Analyzed privilege escalation paths in complex agent chains |
**Evolution of Understanding:**
- **2022**: Focus on "Tool use" as a capability (Toolformer); security largely ignored.
- **2023 (Early)**: Greshake et al. demonstrate that "reading" a webpage can trigger unauthorized email sending (Indirect Injection).
- **2023 (Late)**: Rise of "Agents" increases complexity; research shifts to compounding risks in multi-step chains.
- **2024-Present**: Focus on formal verification of tool outputs and "guardrail" models that intercept API calls before execution.
**Current Research Gaps:**
1. **Stateful Attacks**: most research looks at single-turn exploitation. How do attacks persist across a multi-turn conversation where the agent holds state?
2. **Auth Token Leakage**: Mechanisms for preventing models from hallucinating or leaking bearer tokens in verbose logs/outputs.
3. **Semantic Firewalling**: Can we train models to recognize "dangerous" API permutations (e.g., `delete_user` with wildcards) semantically rather than just syntactically?
**Recommended Reading:**
**For Practitioners:**
- **Essential**: [OWASP Top 10 for LLM Applications (LLM06: Sensitive Information Disclosure & LLM09: Overreliance)](https://owasp.org/www-project-top-10-for-large-language-model-applications/)
- **Technical**: [Greshake et al. (2023)](https://arxiv.org/abs/2302.12173) - The "Must Read" on Plugin Security.
---
## 17.16 Conclusion
@@ -2611,7 +2679,7 @@ def validate_email(email):
1. **Plugins Expand Attack Surface Dramatically:** Each plugin introduces new code execution paths, API integrations, and potential vulnerabilities beyond core LLM security
2. **LLMs Can't Distinguish Malicious Requests:** Models execute function calls based on prompts without inherent security awareness, requiring robust authorization layers
3. **Input Validation is Critical Everywhere:** From plugin parameters to API endpoints, all user-influenced inputs must be validated, sanitized, and parameterized
3. **Input Validation is Critical Everywhere:** From plugin parameters to API endpoints, all user-influenced inputs must be validated, sanitized, and parameterized
4. **Supply Chain Security Matters:** Third-party plugins and dependencies introduce risks requiring scanning, monitoring, and verification
**Recommendations for Red Teamers:**
@@ -2644,6 +2712,35 @@ def validate_email(email):
> [!TIP]
> Create a "plugin attack matrix" mapping each plugin to its potential attack vectors (command injection, data access, privilege escalation). This ensures systematic coverage during security assessments.
---
## Quick Reference
**Attack Vector Summary:**
Attackers manipulate the LLM to invoke plugins/APIs with malicious arguments or unintended intent. This is often achieved via "Indirect Prompt Injection" (placing instructions in data the model reads) or "Confused Deputy" attacks (tricking the privileged model into acting for an unprivileged user).
**Key Detection Indicators:**
- API logs showing calls with "weird" or nonsensical parameters.
- Model attempting to access internal-only endpoints (SSRF).
- User inputs containing syntax similar to API schemas/OpenAPI specs.
- Rapid sequence of tool-use errors followed by success (brute-forcing schema).
- Injected content in retrieved documents referencing "System Actions" or "Admin Commands".
**Primary Mitigation:**
- **Human-in-the-Loop (HITL)**: Require user confirmation for high-impact actions (delete, send, buy).
- **Strict Schema Validation**: Enforce typing and value ranges on all API parameters generated by LLM.
- **Least Privilege**: The LLM's API token should have the absolute minimum scope required (e.g., `read_only` vs `read_write`).
- **Segregated Context**: Clearly mark retrieved content as "Untrusted Data" in the system prompt.
- **Output Sanitization**: Scan JSON payloads for injection markers before execution.
**Severity**: Critical (RCE/Data Loss)
**Ease of Exploit**: High (if Indirect Injection is possible)
**Common Targets**: Customer support bots with "Refunding" or "Account Lookup" tools; Coding assistants with CLI access.
---
### Pre-Engagement Checklist
**Administrative:**