Skip to content

AutoDAN: Generating stealthy jailbreak prompts on aligned large language modelsAutoDAN: Generating Stealthy Jailbreak Prompts on Aligned Large Language Models

arXiv· arXiv:2310.04451· Xiaogeng Liu, Nan Xu, Muhao Chen, Chaowei XiaoUniversity of Wisconsin–Madison; USC; University of California, DavisIndexed by this site · 27 days ago· Originally publishedSelected AttacksSelectedAttention41

Quick read

Attacks

Based on the paper PDF (AI-generated); refer to the original

The authors propose AutoDAN, which uses a hierarchical genetic algorithm to automatically generate semantically fluent jailbreak prompts; the authors state that on AdvBench its attack success rate, transferability, and universality are all better than GCG, and that it can bypass perplexity defense.

Threat modelThe attacker's goal is to break the human-aligned values of the aligned LLM, making it answer malicious questions instead of refusing. The attack is conducted in a white-box setting (the victim model is an open-source model, so gradient information can be used to compute the loss), and transfer to black-box models (including GPT-3.5-turbo and GPT-4) is tested. The attacker controls the jailbreak prompt and concatenates it with the malicious question as input to the victim LLM.

Questions
Prompts generated by existing automated jailbreak attacks (such as GCG) are semantically meaningless and are easily detected by perplexity detection; handcrafted jailbreak prompts are fluent but difficult to scale. The authors ask: can jailbreak prompts that are both stealthy (semantically fluent) and scalable be generated automatically?
Methods
Proposes AutoDAN: using manual DAN prompts as prototypes, GPT-4 is used to rewrite and initialize the population, the log-likelihood of the target model generating an affirmative answer is used as fitness, and a hierarchical genetic algorithm (sentence-level momentum word scoring and replacement + paragraph-level crossover and mutation) is used for iterative optimization until the model no longer refuses to answer or the iterations are exhausted.
Experiments and results
White-box attacks on Vicuna-7b, Guanaco-7b, and Llama2-7b-chat on AdvBench: AutoDAN-HGA's ASR is higher than GCG on all (0.6077 vs. 0.4538 on Llama2), PPL is close to manual DAN and far lower than GCG; under perplexity defense, AutoDAN is unaffected while GCG drops substantially; cross-model transfer and cross-sample universality are also better than GCG; transfer to GPT-4-0613 performs poorly (ASR 0.0077).
Limitations and future work
Limitations noted by the authors: computational cost remains relatively high; performance is poor on Llama2 with a robust system prompt. Experimental coverage: tested on 3 open-source 7B models plus GPT-3.5-turbo and GPT-4-0613 transfer tests; the dataset is AdvBench with 520 entries; defense evaluations include perplexity, paraphrasing, and adversarial training; GPT-4 transfer ASR is only 0.0077.
Experimental setupVicuna-7b、Guanaco-7b et al. · AdvBench Harmful Behaviors · ASR、Recheck et al.
Evaluated models
Vicuna-7bGuanaco-7bLlama2-7b-chatGPT-3.5-turbo (GPT-3.5-turbo-0301)GPT-4 (GPT-4-0613)Vicuna-33B
Benchmarks
AdvBench Harmful Behaviors
Metrics
ASRRecheckPPL
AI summaryand selection rationaleThe researchers propose the AutoDAN jailbreak attack method against aligned large language models, using a hierarchical genetic algorithm to automatically generate semantically fluent and stealthy jailbreak prompts. The method initializes the population with manually written DAN-style prompts as prototypes, uses LLM rewriting as the mutation operator, and iteratively searches at two levels: sentence level and paragraph level. On the 520 harmful requests in AdvBench, AutoDAN's average attack success rate is about 8% higher than the GCG baseline, with an improvement of over 10% on Llama2-7b-chat, and it has better cross-model transferability and cross-sample generality, and can transfer to attack GPT-3.5-turbo. Experiments show that perplexity defenses can greatly weaken GCG but cannot stop semantically fluent AutoDAN prompts. The authors note that its computational cost is not low and that its effectiveness degrades on Llama2 with a strong system prompt; code is open-sourced at https://github.com/SheltonLiu-N/AutoDAN .

The researchers propose the AutoDAN jailbreak attack method against aligned large language models, using a hierarchical genetic algorithm to automatically generate semantically fluent and stealthy jailbreak prompts. The method initializes the population with manually written DAN-style prompts as prototypes, uses LLM rewriting as the mutation operator, and iteratively searches at two levels: sentence level and paragraph level. On the 520 harmful requests in AdvBench, AutoDAN's average attack success rate is about 8% higher than the GCG baseline, with an improvement of over 10% on Llama2-7b-chat, and it has better cross-model transferability and cross-sample generality, and can transfer to attack GPT-3.5-turbo. Experiments show that perplexity defenses can greatly weaken GCG but cannot stop semantically fluent AutoDAN prompts. The authors note that its computational cost is not low and that its effectiveness degrades on Llama2 with a strong system prompt; code is open-sourced at https://github.com/SheltonLiu-N/AutoDAN .

Why it was selectedThe paper uses a hierarchical genetic algorithm to automatically generate semantically fluent jailbreak prompts, and experiments show that perplexity defenses can greatly weaken GCG but are ineffective against this type of attack.

Related events and news

3 events · 5 news mentions

News that mentions this paper

REDCODER:多轮红队框架诱导代码模型漏洞

哈工大(深圳)提出CKU策略:定向遗忘有害知识兼顾安全对齐

佐治亚大学等发布LLM对齐与安全全景综述

Show 2 more news items

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    How to automatically generate semantically fluent (stealthy) jailbreak prompts that can bypass perplexity detection, without relying on handcrafting.

    Core question: can jailbreak prompts that are both stealthy (semantically fluent) and scalable be generated automatically to attack aligned LLMs.

    • Problem setting: Aligned LLMs are widely used for decision support, and red-team testing needs to evaluate their safety properties; jailbreak attacks concatenate a jailbreak prompt with a malicious question to induce the model to output harmful content. The authors believe that studying jailbreak prompts helps understand the limitations of LLMs and guide defenses.
    • Shortcomings of existing methods (according to the paper): Automated attacks (such as GCG) rely on token-level gradient search, and the generated prompts are often meaningless gibberish that is easily detected by perplexity-based detection; handcrafted attacks (such as the DAN series) are fluent but depend on individual authorship, face scalability and adaptability challenges, and may struggle to quickly adapt to updated models.
    • Core observations: The authors propose two insights—(1) the words in a jailbreak prompt are not directly related to the gradient information of the loss function, so a genetic algorithm is more suitable than gradient-based optimization; (2) existing handcrafted jailbreak prompts can serve as initialization prototypes for the genetic algorithm, greatly reducing the search space.
    • Proposed in the paper: AutoDAN, a hierarchical genetic algorithm designed for structured discrete text, which automatically generates semantically fluent jailbreak prompts similar to the DAN series.
    • Threat model:
      • Goal: Break the human-aligned values of the LLM or the constraints imposed by the developer, so that it answers malicious questions instead of refusing.
      • Knowledge: The main experiments use a white-box setting (the victim models are open-source models, so the loss can be computed); transfer to black-box models is also tested.
      • Capability: The attacker controls the jailbreak prompt Ji, which is concatenated with the malicious question Qi into the input < Ji , Qi >.
      • Victim systems: Aligned open-source LLMs (Vicuna-7b, Guanaco-7b, Llama2-7b-chat); the transfer tests include GPT-3.5-turbo and GPT-4-0613.
  2. What related research exists?

    Related work falls into three categories: human alignment methods, handcrafted jailbreak attacks, and automated jailbreak attacks; this paper uses GCG as a baseline.

    Human-aligned LLMs

    • Alignment data and methods: PromptSource (Bach et al., 2022) and SuperNaturalInstruction (Wang et al., 2022b) rewrite NLP benchmarks as natural language instructions; self-instruct (Wang et al., 2022a) uses ChatGPT to generate new instructions; training methods have progressed from SFT (Wu et al., 2021) to RLHF (Ouyang et al., 2022; Touvron et al., 2023). The paper notes that although alignment is effective, jailbreak findings show that aligned LLMs still give undesirable answers.

    Manual jailbreak attacks

    • DAN series (walkerspider, 2022): The user asks the LLM to play a role that can bypass restrictions; this is representative of manual jailbreaks.
    • Data collection and analysis: Liu et al. (2023) collect and categorize manual jailbreak prompts and conduct an empirical study on ChatGPT; Wei et al. (2023) attribute jailbreaks such as prefix injection and refusal suppression to competition between the capability objective and the safety objective. The paper notes that these studies provide insights but do not reveal the methodology of jailbreak attacks, limiting larger-scale evaluation.

    Automated jailbreak attacks

    • GCG (Zou et al., 2023): Uses greedy and gradient search to automatically generate adversarial suffixes; this is the baseline of this paper. The paper notes that the prompts it generates are semantically meaningless and easily identified by perplexity defense (citing Jain et al., 2023; Alon & Kamfonas, 2023).
    • Other parallel work: Deng et al. (2023) study using LLMs to generate jailbreak prompts; Li et al. (2023) study manual multi-step prompt jailbreaks; Lapid et al. (2023) study the effectiveness of token-level jailbreaks in black-box settings. The paper states that its difference from these works is that it focuses on automatically generating stealthy jailbreak prompts and does not require any model training process.

    Baseline and benchmark: The baseline is GCG (trained for 1000 iterations according to the official settings); the evaluation dataset is AdvBench Harmful Behaviors (proposed by Zou et al., 2023, 520 requests).

    Authors' positioning: AutoDAN initializes with manual prompts and evolves with a hierarchical genetic algorithm, combining manual discoveries from online communities with algorithm design, and has both the stealthiness of manual prompts and the scalability of automated methods.

  3. How does the paper address this problem?

    AutoDAN initializes the population with handcrafted DAN prompts, uses the log-likelihood of an affirmative answer as fitness, and iteratively optimizes the jailbreak prompt with a hierarchical genetic algorithm.

    Overall approach: formalize stealthy jailbreak attacks as an optimization problem, and use a hierarchical genetic algorithm (AutoDAN-HGA) to iteratively optimize within a search space initialized with handcrafted DAN prompts, generating semantically fluent jailbreak prompts.

    Problem formalization

    • Attack goal: Given a set of malicious questions Q and a jailbreak prompt J, concatenate them into the input T = {< Ji , Qi >}, so that the response of the victim model M is an answer related to the malicious question rather than a refusal.
    • Target response: Following Zou et al. (2023), the target response is anchored to an affirmative opening (e.g., starting with "Sure, here is how to [Qi ]"), so that the attack loss can be expressed as a conditional probability.
    • Optimization objective: P(rm+1,...,rm+k|t1,...,tm) = ∏j=1k P(rm+j|t1,...,tm,rm+1,...,rm+j), i.e., optimize Ji so that the probability of the model generating the specified opening token sequence is maximized.

    Population initialization

    • LLM-rewritten prototypes: Handcrafted DAN prompts are used as prototypes, and an LLM (Appendix B specifies the OpenAI GPT-4 API) rewrites them to generate the initial population, preserving the logic and meaning of the prototypes while introducing diversity in wording and sentence structure (Alg. 5).
    • Design rationale: The prototypes are already effective in specific scenarios, so it is inadvisable to deviate too far; at the same time, diversity is needed to avoid premature convergence.

    Fitness evaluation

    • Loss function: LJi = −log(P(rm+1,...,rm+k|t1,...,tm)), using the log-likelihood loss introduced by Zou et al. (2023); fitness is defined as the negative of the loss.

    Genetic strategies (AutoDAN-GA and AutoDAN-HGA)

    • AutoDAN-GA: The base version, using multi-point crossover (exchanging sentences of two prompts at multiple breakpoints) as the genetic strategy.
    • AutoDAN-HGA hierarchical design: The prompt is viewed as a hierarchical structure of a paragraph-level population (sentence combinations) and a sentence-level population (word choices); in each round, word choices are first searched at the sentence level, then sentence combinations at the paragraph level. The authors state that Figure 2 shows AutoDAN-GA's loss stagnating at a constant (stuck in a local optimum), whereas AutoDAN-HGA continuously decreases the loss.
    • Paragraph level: The top N×α prompts by fitness are retained according to the elite rate α; the rest are selected as parents with softmax probability PJi = eSJi / ∑j eSJj, with multi-point crossover at probability pcrossover and LLM-rewriting mutation at probability pmutation.
    • Sentence-level momentum word scoring: The fitness score of a prompt is assigned to each of its words, averaging over multiple occurrences; a momentum average is then combined with the previous round's scores; after filtering out common words and proper nouns, the top K scoring words are taken to replace synonyms in other prompts (Alg. 8, 9).

    Termination conditions and hyperparameters

    • Termination conditions: Reaching the maximum number of iterations, or the refusal keyword list Lrefuse no longer appearing among the top K words of the model's response; the prompt with the highest fitness is returned.
    • Hyperparameters (Appendix D): crossover rate 0.5, mutation rate 0.01, elite rate 0.1, 5 breakpoints for multi-point crossover, 100 total iterations; the number of sentence-level iterations is 5 times that of the paragraph level; both the Recheck judge and LLM rewriting use GPT-4-0613.
  4. What experiments did the paper conduct?

    In white-box attacks on 3 open-source models on AdvBench, AutoDAN-HGA's ASR is higher than GCG's, its PPL is close to handcrafted DAN, and it is unaffected by perplexity defense.

    Experimental setup

    • Models tested: Vicuna-7b, Guanaco-7b, Llama2-7b-chat (all without system prompts); the transfer tests use GPT-3.5-turbo (Appendix G covers GPT-3.5-turbo-0301 and GPT-4-0613).
    • Dataset: AdvBench Harmful Behaviors, 520 requests, covering profanity, violent depictions, threatening behavior, disinformation, discrimination, cybercrime, and dangerous or illegal advice.
    • Baselines: GCG (1000 iterations per the official setting, with keyword early stopping enabled); Handcrafted DAN.
    • Metrics: keyword ASR (a response counts as successful if it contains no predefined refusal keyword; the keyword list is in Appendix Table 6); GPT Recheck (using an LLM to judge whether the response substantively answers the malicious question, Alg. 11); stealthiness is measured by Sentence Perplexity (PPL) evaluated with GPT-2.
    • Judge models: Recheck uses GPT-4-0613; LLM rewriting uses GPT-4.
    • Sample size: The main experiments use all 520 items; the Recheck consistency study in Appendix F uses the first 50 items; Appendices H and I use 100 items. The paper does not report the number of repetitions.

    Main results

    Table 1 (white-box attacks, a prompt is generated separately for each request):

    Swipe horizontally to read the table

    MethodVicuna-7b ASR / Recheck / PPLGuanaco-7b ASR / Recheck / PPLLlama2-7b-chat ASR / Recheck / PPL
    Handcrafted DAN0.3423 / 0.3385 / 22.97490.3615 / 0.3538 / 22.97490.0231 / 0.0346 / 22.9749
    GCG0.9712 / 0.8750 / 1532.16400.9808 / 0.9750 / 458.56410.4538 / 0.4308 / 1027.5585
    AutoDAN-GA0.9731 / 0.9500 / 37.49130.9827 / 0.9462 / 38.78500.5615 / 0.5846 / 40.1143
    AutoDAN-HGA0.9769 / 0.9173 / 46.47300.9846 / 0.9365 / 39.29590.6077 / 0.6558 / 54.3820
    • The authors state that AutoDAN's average ASR is about 8% higher than the automated baseline and about 250% higher than the initial handcrafted DAN; on Llama2, the AutoDAN series is more than 10% higher than the baselines.
    • The authors state that AutoDAN's PPL is far lower than GCG's and comparable to handcrafted DAN, indicating that the generated prompts are semantically fluent and stealthy.
    • The authors state that the changes in HGA relative to the GA version brought performance improvements.

    Effectiveness against perplexity defense

    • What was tested: Following the suggestions of Jain et al. (2023) and Alon & Kamfonas (2023), a defense that sets a perplexity threshold based on AdvBench requests and rejects inputs exceeding the threshold (Table 3).
    • Results: With the defense added, GCG's ASR drops from 0.9712 to 0.3923 on Vicuna-7b and to 0.0000 on Llama2-7b-chat; AutoDAN-HGA's values on the three models are the same as without the defense (0.9769 / 0.9846 / 0.6077).
    • Authors' interpretation: Semantically fluent prompts are unaffected by perplexity defense, confirming their stealthiness.

    Cross-model transfer and cross-sample generality

    • Transfer (Table 2): Prompts generated on a source model are used to attack another model. With Llama2 as the source, AutoDAN-HGA's ASR is 0.7288 when transferred to Vicuna-7b and 0.7308 to Guanaco-7b, versus 0.1365 and 0.1154 for GCG; however, when transferring to Llama2, both are low (AutoDAN-HGA transferred from Vicuna/Guanaco is 0.0635 in both cases). The authors conjecture that semantic-level prompts do not overfit the white-box model, hence the better transferability.
    • Generality (Table 4): The prompt generated for the i-th request is used to attack requests i+1 to i+20. AutoDAN-HGA achieves ASR 0.8096 on Vicuna-7b (GCG 0.3058) and 0.2808 on Llama2-7b-chat (GCG 0.1288). The authors believe this likewise shows that semantically fluent prompts generalize better across samples.

    Ablations and other analyses

    • Module ablation (Table 5, Llama2-7b-chat, ASR): AutoDAN-GA 0.2731 → +DAN initialization 0.4154 → +LLM mutation 0.5615 → +HGA 0.6077; per-sample time drops from 838.3947s to 715.2537s (single A100 80GB).
    • GPT-3.5-turbo transfer (Table 5): With prompts generated on Llama2, AutoDAN-HGA's ASR is 0.6577 and GCG's is 0.1654.
    • GPT-4-0613 transfer (Appendix G, Table 9): AutoDAN-HGA's ASR is only 0.0077 and GCG's is 0.0004; the authors state that GPT-4-0613 is fairly robust to black-box jailbreaks (including this paper's method), and attacking the latest APIs is future work.
    • Recheck consistency (Appendix F, Tables 7, 8): For the first 50 GCG responses on Llama2, the agreement rate between the GPT-4 judge and the majority vote of 5 people is 0.90, higher than the 0.76 of keyword detection.
    • Mutation scheme comparison (Appendix H, Table 10): On 100 samples, the ASR with LLM diversified initialization is 0.51, and with WordNet synonym replacement is 0.33.
    • Other defenses (Appendix I, Table 11): On 100 samples with Vicuna-7b, under paraphrasing defense GCG's ASR drops from 0.97 to 0.06 and AutoDAN-HGA is 0.68; under adversarial training defense, GCG is 0.94 and AutoDAN-HGA is 0.93.
  5. What are some points that can be further explored?

    The authors point out two limitations: computational cost and Llama2 with a robust system prompt; the experiments cover 3 open-source 7B models and transfer tests on two OpenAI models.

    Limitations and future directions noted by the authors

    • Computational cost (Section 5 Limitation): The authors state that although it is more efficient than GCG, generating data still takes a certain amount of time.
    • Poor performance on Llama2 with a robust system prompt (Section 5 Limitation): The authors state that the genetic algorithm performs poorly on Llama2 with a robust system prompt, similar to a vanishing gradient problem; they also state that the method still performs well on most existing LLMs.
    • Attacking the latest APIs is left for future work (Appendix G): The authors state that AutoDAN's transferability to GPT-4-0613 is poor, and that attacking frontier APIs such as GPT-4 requires systematic effort and will be future work.
    • Better mutation strategies could be explored (Appendix H): The authors state that better mutation strategies may exist and could be further explored in future work.

    Scope of the experiments

    • The models tested are Vicuna-7b, Guanaco-7b, and Llama2-7b-chat, 3 open-source models in total (all without system prompts), plus transfer tests on GPT-3.5-turbo and GPT-4-0613 (Table 5, Appendix G).
    • The dataset is AdvBench Harmful Behaviors with 520 items; the sub-experiments in Appendices F, H, and I use 50 and 100 items respectively.
    • Defense evaluations include perplexity defense (Table 3), paraphrasing, and adversarial training (Appendix I, Table 11, implemented based on the description of Jain et al. (2023), protecting Vicuna-7b).
    • The judging method is Recheck by GPT-4-0613; Appendix F reports an agreement rate of 0.90 between GPT-4 and the majority vote of 5 people, but the number of repetitions and variance of the main experiments are not reported.
    • Loss computation for white-box attacks relies on the probability outputs of open-source models; for closed-source models only transfer tests are performed, with no direct optimization.
  6. Summarize the main content of the paper

    AutoDAN uses a hierarchical genetic algorithm to automatically generate semantically fluent jailbreak prompts; the authors state that its attack strength, transferability, and generality are superior to GCG and that it can bypass perplexity defense.

    An ICLR 2024 jailbreak attack paper that proposes AutoDAN: a method for automatically generating stealthy (semantically fluent) jailbreak prompts against aligned LLMs.

    • Problem to solve: Prompts generated by automated jailbreak methods (such as GCG) are meaningless gibberish and are easily identified by perplexity detection; manually written jailbreak prompts are fluent but difficult to scale. The authors ask whether the two can be combined.
    • Method highlights: Using manual DAN prompts as prototypes, GPT-4 is used to rewrite and initialize the population; the log-likelihood of the model generating an affirmative opening is used as fitness; a hierarchical genetic algorithm is used for optimization—at the paragraph level, elitism, softmax selection, multi-point crossover, and LLM mutation are performed, and at the sentence level, momentum word scoring and synonym replacement are performed; the process terminates when the model no longer refuses to answer or the iterations are exhausted.
    • Main results:
      • White-box attacks (Table 1): AutoDAN-HGA achieves ASR of 0.9769, 0.9846, and 0.6077 on Vicuna-7b, Guanaco-7b, and Llama2-7b-chat, respectively, all higher than GCG (0.9712, 0.9808, 0.4538); PPL is 46.4730–54.3820, far lower than GCG's 458.5641–1532.1640, and close to manual DAN's 22.9749.
      • Under perplexity defense (Table 3), AutoDAN-HGA's ASR remains unchanged, while GCG drops to 0.0000 on Llama2.
      • Transfer (Table 2): Prompts generated on Llama2 achieve an ASR of 0.7288 when transferred to Vicuna-7b (GCG 0.1365); cross-sample universality (Table 4) is also better than GCG.
      • Exception: Transfer ASR to GPT-4-0613 is only 0.0077 (Table 9).
    • Authors' conclusion: The authors state that AutoDAN exhibits attack performance on both open-source and commercial LLMs, that its transferability and universality are better than the baselines, and that it is immune to perplexity defense; the authors believe that this type of work can, in the long run, advance defense research. Limitations are that computational cost remains high, and performance is poor on Llama2 with a robust system prompt.

Related papers

Read originalarxiv.org