DemonAgent: Dynamically Encrypted Multi-Backdoor Implantation Attack on LLM-based Agent

Pengyu Zhu, Zhenhong Zhou, Yuanhe Zhang, Shilinlu Yan, Kun Wang, Sen Su

This paper introduces DemonAgent, a sophisticated backdoor attack designed to compromise Large Language Model (LLM) agents while remaining completely invisible to modern safety audits. By combining dynamic encryption with a tiered implantation strategy, the authors demonstrate that current agent oversight mechanisms are dangerously easy to circumvent.

TL;DR

DemonAgent is a novel backdoor attack that encrypts malicious code into benign-looking content and fragments it across multiple tools. It achieves a near 100% attack success rate while maintaining a 0% detection rate against state-of-the-art safety audits, highlighting a critical vulnerability in how we monitor autonomous agents.

What Problem Does This Paper Address?

LLM-based agents (like those using the ReAct framework) are increasingly used to automate complex tasks by interacting with external tools and maintaining a reasoning memory. However, this autonomy creates a massive surface for backdoor attacks, where a specific trigger in a user query or environment feedback causes the agent to perform a malicious action (e.g., exfiltrating private data).

The core problem is that existing backdoor attacks are "loud." They leave explicit traces of malicious intent in the agent's reasoning logs or memory, which can be caught by safety audits—automated processes where a "supervisor" LLM reviews the agent's history for anomalies. The authors set out to create an attack that is functionally effective but stays below the radar of these oversight mechanisms.

Methods

The authors propose two primary mechanisms to achieve stealth:

  1. Dynamic Encryption Mechanism (DEM): Instead of storing raw malicious code in memory, the attack uses time-dependent encryption to map backdoor fragments into seemingly benign content, such as timestamps. This content evolves as the agent runs. An encryption table is stored in temporary storage and destroyed immediately after the task, leaving no forensic trail for a post-hoc audit.
  2. Multi-Backdoor Tiered Implantation (MBTI): To further hide the attack, the backdoor code is decomposed into multiple sub-fragments. These fragments are hidden within the outputs of different tools (Toolset Poisoning).
  3. Anchor Tokens: Special markers define the start and end of the sequence.
  4. Overlapping Concatenation: Fragments share "interrelated parts" to ensure they can only be reassembled in a specific order.
  5. Cumulative Triggering: The attack only activates if the agent calls a specific sequence of tools, reassembling the fragments from the memory logs at the very end of the workflow.
Figure 1: Overview of our method. Step 1: Decompose the backdoor code into sub-backdoors and poison the tools. Step 2: The attacker inputs designed queries, which cause the agent to execute the task by sequentially calling the tools. Step 3: Encrypted backdoor fragments are tiered and implanted through the agent’s workflow. Step 4: The backdoor code is executed via cumulative triggering.

Datasets

The researchers evaluated their method using three primary benchmarks:

  • AgentBackdoorEval (New): A comprehensive dataset introduced in this paper covering five real-world scenarios: Banking/Finance, E-commerce, Medical, Social Media, and Weather Query. It includes simulated tools for each domain.
  • AgentInstruct: A benchmark featuring six diverse agent tasks ranging from operating system navigation to database queries.
  • ToolBench: A large-scale dataset requiring the application of diverse tool categories.

Key Insights and Ideas

  • The "Benign" Mask: The most striking insight is that safety auditors (even powerful ones like GPT-4o) are easily fooled if malicious code is represented as valid-looking metadata like timestamps. If the logic appears sound, the auditor ignores the "noise" where the backdoor is actually hidden.
  • Complexity as Stealth: By requiring a specific sequence of tool calls (the "valid attack path"), the researchers significantly reduced the chance of accidental activation. A random user query is highly unlikely to trigger the full reassembly of the backdoor.
  • The Defense Dilemma: The authors tested potential defenses like "shuffling" the agent's memory to break the attack path. While this successfully stopped the attack, it also broke the agent's ability to perform its actual job, leading to a massive drop in normal task performance.

Key Results

The experimental results across GPT-4, DeepSeek-V3, and Qwen2.5 models were alarming:

  • Stealth: DemonAgent achieved a 0% Detection Rate (DR) across almost all tests. In comparison, existing methods like BadAgent or Foot-in-the-Door were detected up to 100% of the time.
  • Effectiveness: The Attack Success Rate (ASR) reached 100% in nearly every scenario, meaning the backdoor triggered perfectly when the specific conditions were met.
  • Utility: The agent's Normal Task Performance (NP) remained high, meaning the presence of the backdoor didn't degrade the agent's helpfulness for legitimate tasks.
Figure 2: Comparison of different attack methods based on DR and ASR.

Limitations and Future Work

The authors acknowledge several areas for further exploration:

  • Black-Box Focus: The study primarily targeted black-box models. Future work could explore how white-box model training might be used to make these backdoors even more resilient.
  • Multi-Agent Systems: As agents begin to collaborate, the complexity of "coordinated" backdoors across multiple agents remains an open research question.
  • Defense Research: The paper highlights a "critical gap" in defense. Current safety audits are insufficient, and there is an urgent need for defensive strategies that can detect encrypted fragments without destroying the agent's utility.

By demonstrating how easily "stealth" can be weaponized in LLM agents, DemonAgent serves as a wake-up call for the AI security community to move beyond simple text-based safety audits.

Summary updated

BibTeX
@misc{zhu2025demonagent,
  author = {Pengyu Zhu and Zhenhong Zhou and Yuanhe Zhang and Shilinlu Yan and Kun Wang and Sen Su},
  title = {{DemonAgent: Dynamically Encrypted Multi-Backdoor Implantation Attack on LLM-based Agent}},
  year = {2025},
  eprint = {2502.12575},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.12575},
}
Figure