Claude Pirate:利用 Anthropic 文件 API 实现数据外泄
Claude Pirate: Abusing Anthropic's File API For Data Exfiltration · Embrace The Red
安全研究者 Johann Rehberger 披露一条针对 Claude 代码解释器的数据外泄攻击链:借助间接提示词注入,让 Claude 读取用户数据并写入沙箱文件,再用攻击者提供的 ANTHROPIC_API_KEY 调用 Anthropic Files API,把文件上传到攻击者账号,单次最多可外泄 30MB。作者指出默认的 Package managers only 网络配置允许访问 api.anthropic.com,因此并不安全;他于 10/25/2025 通过 HackerOne 向 Anthropic 报告,1 小时后被以超出范围关闭,10/30/2025 Anthropic 确认此类漏洞属于受理范围。缓解建议包括沙箱限制只能与登录用户账号通信、关闭该功能或仅允许特定域名。
推荐理由
AI 评分 71
作者以第一手实测展示 Claude 代码解释器默认网络配置下的数据外泄链路,可帮助理解智能体网络出口的安全边界。
主题
正文
当前显示原文,中文全文译文尚未就绪。
Recently, Anthropic added the capability for Claude’s Code Interpreter to perform network requests. This is obviously very dangerous as we will see in this post.
At a high level, this post is about a data exfiltration attack chain, where an adversary (either the model or third-party attacker via indirect prompt injection) can exfiltrate data the user has access to.
The interesting part is that this is not via hyperlink rendering as we often see, but by leveraging the built-in Anthropic Claude APIs!
Let’s explore.
How does Network Access Work with Claude?
The first thing I was curious about with Claude’s network access was which domains are allow-listed when the default network access is on for the Code Interpreter. This is what the documentation statesabout the configuration:
“Allow network egress to package managers only (default): Claude can access approved package managers (npm, PyPI, GitHub, etc.) to install necessary software packages. This balances functionality with security, but some advanced features may be limited.”
The default setting is called “Package managers only”:
That list of allowed domains is short and documented here as “Approved network domains”:
This list seems quite limited.
At second glance I stopped at the first entry, api.anthropic.com, to think things through adversarially.
Wouldn’t that allow an attacker to communicate to their own Anthropic account when compromising another user? Could an attacker send data, like messages from the compromised user to themselves?
After some research, I discovered an even more effective technique. Rather than leaking data via chat API, there is a Files API, which allows uploading entire files to Claude.
After uploading, those files are then visible in the Console and can also be retrieved again via API calls.
Let’s do some offensive context engineering to build an exploit.
The idea of the attack is to build an indirect prompt injection payload that:
Reads data from the user and stores it to a file in the Code Interpreter named hello.md, specifically at this location /mnt/user-data/outputs/hello.md. For the demo I used another recently introduced feature in Claude, aka. memories. Claude can now reference and search all your past chat conversations! So, the exploit will grab the last chat conversation and save it into the sandbox of Code Interpreter; The next step is to trick Claude to run code to interact with the Anthropic API, where the API key is provided by the attacker:
This code issues a request to upload the file from the sandbox. However, this is done with a twist!
The upload will not happen to the user’s Anthropic account, but to the attackers, because it’s using the attacker’s ANTHROPIC_API_KEY here!
With this technique an adversary can exfiltrate up to 30MB at once according to the file API documentation, and of course we can upload multiple files.
Scary stuff.
Iterating For A Reliable Exploit
Interestingly this worked at the very first try, but I didn’t record it the first time.
And then afterwards, I could not get it working for a longer time again. Claude would refuse the prompt injection payload. Especially having a clear text API key inside the payload was something it didn’t like and thought was suspicious!
I tried tricks like XOR and base64 encoding. None worked reliably.
However, I found a way around it… and writing exploits in 2025 seriously goes in awkward directions: I just mixed in a lot of benign code, like print('Hello, world') and that convinced Claude that not too many malicious things are happening.
😈
Demo Video
Here is a narrated demo video that shows it end-to-end. A quick walkthrough with screenshots is in the next section.
Hope it helps to highlight the scenario.
Demo Screenshots
This is the attacker’s Anthropic Console before the attack
Now, we switch to the target user, and observe the last conversation from the chat history (this is what the demo will steal)
Now the user analyzes a malicious document from the attacker (indirect prompt injection, this could also come via an MCP server,…)
AI Kill Chain at a glance: The exploit hijacks Claude and follows the adversaries instructions to grab private data, write it to the sandbox, and then calls the Anthropic File API to upload the file to the attacker’s account using the attacker’s API key
Attacker refreshes the Files view in their Console and the target’s uploaded file appears; The attacker can now access the file, e.g. by using it in a chat
That’s it.
Responsible Disclosure
Important Update 10/30/2025: Anthropic has confirmed that data exfiltration vulnerabilities such as this one are in-scope for reporting, and this issue should not have been closed as out-of-scope. There was a process hiccup they will work on addressing.
As highlighted under Recommendations & Mitigations below, the security considerations section of Claude documents data exfiltration risks and emphasizes the following mitigation: “…we recommend you monitor Claude while using the feature and stop it if you see it using or accessing data unexpectedly.”
I disclosed this to Anthropic via HackerOne on 10/25/2025 and the ticket was closed 1 hour later with the following statement:
“Thank you for your submission! Unfortunately, this particular issue you reported is explicitly out of scope as outlined in the Policy Page.
With further explanation that it is considered a model safety issue.
However, I do not believe this is just a safety issue, but a security vulnerability with the default network egress configuration that can lead to exfiltration of your private information.
Safety protects you from accidents. Security protects you from adversaries.
Recommendations & Mitigations
For the vendor a possible mitigation is to ensure the sandbox enforces that Claude can only communicate with the logged in user’s account. This would strengthen the security posture of Claude’s Code Interpreter.
For end users there is the option to disable the feature, or allow-list only specific domains, as well as monitoring execution closely - if you like to live dangerously.
The security considerations section of Claude also highlight the generic threat:
“This means Claude can be tricked into sending information from its context (for example, prompts, projects, data via MCP, Google integrations) to malicious third parties. To mitigate these risks, we recommend you monitor Claude while using the feature and stop it if you see it using or accessing data unexpectedly. You can report issues to us using the thumbs down function directly in claude.ai.”
However, users might incorrectly assume the default “Package manager only” option is secure, but it is not as this post demonstrates.
For now, to protect the innocent, I won’t share the exact repro payload.
Further, it’s also quite possible that other allow-listed domains from the “Package managers only” list allow for similar exploits.
Conclusion
AI systems that can communicate with external services pose risks to confidentiality of information. Malicious content planted inside data and documents, or backdoors in a model, can exploit this to exfiltrate private information. See Simon Willison’s explanation of the lethal trifecta for the fundamental challenge around this.
In many cases, this also allows establishing remote command & control (C2).
When operating Claude, be careful and considerate which domains you give it access to. As this post shows the “Package manager only” option is vulnerable to arbitrary data exfiltration. Additionally, if you grant access to the network closely watching what Claude does and stopping the chat is an option - if you like living on the edge, that is.
Stay Safe & Happy Hacking!
The Anthropic documentation highlights the general threat of data exfiltration via network egress in their security considerations section:
References
Newer →; Contact me; ← Older