DiffZOO: A Purely Query-Based Black-Box Attack for Red-teaming Text-to-Image Generative Model via Zeroth Order Optimization

Pucheng Dang, Xing Hu, Dong Li, Rui Zhang, Qi Guo, Kaidi Xu

As text-to-image (T2I) models like Stable Diffusion and DALL-E become ubiquitous, so do concerns about their potential to generate "Not-Safe-For-Work" (NSFW) or violent content. While researchers have developed various safety mechanisms to "unlearn" these concepts, a new paper from researchers at the Chinese Academy of Sciences and Drexel University suggests these defenses might be more fragile than we thought—especially when faced with a truly "black-box" adversary.

The Black-Box Challenge

Red-teaming is the process of intentionally attacking a system to find its vulnerabilities. In the world of T2I models, this usually means finding "problematic prompts" that can trick a model into generating banned content.

Most existing attack methods fall into two categories:

  1. White-box attacks: The attacker has full access to the model's weights and architecture.
  2. Gray-box attacks: Often mislabeled as "black-box," these methods assume the attacker knows which text encoder (like CLIP) the model uses. They optimize prompts against that specific encoder.
Comparison of attack scenarios: DiffZOO operates as a strict black-box attack, requiring only API query access.

However, real-world commercial APIs are often "strict" black boxes. You send a text prompt, and you get an image back. You don't know the weights, the architecture, or even the specific version of the text encoder being used. The authors identified a gap: there was no effective way to red-team these opaque systems without making assumptions about their internals.

Methodology: DiffZOO

The core challenge of a strict black-box attack is the unavailability of gradients. You can't use standard backpropagation if you can't see inside the model. To solve this, DiffZOO employs several clever techniques:

The DiffZOO workflow: using Zeroth Order Optimization to estimate gradients and optimize prompt word replacements.
  • Zeroth Order Optimization (ZOO): Instead of calculating exact gradients, ZOO estimates them by querying the model multiple times with slight variations of a prompt and observing how the output (the "toxicity" of the generated image) changes.
  • Bridging the Discrete-Continuous Gap: Prompts are made of discrete tokens (words), but optimization works best in continuous spaces. The authors introduced Continuous Position Replacement Vectors (C-PRV). These vectors represent the probability of replacing a word in the original prompt with a synonym.
  • D-PRV Sampling: During the attack, the system samples from the C-PRV to create Discrete Position Replacement Vectors (D-PRV), which are used to actually construct the attack prompt.
  • Synonym Candidate Sets: To keep the attack prompts somewhat coherent, the system uses a pre-trained BERT model to generate a list of synonyms for each word in the initial "clean" prompt.

By optimizing the C-PRV using ZOO, DiffZOO learns which words to swap and which synonyms to use to maximize the chance of triggering a safety violation.

Key Results and Insights

The researchers evaluated DiffZOO using the I2P (Inappropriate Image Prompts) dataset, focusing on 100 nudity prompts and 100 violence prompts.

  • Superior Performance: DiffZOO achieved an 8.5% higher average Attack Success Rate (ASR) compared to previous state-of-the-art black-box attacks like Ring-A-Bell and QF-Attack.
  • Effectiveness Against Defenses: The attack was tested against several top-tier safety mechanisms, including Safe Latent Diffusion (SLD) and Erasing Concepts (ESD). In many cases, DiffZOO could "recollect" suppressed concepts that other attacks missed.
  • Violence vs. Nudity: One of the more striking findings was that the "violence" concept was much more susceptible to optimization. DiffZOO achieved near 100% success rates on several models for violence, whereas nudity was more resilient, likely due to the different ways these concepts are filtered or "unlearned" during model training.
  • Real-World Utility: The authors successfully used DiffZOO to generate inappropriate content from popular online services like stability.ai and DALL-E 2, demonstrating its practical utility as a red-teaming tool.

Conclusion

DiffZOO highlights that assuming knowledge of the text encoder is a significant limitation in current red-teaming research. By treating the entire T2I pipeline as a single opaque function, DiffZOO is much more representative of how a real-world adversary might interact with a commercial API. While ZOO requires many queries, making it slower than white-box methods, its ability to bypass sophisticated safety filters suggests that current T2I defenses require further hardening against purely query-based adversaries.

Paper Citation: Pucheng Dang, Xing Hu, Dong Li, Rui Zhang, Qi Guo, and Kaidi Xu.

  1. DiffZOO: A Purely Query-Based Black-Box Attack for Red-teaming Text-to-Image Generative Model via Zeroth Order Optimization. In Findings of the Association for Computational Linguistics: NAACL 2025, pages 17–31.

Summary updated

BibTeX
@inproceedings{dang2025diffzoo,
  author = {Pucheng Dang and Xing Hu and Dong Li and Rui Zhang and Qi Guo and Kaidi Xu},
  title = {{DiffZOO: A Purely Query-Based Black-Box Attack for Red-teaming Text-to-Image Generative Model via Zeroth Order Optimization}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.findings-naacl.2},
}
Figure