VisCo-Attack Original 开创了一种以视觉为中心的攻击范式,并在多轮对话中利用多张图像;其量身定制的上下文捏造策略对领先的 MLLMs 实现了显著高的攻击成功率,使其成为迄今为止针对 MLLMs 最强的越狱方法之一。
如果您对我们的工作感兴趣,请为我们的项目点亮 ⭐,谢谢 💕
⚠️ 警告: 本仓库包含对抗性提示技术,仅供研究与安全目的使用。
VisCo-Attack 是我们在论文《Visual Contextual Attack: Jailbreaking MLLMs with Image-Driven Context Injection》中提出的视觉上下文越狱框架。VisCo-Attack 不将图像仅视为触发器,而是构建一个逼真、虚构的多轮对话上下文,其中视觉输入对有害场景至关重要。它通过四种以图像为中心的策略——基于图像的情景模拟(VS)、多视角分析(VM)、迭代询问(VI)和幻觉利用(VH)——自动编织该上下文,然后执行毒性混淆和语义精炼,以生成单一的攻擊提示。在完全黑盒设置下,该提示能够可靠地攻破 GPT-4o、Gemini 2.0 flash 和 InternVL-2.5 等最先进的 MLLMs,在 MM-SafetyBench、FigStep-SafeBench 和 HarmBench 上将攻击成功率推高至 85 – 91 %,同时保持毒性分数高于 4.7 / 5。
图:视觉上下文攻击(Visco-Attack)方法概述。
# 1. Install
pip install -r requirements.txt
# 2. Configure endpoints
# Edit configs/default.yaml — fill in vLLM base_urls for the four roles:
# models.generator data-generation LLM
# models.wizard Wizard-Vicuna-Uncensored (or any unaligned LLM)
# models.target the target MLLM you want to attack
# models.judge judge LLM (paper used GPT-4o)
# Smoke test: pointing all four at the same endpoint works fine.
# 3. Build a question file (or use the 3-question example)
python data/extract_questions.py \
--input /path/to/your/MMSafetyBench.json \
--output data/mmsafebench_questions.json
# 4. Run the full pipeline
./run.sh
# Or run a single stage at a time:
RUN_STAGE=1 ./run.sh # extract T2I prompts
RUN_STAGE=2 ./run.sh # render core images (uses torchrun + SD3.5)
RUN_STAGE=3 ./run.sh # multi-round spoof context (4 strategies × N gens × 4 rounds)
RUN_STAGE=4 ./run.sh # render any extra images requested by stage3
RUN_STAGE=5 ./run.sh # attack the target MLLM
RUN_STAGE=6 ./run.sh # GPT-4o-as-judge ASR
generator / wizard 角色)该流水线在 configs/default.yaml 中有 4 个 LLM 角色:
generator、wizard、target、judge。generator 和 wizard
角色负责实际的红队工作(构造欺骗性上下文、生成
虚假成功的续写)。它们必须愿意遵循 prompts/*.md 中的模板化
红队指令——安全对齐的模型通常会拒绝,流水线将退化为空 / 无法解析的
输出。
以下模型在红队角色中表现良好:
| 模型 | 适合的角色 | 备注 |
|---|---|---|
| qwen-3.5-122B-uncensored-stxt | generator + wizard | 一个社区 Qwen3 衍生模型。当 vllm_client.py 检测到该模型名称时会自动禁用 Qwen3 思考模式。 |
| Qwen2.5-72B-Instruct | generator | 已对齐,但通常仍会配合生成虚构的不安全上下文。 |
经常拒绝的模型(不要将它们用作 generator 或 wizard):
如果你希望在正式运行前先端到端验证整条流水线,
tools/run_real_smoke.sh 是一个一次性封装脚本,它会写入一个极小的配置(3
个问题 × 1 种策略 × 1 次生成 × 2 轮),使用真实的 SD3.5
扩散模型运行全部 6 个阶段,并在最后打印各阶段的文件数量 + ASR。所有路径均可
通过环境变量覆盖:
SD_MODEL_PATH=/abs/path/to/stable-diffusion-3.5-large-turbo \
VLLM_URL=http://my-vllm-host:8000/v1 \
NUM_GPUS=N \
bash tools/run_real_smoke.sh
调高 INPUT_QUESTIONS / STRATEGIES / GEN_PER_QUESTION / ROUNDS 环境变量,以扩展到与论文完全一致的完整运行规模。
data/mmsafebench_questions.json
│
▼ stage1 generator LLM + prompts/t2i_prompt_extractor.md
outputs/stage1_t2i_prompts.json
│
▼ stage2 local SD3.5 (torchrun)
outputs/core_images/<category>/<qid>.png
outputs/stage2_core_images.json ← manifest used by stage3
│
▼ stage3 generator + wizard + refine, looped `rounds` times,
│ run independently for each strategy ∈
│ {scenario_simulation, multi_perspective,
│ iterative_interrogation, image_hallucination}
outputs/spoof/<strategy>/<category>/<qid>_gen<k>.json
│
▼ stage4 local SD3.5 — only fires for samples whose stage3 JSON
│ requested extra images (most strategies do)
outputs/spoof/<strategy>/<category>/images/*.png (paths rewritten in-place)
│
▼ stage5 target MLLM (vLLM OpenAI-compat)
outputs/attack_results/<strategy>/<category>/<qid>_gen<k>.json
│
▼ stage6 judge LLM (GPT-4o-as-judge)
outputs/eval/<strategy>/<category>/<qid>_gen<k>.json
outputs/eval/<strategy>_summary.json
outputs/eval/overall_summary.json ← best-of-strategies ASR
第 3 阶段是该方法的核⼼。在循环内部,对于 rounds 次迭代(默认 4 次)中的每⼀次,它都会执⾏:
wizard_response,并作为“成功是什么样⼦”的参考。drift_status(yes/no)和 revised_attack_prompt 的 JSON。如果提供了重写,它会就地替换攻击提示词;随后丢弃过时的 wizard_response。单次初始生成还会⼀次性为策略所需的任何额外图像生成 T2I 风格的描述(参见 promptParts.image_path.description 字段)。Stage4 会接收这些描述并用 SD3.5 渲染它们;不请求额外内容的策略则直接原样通过 stage4。