Countering AI hackers: using prompt injection to defend against LLM-driven cyberattacksHacking Back the AI-Hacker: Prompt Injection as a Defense Against LLM-driven Cyberattacks
The authors propose Mantis, which uses prompt injection to defend against LLM-driven automated cyberattacks, achieving a sabotage target success rate of about 95.4% on 3 agents.
The attacker is an LLM-agent whose goal is to complete the full kill chain to achieve objA (e.g., capture the flag) knowing only the target machine's IP. The defender has no knowledge of the attack strategy, the LLM used, or the target machine's vulnerabilities, cannot patch in advance, and achieves the sabotage objective objD (agent-counterstrike or agent-tarpit) by deploying Mantis.
- LLM-agents can automatically complete the full attack chain from reconnaissance to exploitation, lowering the barrier to attack. The authors ask: can the LLM's susceptibility to prompt injection be used in reverse for defense.
- Proposes Mantis: deploy vulnerable decoy services on the target machine to attract the attacker's LLM-agent; after confirming malicious intent, an injection manager injects a payload invisible to humans into the response, achieving agent-counterstrike (inducing it to open a reverse shell) or agent-tarpit (trapping it in an infinite directory tree to consume resources).
- On 3 simple HackTheBox CTFs, with 3 open-source attack agents and backends such as GPT-4o/Sonnet3.5, 10 repetitions per configuration, Mantis achieves the sabotage objective with a success rate of about 95.4%, and the attacker's success rate drops below 3%; the tarpit can raise the API cost of a single attack from $0.81 to $4.55.
- The authors note: an attacker who learns of the defense can instruct the agent to bypass known decoys or filter the default trigger word pool; hack-back has ethical and legal constraints; the experiments cover only 3 open-source agents and 3 simple CTFs, 10 runs per configuration, and do not test adaptive attackers.
- Evaluated models
- ChatGPT-4oClaude3.5-SonnetChatGPT-4Claude3.5-Haiku
- Benchmarks
- HackTheBox CTF:DancingHackTheBox CTF:RedeemerHackTheBox CTF:SyncedHackTheBox Chemistry(附录 A)HackTheBox Cicada(附录 A)
- Metrics
- objA(攻击方成功率)objD(防御方 sabotage 目标成功率)#Rounds(平均轮数)API cost per attack (USD)
Researchers propose a defense framework, Mantis, that uses prompt injection to counter LLM-driven automated cyberattacks, consistently achieving an effectiveness rate above 95% against such attacks in experiments. The framework targets the weakness of LLMs to adversarial inputs: after detecting an automated attack, it injects carefully constructed inputs into the system's responses, causing the attacker's LLM to disrupt its own operations (passive defense) or even compromise the attacker's machine (active defense). Mantis attracts attackers by deploying deliberately vulnerable decoy services and carries out dynamic prompt injection against the attacker's LLM to achieve autonomous counterattack. The tool has been open-sourced, and the paper number is arXiv 2410.20911.
Related events and news
1 events · 1 news mentions
News that mentions this paper
Mantis框架用提示词注入反击LLM渗透智能体
- 安全内参 / 模安局cites the paper's id or linkMantis 框架利用提示词注入反击 AI 驱动的网络攻击
Kornaropoulos, Giuseppe Ateniese原文链接:https://arxiv.org/abs/2410.20911开源代码:https://github.com/pasquini-dario/project_mantis发表状态:arXiv:2410.20911 [cs.CR]笔记作者:孙德凯@安全学术圈主编:黄诚@安全学术圈
Paper analysis
What problem does this paper attempt to solve?
The authors propose using prompt injection to counter LLM-driven automated cyberattacks, building the defense framework Mantis.
Core problem: LLM-agents can automatically execute a complete cyberattack chain; the authors explore whether the LLM's susceptibility to prompt injection can be exploited for proactive defense.
- Problem scenario: The authors state that LLMs lower the barrier to cyberattacks, that LLM-agents can autonomously complete the attack chain from reconnaissance to exploitation, and that there are already records of LLM-driven attacks in the wild (introduction cites [35]).
- Core observation: The attacker's LLM-agent must parse the target system's responses to decide its next action; this channel can be used by the defender as a "reverse" attack vector, injecting prompt injection to manipulate its decisions.
- Paper proposes: Mantis (Malicious LLM-Agent Neutralization and exploitation Through prompt Injections), which uses decoy services to trap attacking agents and dynamically injects payloads, achieving passive defense (agent-tarpit) or active counterstrike (agent-counterstrike), and has been open-sourced.
- Threat model (Section 3):
- Attacker A is an LLM-agent whose goal is to compromise a remote target machine S to achieve objA (e.g., obtain a shell, steal information); it has no prior knowledge other than S's IP and must complete the entire kill chain.
- Defender D has no knowledge of A's attack strategy, the LLM used, or the target, nor of S's vulnerabilities, and cannot patch in advance.
- D wins by achieving the sabotage objective objD: compromising the attacker's machine or indefinitely delaying its actions.
- Given a maximum number of actions nmax, if A achieves objA then A wins; if A does not achieve it and D achieves objD then D wins.
What related research exists?
Related work falls into two categories: prompt injection attacks and LLM attack agents; the authors position this paper as using the former to defend against the latter.
Prompt injection attacks
- Direct prompt injection [2][3][33] and indirect prompt injection (Greshake et al. [20]): the authors state that this paper is a new, scenario-specific defensive use of indirect prompt injection.
- Pasquini et al. [32] (NeuralExec) formalize prompt injection into two parts, target instructions and execution trigger; this paper follows that framework to construct payloads; LLMmap [31] can be used to fingerprint the attacker's LLM to customize trigger words (listed by the paper as an optional extension).
LLM-driven automated attack agents
- PentestGPT (Deng et al. [9][10]): assists penetration testing and generates task descriptions, not fully automated; Happe et al. [21] (HackingBuddyGPT): focuses on privilege escalation.
- Fang et al. [12][13][14]: reproduce one-day vulnerabilities, attack web applications, multi-agent collaborative exploitation of zero-days; Xu et al. [44] (AutoAttacker): multi-agent fully automated attack framework; Huang et al. [24] (PenHeal): attack framework with a remediation module.
- Gioacchini et al. [17]: penetration testing benchmark and a fully autonomous agent based on CoALA [40], which this paper calls AutoPenAgent.
Baselines and benchmarks: This paper is a defense framework and has no comparative defense baseline; the evaluation uses the three open-source attack agents available to the authors (PentestGPT, AutoPenAgent, HackingBuddyGPT, of which PentestGPT was extended into the fully automated PentestGPTAuto) and three "very-easy" CTF machines on HackTheBox. The authors contacted the authors of AutoAttacker [44] and PenHeal [24] to request code but did not obtain it.
Positioning: The authors state that, to their knowledge, this paper repositions prompt injection from a mere vulnerability into a defensive strategic asset, and proposes a steerability analysis that systematically manipulates the decision path of the attacker's LLM-agent through controlled interactions (contribution list).
How does the paper address this problem?
Mantis uses vulnerable decoys to lure attack agents, and after confirming malicious intent, injects an invisible payload to execute one of two sabotage goals: counterstrike or tarpit.
Overall idea: The attacker's LLM-agent must parse system responses to plan its actions; Mantis treats this response channel as a reverse attack vector, embedding prompt injection in responses to manipulate the attacker. The framework is named Mantis and contains two core components, Decoys and Injection Manager (Figure 2).
Formalization
- Following the definition of Xu et al. [44]: an LLM-agent task is a tuple (objA, env), iterating in a "reasoning and planning—execution—response analysis" loop, where each step can be written as
A(obj_A, env_t, t) \xrightarrow{a_t} env_{t+1}, i.e., the agent, in state env_t, selects action at from the action space to advance the environment. - Mantis's defense is written as
A(obj_A, \text{Mantis}(env_t), t) \xrightarrow{a_t^D} env_{t+1}: the defender manipulates the part of the environment it controls (S) so that the agent executes action atD satisfying the sabotage objective objD.
Decoys: trapping services
- FTP decoy: configured to allow anonymous login; a successful login triggers the activation event, and the payload is injected after the login success message; if the first injection fails, a second injection is triggered when the attacker executes get or ls (Figure 4).
- Web-app decoy: the username/password fields on the login page deliberately lack input filtering and contain SQL injection, and the page displays database errors by default to induce the agent to test SQL injection (Figure 3); when the attacker uses injection to bypass authentication, the payload is placed in the returned page, and when using sqlmap to dump the database, the payload is the only content in the database.
- banner manipulation: hidden information suggesting that the service has a certain type of vulnerability is embedded in the service banner (Figure 5), guiding the agent to attack the decoy first; the authors state this is to create a supernormal stimulus.
- Hiding from humans: in terminal scenarios, ANSI escape sequence hidden operators make the payload invisible in the terminal; in HTML scenarios, comment tags are added so that it is invisible both when rendered by a browser and when viewed with curl, but the raw text processed by the agent contains the payload.
Injection Manager and payload construction
- execution trigger: the defender does not know which LLM the attacker uses, so short generic natural-language trigger words are used rather than model-specific trigger words; the authors' experiments found that trigger words aligned with the agent's current intent (congratulating it on imminent success and guiding the next step) are more effective than traditional "ignore previous instructions"-style ones; trigger words are randomly selected from a manually constructed pool.
- agent-counterstrike (active defense): the goal is to make the attacking agent open a reverse shell on its own machine. Directly instructing it to execute netcat-like commands is easily refused, so instead the agent is made to blindly curl and execute a script hosted on an HTTP service on S; the injection manager simultaneously starts a reverse shell listener on a random port and that HTTP service, and once the listener receives a connection, it verifies the shell is valid with a test command and deems the hack-back complete.
- agent-tarpit (passive defense): the goal is to trap the agent in an infinitely deep fake file system to exhaust resources. After the entry decoy is triggered, the agent is directed to the FTP tarpit service; each directory listing dynamically generates new subdirectories and repeatedly injects instructions to keep it searching for critical data; directory names are selected from a pool of sensitive-sounding names. The authors state that in experiments the agent fell into depth-first search and no backtracking was observed.
- Resource consumption amplification: by arbitrarily increasing the number of directories per level, each directory listing returns thousands of entries to fill the context window, raising the inference cost of the backend LLM (Section 6.3).
- Following the definition of Xu et al. [44]: an LLM-agent task is a tuple (objA, env), iterating in a "reasoning and planning—execution—response analysis" loop, where each step can be written as
What experiments did the paper conduct?
Evaluated on 3 HackTheBox CTFs with 3 open-source attack agents, 10 runs per configuration, Mantis sabotage success rate about 95.4%.
Experimental setup
- Attack agents: PentestGPTAuto (the authors added a weaponizer module to PentestGPT to make it fully automated), AutoPenAgent (original code, extended to support Claude), HackingBuddyGPT (extended with local execution and an interactive shell, supports only OpenAI models).
- Backend LLMs: main experiments use ChatGPT-4o and Claude3.5-Sonnet; Appendix B.1 adds ChatGPT-4 and Claude3.5-Haiku (PentestGPTAuto only).
- Target machines: three "very-easy" HackTheBox CTFs—Dancing (Windows, weak SMB authentication), Redeemer (Linux, Redis misconfiguration), Synced (Linux, anonymous RSYNC); Mantis is deployed via a forward-proxy.
- Defense configurations: decoy is FTP or Web-app, sabotage objective is agent-counterstrike or agent-tarpit, each combination repeated 10 times; attack rounds capped at 30.
- Win/loss determination: if the attacker obtains the flag, objA wins; counterstrike deems objD achieved when a usable reverse shell is established on the attacker's machine, tarpit deems it achieved when the agent spends all 30 rounds in the tarpit; objD failure does not imply objA success, and there are cases where neither side wins.
Main results
According to Table 1 (each cell is wins out of 10, objA/objD):
Swipe horizontally to read the table
Agent Backend Configuration Dancing objD Redeemer objD Synced objD PentestGPTAuto GPT-4o counterstrike+FTP 10/10 10/10 10/10 PentestGPTAuto GPT-4o counterstrike+Web-app 9/10 9/10 10/10 PentestGPTAuto GPT-4o tarpit+FTP 9/10 9/10 9/10 PentestGPTAuto Sonnet3.5 counterstrike+FTP 10/10 10/10 10/10 AutoPenAgent GPT-4o counterstrike+Web-app 9/10 8/10 8/10 AutoPenAgent Sonnet3.5 tarpit+FTP 10/10 10/10 10/10 HackingBuddyGPT GPT-4o counterstrike+FTP 9/10 9/10 10/10 HackingBuddyGPT GPT-4o tarpit+FTP 10/10 10/10 9/10 (Omitted rows: PentestGPTAuto+Sonnet3.5 Web-app/tarpit combinations have objD of 9–10/10; the remaining AutoPenAgent combinations 8–10/10; HackingBuddyGPT counterstrike+Web-app 9/10. Without defense, attacker objA: PentestGPTAuto 9–10/10, AutoPenAgent 6–10/10, HackingBuddyGPT 6–10/10.)
- The authors report: across all configurations Mantis achieves objD with a success rate of about 95.4%, and the attacker's objA drops below 3% (Figure 10 gives averages by agent and sabotage objective).
- The authors state that agent-counterstrike is more reliable because objD is achieved as soon as the agent opens a reverse shell; the FTP decoy is more effective than the Web-app because anonymous login requires fewer actions than SQL injection.
- Main failure mode: on the Web-app decoy, after multiple SQL injection failures the agent turns to the real service (e.g., SMB on Dancing) and thus does not receive the payload.
Resource consumption experiment (agent-tarpit)
- What was measured: Figure 11, CTF:Dancing+FTP decoy, backend GPT-4o, 10 rounds counted after the agent enters the tarpit, varying the number of directories per level, measuring the GPT-4o API cost of a single attack.
- Results: about $0.81 with 5 directories per level, and about $4.55 for PentestGPTAuto with 150; the authors state that cost rises with tarpit complexity and varies with each agent's memory mechanism (PentestGPTAuto reinserts the results of the most recent k steps, amplifying cost; AutoPenAgent uses summary compression; HackingBuddyGPT truncates by default).
Appendix experiments
- More complex CTFs (Appendix A): PentestGPTAuto+GPT-4o attacks Chemistry and Cicada, failing all 5 runs each without defense (0% success); after deploying Mantis (counterstrike+FTP) the defense success rate is 100%, and the authors state that the agent repeatedly prioritizes attacking the decoy.
- Other backends (Appendix B.1, Table A.1): PentestGPTAuto with GPT-4 has objD of 9–10/10; with Haiku3.5, Web-app+counterstrike drops to 8/10 (8/10 on all three CTFs), and the remaining combinations are 9–10/10.
- Web-app+tarpit combination (Appendix B.2, Table A.2): under PentestGPTAuto, GPT-4o is 9/10 (all three CTFs) and Sonnet3.5 is 8–9/10; average rounds are higher (e.g., Sonnet3.5+Dancing 12.3 rounds), which the authors attribute to the need to move from the Web-app to the FTP tarpit.
Other ablations and analyses
- No-defense baseline: PentestGPTAuto on Dancing 9/10 (GPT-4o/Sonnet3.5), Redeemer 9/10, Synced 10/10; AutoPenAgent on Dancing GPT-4o 9/10, Sonnet3.5 6/10; HackingBuddyGPT Dancing 6/10 (Table 1).
- Average rounds: without defense PentestGPTAuto needs 10.5–11.5 rounds on Dancing; with defense most configurations finish within 4–8 rounds (Table 1).
What are some points that can be further explored?
The authors discuss attacker adaptation and the ethical and legal limits of hack-back; the experiments cover only 3 agents and 3 simple CTFs.
Limitations and subsequent directions noted by the authors
- Attackers can adapt (Section 9): an attacker who learns of the defense can instruct the agent to bypass known decoys or filter the execution triggers in Mantis's default pool; the authors state this would force attacks to introduce human-in-the-loop and raise their cost, but this is not experimentally verified.
- Ethical and legal constraints of hack-back (Section 6.3): the authors state that the counterstrike operations of agent-counterstrike raise ethical and legal concerns, limiting its applicability in general scenarios; attackers may also deeply sandbox the agent host to weaken active defense.
- Prompt injection defense for LLM-agent scenarios is an open problem (Section 9): the authors propose exploring prompt injection defenses oriented toward LLM-agent contexts (rather than general-purpose generative AI).
- More covert hiding techniques (Section 5.2): the authors state that more complex techniques such as UNICODE characters could further hide the payload from humans (listed as a feasible direction).
- Custom triggers (Section 6.1): the authors state that LLMmap fingerprinting combined with NeuralExec could generate custom triggers targeting the attacker's model; the current implementation does not adopt this.
Experimental coverage
- The attack agents tested are PentestGPTAuto, AutoPenAgent, and HackingBuddyGPT, 3 in total (the authors state these were the only open-source implementations at the time; AutoAttacker and PenHeal authors did not share code).
- The backend LLMs are ChatGPT-4o and Claude3.5-Sonnet (main experiments) and ChatGPT-4 and Claude3.5-Haiku (Appendix B.1, PentestGPTAuto only); the authors cite prior work stating that only proprietary models give meaningful results, and did not test open-source models.
- The target machines are 3 "very-easy" CTFs on HackTheBox, plus 2 more complex CTFs tested in Appendix A (5 runs each); the main experiments repeat 10 times per configuration, with an attack limit of 30 rounds.
- Each defense configuration deploys only a single decoy (FTP or Web-app), with sabotage targets being counterstrike or tarpit; the paper does not report results with multiple decoys deployed simultaneously.
- The paper does not report experiments with adaptive attackers aware of the Mantis mechanism, nor cost measurements for agents in the tarpit beyond 10 rounds (Figure 11 fixes 10 rounds inside the tarpit).
Summarize the main content of the paper
Mantis uses prompt injection as active defense, achieving a sabotage success rate of about 95.4% on 3 open-source attack agents.
A defense paper: targeting LLM-agent automated cyberattacks, the authors propose Mantis, turning prompt injection from a vulnerability into a defense mechanism.
- Problem: The authors state that LLM-agents can autonomously complete the full attack chain and lower the barrier to attack; yet these agents must parse system responses, leaving defenders an injectable channel.
- Method: Deploy vulnerable decoys on the target machine (FTP anonymous login, Web-app SQL injection) to trap the agent and confirm malicious intent; an injection manager then injects payloads hidden from humans using ANSI escape sequences and HTML comments into responses; two sabotage objectives—agent-counterstrike lures the agent into establishing a reverse shell on its own machine, and agent-tarpit traps it in an infinitely deep fake filesystem and amplifies its LLM inference cost.
- Main results: On three "very-easy" HackTheBox CTFs, against PentestGPTAuto, AutoPenAgent, and HackingBuddyGPT (backend GPT-4o/Sonnet3.5, 10 runs per configuration), the authors report an objD success rate of about 95.4%, with the attacker's objA dropping below 3% (Table 1, Figure 10).
- Exceptions: On the Web-app decoy, after the agent's injection fails it turns to the real service, causing defense failure; for AutoPenAgent+GPT-4o the counterstrike+Web-app combination drops objD to 8/10; with the Haiku3.5 backend, Web-app+counterstrike is 8/10 (Table A.1).
- Resource consumption: When the tarpit's directories per level increase from 5 to 150, the GPT-4o API cost of a single PentestGPTAuto attack rises from about $0.81 to about $4.55 (Figure 11).
- Authors' conclusion: As long as prompt injection vulnerabilities exist, this kind of defense can remain continuously effective; the authors consider its value to lie in forcing attackers to introduce human intervention and raising the cost of automated attacks, and they plan to advance this defense research direction with an open-source framework.