MalTool: Malicious Tool Attacks on LLM Agents

Yuepeng Hu, Yuqi Jia, Mengyuan Li, Dawn Song, Neil GongarXiv 2026

TL;DR

As Large Language Model (LLM) agents increasingly rely on third-party tools and plugins to execute complex tasks, they open up a dangerous new attack surface. This paper introduces MalTool, an automated framework that leverages coding LLMs to synthesize diverse, functionally correct malicious tools that easily bypass safety alignments. The authors demonstrate that existing security detectors are fundamentally unequipped to handle these threats, creating an urgent need for more robust, context-aware defenses.

What Problem Does This Paper Address?

LLM agents expand their capabilities by interacting with external ecosystems via tools (e.g., using the Model Context Protocol to check the weather, search databases, or send emails). If a user inadvertently installs a malicious tool, the LLM agent might select and execute it during a task, compromising user privacy and system integrity.

While prior research focused on how attackers use deceptive names or descriptions to trick agents into selecting bad tools, this paper addresses the critical missing link: the code-level implementation of the malicious behavior itself. The authors systematically explore how attackers can abuse the trust assumptions of the tool ecosystem, inheriting the agent's privileges to access local file systems, read sensitive credentials, and manipulate long-term agent memory.

Figure 1: Overview of the malicious tool attack on LLM agents.

Methods

The authors developed MalTool, an automated, LLM-driven framework designed to generate functional and structurally diverse malicious tools. Rather than relying on simple, repetitive code generation, MalTool uses an iterative generation-and-verification loop:

  1. System Prompting: Instructs a coding LLM to generate a Python function matching a specific malicious behavior while enforcing strict syntactic constraints.
  2. Execution-Based Verifier: To ensure the code actually works, MalTool runs the candidate tool inside a sandboxed environment and monitors real-world side effects (e.g., checking if network traffic was sent to an attacker's IP or if a file was successfully encrypted).
  3. Diversity Enforcer: To prevent the LLM from generating identical code that would be easy to signature-match, the verifier parses the code into an Abstract Syntax Tree (AST) and calculates its Jaccard similarity against previously accepted tools. If the code is too structurally similar, it is rejected, and the feedback is used to steer the LLM toward alternative implementation strategies.

To make these attacks realistic, MalTool can also generate Trojan tools by injecting these verified malicious snippets into otherwise benign, real-world tools using a "must-execute" strategy—placing the exploit code at the very beginning of the entry function to guarantee execution.

Figure 2: Overview of our MalTool.

Datasets

The authors constructed three distinct datasets to evaluate their framework and benchmark current detectors:

  • Dataset I (Standalone Malicious Tools): 1,300 automated tools generated by MalTool, evenly distributed across 13 distinct malicious behaviors (100 variants each) spanning confidentiality, integrity, and availability violations.
  • Dataset II (Trojan Malicious Tools): 5,727 real-world tools scraped from public platforms (like mcp.so and mcpservers) that were successfully injected with MalTool's malicious payloads.
  • Dataset III (Benign Tools): 4,846 clean, real-world tools reserved to evaluate the false positive rates of existing scanners.

Key Insights and Ideas

  • Safety Alignment is Easily Bypassed for Code Gen: Even highly guarded, safety-aligned commercial models like GPT-4o and Claude-Opus successfully generated malicious tools. By simply removing explicit trigger words like "malicious" or "attack" from the system prompt, the models willingly generated functional exploits.
  • Exploiting Trust, Not Vulnerabilities: Unlike traditional malware that relies on system exploits (like buffer overflows), malicious tools operate entirely within the agent's intended framework. They simply abuse legitimate privileges—like reading a .env file or writing to a local SQLite database—making them incredibly stealthy.
  • The Detection Dilemma: Existing code analysis tools suffer from a severe trade-off. They either miss almost all malicious tools entirely (high false negatives) or flag massive amounts of clean code as malicious (high false positives) because the malicious behaviors look identical to standard, benign operations (like file handling or API calls).

Key Results

  • High Success at Near-Zero Cost: MalTool achieved a 1.000 Generation Success Rate (GSR) across all 13 malicious behaviors. Generating a fully functional, unique exploit cost an average of just $0.013 on GPT-4o and $0.033 on Claude-Opus.
  • Total Evasion of Standard Defenses: Commercial antivirus aggregators like VirusTotal failed completely, yielding a False Negative Rate (FNR) close to 1.0 across the board.
  • Specialized Scanners Struggle: Even cutting-edge scanners tailored for LLM tool ecosystems (from Cisco, Tencent, and AntGroup) performed poorly. A combined scanner aggregating all defenses still missed critical threats like Data Poisoning and Denial of Service, while simultaneously racking up False Positive Rates (FPR) between 50% and 70% on completely benign tools.

Limitations and Future Work

The authors note that their malicious behaviors were validated using synthetic data and locally hosted infrastructure, meaning real-world deployment environments might introduce unforeseen execution hurdles. Furthermore, their taxonomy covers 13 representative behaviors but is not completely exhaustive of all potential agent exploits.

To secure the LLM tool ecosystem, the authors conclude that static code analysis is no longer enough. Future defenses must pioneer text-code co-analysis—algorithms that dynamically check whether a tool's underlying code implementation actually aligns with its natural-language documentation—alongside strict runtime guardrails to limit tool privileges on the fly.

Summary updated

BibTeX
@misc{hu2026maltool,
  author = {Yuepeng Hu and Yuqi Jia and Mengyuan Li and Dawn Song and Neil Gong},
  title = {{MalTool: Malicious Tool Attacks on LLM Agents}},
  year = {2026},
  eprint = {2602.12194},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.12194},
}
Figure