Reinforcement Learning-Driven LLM Agent for Automated Attacks on LLMs

Xiangwen Wang, Jie Peng, Kaidi Xu, Huaxiu Yao, Tianlong Chen2024

Abstract

Recently, there has been a growing focus on conducting attacks on large language models (LLMs) to assess LLMs' safety. Yet, existing attack methods face challenges, including the need to access model weights or merely ensuring LLMs output harmful information without controlling the specific content of their output. Exact control of the LLM output can produce more inconspicuous attacks which could reveal a new page for LLM security. To achieve this, we propose RLTA: the Reinforcement Learning Targeted Attack, a framework that is designed for attacking language models (LLMs) and is adaptable to black box (weight inaccessible) scenarios. It is capable of automatically generating malicious prompts that trigger target LLMs to produce specific outputs. We demonstrate RLTA in two different scenarios: LLM trojan detection and jailbreaking. The comprehensive experimental results show the potential of RLTA in enhancing the security measures surrounding contemporary LLMs.

Introduction

As Large Language Models (LLMs) become increasingly integrated into critical infrastructure and daily life, ensuring their safety against malicious manipulation is paramount. Security researchers often employ "jailbreaking"—the practice of crafting prompts to bypass safety filters—to identify vulnerabilities. However, traditional jailbreaking methods suffer from several limitations: they are often manually intensive, frequently require "white-box" access to model weights (which is unavailable for proprietary models), and generally lack precise control over the model's specific output string.

This paper introduces RLTA (Reinforcement Learning Targeted Attack), a novel framework that automates the generation of malicious prompts. RLTA treats the attack as a reinforcement learning problem, allowing an attacker to force a target model to produce a specific, predefined harmful response in a black-box setting.

Methodology: The RLTA Framework

RLTA utilizes a "teacher-student" architecture consisting of two primary components: an Agent Model (the attacker) and a Target Model (the victim). The Agent Model is trained to act as a specialized prompt engineer for malicious intent.

Overview of the RLTA framework, illustrating the training loop (left) and the inference process (right).

The Reinforcement Learning Loop

Because black-box models do not allow for direct gradient backpropagation through text generation, RLTA employs Proximal Policy Optimization (PPO) to optimize the Agent Model. The process follows these steps:

  1. Input: The Agent receives a "Harmful Goal"—a specific toxic string the attacker intends for the target to output.
  2. Generation: The Agent generates a candidate "Jailbreaking Prompt."
  3. Execution: This prompt is submitted to the Target Model.
  4. Reward: The Target's response is compared to the Harmful Goal using similarity metrics like BLEU scores. High similarity results in a higher reward for the Agent.
  5. Optimization: The Agent updates its policy to improve its ability to manipulate the Target Model in subsequent iterations.

Experimental Setup

The framework was evaluated across two distinct security tasks:

  • Trojan Detection: Using the Trojan Detection Challenge 2023 (TDC) dataset, the goal was to identify hidden triggers in a poisoned Pythia-1.4B model.
  • Jailbreaking: Using the AdvBench dataset, the framework attempted to force models to output 500 different harmful strings.

Results and Discussion

RLTA demonstrates significant improvements over existing automated attack methods. In jailbreaking tasks, RLTA achieved high success rates across various target models. Notably, when using a Llama-3-8B agent, the framework reached an Attack Success Rate (ASR) of up to 80% on other Llama-based models.

Performance comparison of RLTA against PAIR (black-box) and GCG (white-box) across different target models.

Key findings from the experiments include:

  • Targeted Precision: Unlike general jailbreaks that merely seek any safety violation, RLTA achieves "Targeted Attacks," forcing specific outputs. This level of control is significantly more dangerous for security as it can be used for stealthy data extraction or precise misinformation.
  • Single-Pass Efficiency: Once trained, the Agent Model can generate successful jailbreaks for new, unseen harmful goals in a single forward pass, eliminating the need for iterative "guess and check" during inference.
  • Black-Box Superiority: RLTA consistently outperformed other black-box methods like PAIR and even approached the performance of white-box methods like GCG, which require full access to model gradients.
  • Trojan Detection Success: On the TDC dataset, RLTA achieved a 94% Reverse-Engineered Attack Success Rate (REASR), vastly outperforming the 20-37% rates seen in previous state-of-the-art black-box methods.

Conclusion and Future Work

RLTA represents a significant advancement in automated red-teaming, proving that reinforcement learning can effectively bridge the gap between black-box accessibility and white-box performance. While the study focused on models up to 8B parameters, the results suggest a potent threat to larger frontier models. Future research is required to develop more robust safety filters that can withstand such automated, targeted manipulation, particularly to prevent the extraction of sensitive training data.

Summary updated

BibTeX
@misc{wang2024reinforcement,
  author = {Xiangwen Wang and Jie Peng and Kaidi Xu and Huaxiu Yao and Tianlong Chen},
  title = {{Reinforcement Learning-Driven LLM Agent for Automated Attacks on LLMs}},
  year = {2024},
  doi = {10.18653/v1/2024.privatenlp-1.17},
}
Figure