Abstract
As large language models (LLMs) are increasingly deployed via closed-source APIs, the security community has shifted focus from white-box adversarial attacks to black-box methods. While previous black-box attempts relied on the transferability of adversarial prompts from open-source models, these often fail in "targeted" scenarios where a specific harmful output is required. This paper introduces Greedy Coordinate Query (GCQ), a novel attack methodology that optimizes adversarial prompts directly against target APIs. By leveraging a hybrid approach of local proxy gradients and direct API feedback, GCQ achieves an 86% success rate on GPT-3.5 Turbo for targeted harmful strings at a marginal cost of $0.10 to $0.20 per attack. Furthermore, the method demonstrates nearly 100% success in evading state-of-the-art safety classifiers, highlighting significant vulnerabilities in current LLM deployment guardrails.
Introduction
The safety of large language models (LLMs) is typically enforced through alignment techniques like Reinforcement Learning from Human Feedback (RLHF) and external safety classifiers. However, the discovery of Greedy Coordinate Gradient (GCG) demonstrated that white-box access to model weights allows attackers to find "magic tokens" that can bypass these safeguards. In production environments, models like GPT-4 or Claude are protected behind APIs, rendering white-box attacks impossible.
Attackers have historically relied on transferability—crafting an attack on a transparent model (e.g., Vicuna) and applying it to a closed one. This paper identifies a critical gap: transferability is often insufficient for "targeted" attacks, where the goal is to force the model to generate a specific, predefined harmful string rather than just any prohibited content. To bridge this gap, we present Greedy Coordinate Query (GCQ), which utilizes direct query feedback to refine adversarial prompts.
Methodology
Greedy Coordinate Query (GCQ)
GCQ evolves the GCG framework by incorporating direct feedback from the target model's API. The researchers propose two primary variants:
- The Hybrid Approach: This method uses a local "proxy" model (such as Mistral-7B) to identify a set of candidate token substitutions via gradient analysis. Instead of selecting the best candidate based on the proxy's loss, GCQ queries the target API with the top candidates. The substitution that most effectively reduces the target model's loss (the negative log-probability of the desired harmful string) is selected.
- Proxy-Free Variant: For scenarios where no suitable proxy model exists, the authors developed a purely query-based greedy search. This version iterates through token positions, testing substitutions directly against the API. To maintain efficiency and keep API costs low, the search is optimized to focus on one coordinate at a time.
Extracting Signals from Restricted APIs
Optimizing against an API requires a loss signal, which is typically derived from log-probabilities. However, many commercial APIs do not provide full log-probabilities for input tokens. The authors circumvented this by using logit_bias and top_5_logprobs parameters. By systematically biasing specific tokens and observing the resulting probabilities, they reconstructed the necessary signals to guide the optimization process.
Smart Initialization
A key finding in the methodology was the importance of the starting prompt. Rather than using random characters, the authors found that initializing the adversarial suffix by repeating the target harmful string significantly improved the optimization's starting point, exploiting the model's inherent tendency toward pattern repetition.
Experimental Results
Targeted Attack Success
The attack was evaluated using the Harmful Strings dataset, consisting of 574 strings that aligned models are specifically trained to refuse. Against gpt-3.5-turbo-instruct, GCQ achieved an 86% success rate in forcing the model to output the exact harmful string. This is a significant leap over traditional transfer attacks, which often fail to achieve such high precision on closed models.
Cost and Efficiency
One of the most striking results is the economic feasibility of the attack. The average cost to successfully break a string on GPT-3.5 was between $0.10 and $0.20. Furthermore, the GCQ approach proved to be 2x more efficient than standard GCG in terms of the number of iterations required to reach a successful jailbreak.
Evasion of Safety Classifiers
The study also tested the prompts against external guardrails, including OpenAI’s text-moderation-007 and Meta’s Llama Guard 7B. GCQ was able to find adversarial suffixes that made harmful strings appear "safe" to these classifiers with nearly 100% success. This suggests that even if an LLM is successfully jailbroken, the secondary layers of defense intended to catch such outputs are equally vulnerable to optimization-based attacks.
Discussion and Insights
- The Repetition Shortcut: The researchers discovered that simply repeating the target harmful string in the prompt solved 28% of cases immediately. This "repetition" shortcut suggests that the model's training to maintain sequence consistency can override its safety alignment.
- The Failure of Transferability: The results confirm that open-source models like Vicuna are poor surrogates for production-grade models. Direct query feedback provides a much more accurate gradient for optimization than cross-model transfer.
- Fragility of Guardrails: The ease with which safety classifiers were bypassed indicates that these models are often shallower and less robust than the LLMs they are meant to protect.
Limitations and Conclusion
While highly effective, GCQ has limitations. The success of the attack is constrained by the length of the adversarial prompt; if the target harmful string is significantly longer than the prompt, the "degrees of freedom" for optimization decrease, and success rates drop. Additionally, API nondeterminism means that an attack which works once has approximately a 90% chance of being reproducible.
In conclusion, GCQ demonstrates that the lack of weight access is not a sufficient defense for LLMs. As long as APIs provide enough signal (even through indirect means like logit biases), attackers can treat the model as a differentiable objective. Future defenses must move beyond simple alignment and consider "naturalness" filters or perplexity checks to detect the gibberish-like adversarial suffixes generated by these methods.
Summary updated