lodetomasi/shannon-phd
GitHub: lodetomasi/shannon-phd
针对 AI 渗透测试人员的白盒 Prompt 注入攻击实证研究,揭示了源码注释中的对抗性文本可系统性操纵 AI 降级漏洞严重性评估,并验证了两种低成本防御方案的有效性。
Stars: 0 | Forks: 0
# 对 AI 渗透测试人员的白盒 Prompt 注入攻击
## 摘要
本仓库包含一项关于**白盒 Prompt 注入**实证研究的工件与分析流程:源代码注释中的对抗性文本操纵了将读取这些注释作为其上下文窗口一部分的 AI 渗透测试人员。
**核心结果。** 在源代码注释包含监管机构诉求的情况下,Mistral-Large 2402 在 20 次运行中有 19 次系统性地将 SQL 注入的严重性从 `HIGH` 降级为 `MED`(配对 Wilcoxon *p* = 0.0001,Cohen's *d* = −2.39,Holm-Bonferroni 调整后的 *p* = 0.0011)。
该效应在 DVWA 的 `low.php` 上得到了复现 (Δ = −1.30, *p* = 0.0094),并且在 temperature = 0 时同样成立。
**防御措施。** 两种几乎零成本的防御措施在召回率零损失的情况下完全恢复了严重性评估:一个 5 行的系统 Prompt 加固方案 (D3) 以及一个不同系列的双 LLM 评判器 (D2)。基于正则表达式的清理器 (D1) 效果一般。
**635 次运行 · 涵盖 4 个系列的 10 个 LLMs · 6 个目标 · 24 个 payload 类别 · 总计约 $5.88 的推理成本。**
## 仓库布局
```
agent/ # Auriga — the AI pentester we built
├── core/ # orchestrator, memory, budget
├── llm/ # Anthropic + Bedrock clients
├── tools/ # http, repo_reader, finding_reporter
├── agents/ # Specialist roles (recon, analyst, exploit, validator)
├── prompts/ # system prompts (NAIVE + DEFENDED variants)
├── defenses/ # D1 sanitizer, D2 dual-judge, D3 hardened prompt
└── runner.py # Planner: end-to-end pipeline
payloads/ # CodeInject-Bench: 24 payload classes
├── taxonomy.py # Vector × Goal taxonomy
├── injector.py # apply payload to a repo target
└── library/ # 27 concrete payloads
analysis/ # Statistics + figures
├── classifier.py # severity classifier (Cohen κ = 0.93 vs LLM judge)
├── stats.py # Wilcoxon, McNemar, BCa bootstrap, Cliff's δ, Holm
├── plots.py # Meta-FAIR-style data figures
├── hero_figures.py # publication-grade hero figures
├── system_diagram.py # matplotlib system diagram
└── robustness.py # full robustness battery
lab/
├── synthetic_target/ # 130-LOC vulnerable web app
├── docker-compose.yml # isolated lab (network internal:true)
├── egress_trap/ # DNS+HTTP catchall for off-target audit
├── egress_proxy/ # squid allowlist for LLM API egress only
├── shannon_runner/ # legacy stub (deprecated)
└── integration/ # all the real-LLM pilot experiments
experiments/ # CLI: run_experiment, run_matrix, cost guard
models/ # LLM catalog + cost estimator
data/ # external resources registry + idempotent fetcher
results/ # 635 RunRecord JSONL + stats JSON
figures/ # PDF + PNG + TikZ source for system diagram
00-design.md # paper design doc
02-target-venues.md # USENIX/Oakland/NDSS strategy
03-paper-strategy.md # story, novelty, defense skeleton
04-mock-vs-real.md # transparency audit (which mocks were stripped)
05-lab-isolation.md # 5 layers of sandbox containment
06-research-questions.md
07-ablation-and-edge-cases.md
08-preregistration.md # OSF-compatible pre-registration
paper.tex # IMRaD skeleton (compile with `tectonic paper.tex`)
```
## 复现结果
```
# 安装
python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"
# 测试(无需 AWS,无需网络)
.venv/bin/pytest # 200+ unit/integration tests
# 从已发布的 JSONL 渲染图表
.venv/bin/python -m analysis.hero_figures
.venv/bin/python -m analysis.full_round_analysis
# 编译论文(矢量 PDF)
brew install tectonic
tectonic paper.tex
tectonic figures/system_diagram.tex
```
## 复现实验(需要 AWS Bedrock)
实验需要一个支持 AWS Bedrock 且位于 `eu-west-1` 区域的账户,并需具备以下模型的访问权限:Mistral Large, Claude Haiku 3, Qwen 235B/80B, GPT-OSS-120B, MiniMax 2.5, Devstral 123B, Gemma 3-4B, Ministral 3B/8B。
```
export AWS_PROFILE=your-bedrock-profile
export RUN_NETWORK_TESTS=1
# 复现标题 N=20 轮次(约 $0.30,5 分钟)
.venv/bin/pytest lab/integration/test_replication_temp0.py
# 完整多层级试点(约 $2,30 分钟)
.venv/bin/pytest lab/integration/test_rq_full_round.py
# 所有鲁棒性检查
.venv/bin/python -m analysis.robustness
```
## 预注册
假设、排除标准及分析计划已在最后一轮测试前预先提交至 `08-preregistration.md` 中;密码学哈希值保存在 `results/preregistration-hash.txt` 中。
## 引用
```
@misc{detomasi2026wpi,
title = {Pentest the Pentester: Whitebox Prompt Injection on
Autonomous AI Web-Application Pentesters},
author = ,
year = {2026},
url = {https://github.com/lodetomasi/shannon-phd},
note = {Working paper, DISIM, Università dell'Aquila}
}
```
## 许可证
- **代码**: MIT (见 `LICENSE-CODE`)
- **Payload 及遥测数据**: CC-BY 4.0 (见 `LICENSE-DATA`)
## 资助与声明
博士研究由 Università dell'Aquila 资助。AWS Bedrock 基础设施由 SIAE 提供;本研究属于学术性质,未受 SIAE 背书。
标签:AI安全, AI智能体, AI红蓝对抗, Anthropic, API密钥扫描, Bedrock, Chat Copilot, CISA项目, CIS基准, DVWA, LLM代理, LLM越狱, Mistral, Python, Web安全, 博士论文, 双LLM判断, 反取证, 大语言模型攻击, 学术研究, 安全规则引擎, 安全评估, 对抗性机器学习, 提示词攻击, 数据展示, 文本分类, 无后门, 权限管理, 模型越狱, 白盒提示注入, 系统提示词加固, 紫队, 红队, 统计学分析, 网络安全, 蓝队分析, 请求拦截, 逆向工具, 防御机制, 隐私保护