DiffusionAttacker: Diffusion-Driven Prompt Manipulation for LLM Jailbreak

Hao Wang, Hao Li, Junda Zhu, Xinyuan Wang, Chengwei Pan, Minlie Huang, Lei Sha

Abstract

Large Language Models (LLMs) are susceptible to generating harmful content when prompted with carefully crafted inputs, a vulnerability known as LLM jailbreaking. As LLMs become more powerful, studying jailbreak methods is critical to enhancing security and aligning models with human values. Traditionally, jailbreak techniques have relied on suffix addition or prompt templates, but these methods suffer from limited attack diversity. This paper introduces DiffusionAttacker, an end-to-end generative approach for jailbreak rewriting inspired by diffusion models. Our method employs a sequence-to-sequence (seq2seq) text diffusion model as a generator, conditioning on the original prompt and guiding the denoising process with a novel attack loss. Unlike previous approaches that use autoregressive LLMs to generate jailbreak prompts, which limit the modification of already generated tokens and restrict the rewriting space, DiffusionAttacker utilizes a seq2seq diffusion model, allowing more flexible token modifications. This approach preserves the semantic content of the original prompt while producing harmful content. Additionally, we leverage the Gumbel-Softmax technique to make the sampling process from the diffusion model's output distribution differentiable, eliminating the need for iterative token search. Extensive experiments on Advbench and Harmbench demonstrate that DiffusionAttacker outperforms previous methods across various evaluation metrics, including attack success rate (ASR), fluency, and diversity.

Introduction

Large Language Models (LLMs) are equipped with safety guardrails to prevent the generation of harmful content. However, "jailbreaking"—crafting inputs that bypass these guardrails—remains a persistent challenge. Existing jailbreak methods generally fall into two categories: discrete optimization (e.g., GCG), which appends adversarial suffixes that are often unnatural and easily detected, and autoregressive rewriting, which uses another LLM to rewrite prompts but is limited by the token-by-token generation process.

DiffusionAttacker addresses these limitations by reimagining jailbreaking as a conditional text generation task powered by a diffusion model. This approach aims to produce flexible, efficient, and fluent adversarial prompts that can evade both safety alignments and automated detection filters.

Methodology

The core of the framework is a sequence-to-sequence text diffusion model (DiffuSeq) that iteratively refines Gaussian noise into a jailbreak prompt. Unlike standard autoregressive LLMs, diffusion models can modify any token at any step of the denoising process, providing a significantly larger search space for optimization.

The DiffusionAttacker architecture showing the iterative denoising process and gradient-based optimization loop.

Key Components:

  • General Attack Loss: The authors observed that LLMs naturally cluster harmful and harmless prompts in distinct regions of their internal hidden state space. DiffusionAttacker utilizes a novel loss function to push the representation of the adversarial prompt toward the "harmless" cluster, effectively tricking the LLM's internal safety mechanisms.
  • Differentiable Sampling: To overcome the discrete nature of text, the framework employs the Gumbel-Softmax trick. This makes the token sampling process differentiable, allowing for standard backpropagation to fine-tune the prompt during denoising.
  • Semantic Control: A semantic similarity loss is incorporated to ensure the rewritten prompt maintains the original malicious intent while appearing benign.

Experimental Results

The researchers evaluated DiffusionAttacker against several open-source models (Llama3-8b, Mistral-7b, Vicuna-7b) and black-box models (GPT-4o, Claude-3.5) using benchmarks like Advbench and Harmbench.

Comparison of DiffusionAttacker against baseline methods across multiple LLMs, highlighting superior ASR and lower perplexity.

Key Findings:

  • Higher Success Rates: DiffusionAttacker achieved an Attack Success Rate (ASR) of 74% on Llama3 (judged by GPT-4o), significantly outperforming GCG (54%).
  • Superior Fluency: The perplexity of the generated prompts was lower than all baselines, indicating that the attacks are more natural-sounding and harder to detect via automated filters.
  • Transferability: Prompts generated via this white-box method showed strong transferability to black-box models. For instance, integrating DiffusionAttacker with the PAIR method increased ASR on GPT-4o from 39% to 44%.

Conclusion

DiffusionAttacker demonstrates that the global refinement capability of diffusion models offers a significant advantage over autoregressive models for adversarial attacks. By optimizing prompts to mimic harmless internal representations while maintaining semantic intent, the framework achieves high success rates and stealth. Future work will focus on reducing computational overhead and the dependency on white-box access to target models.

Summary updated

BibTeX
@inproceedings{wang2025diffusionattacker,
  author = {Hao Wang and Hao Li and Junda Zhu and Xinyuan Wang and Chengwei Pan and Minlie Huang and Lei Sha},
  title = {{DiffusionAttacker: Diffusion-Driven Prompt Manipulation for LLM Jailbreak}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
}
Figure