Prompt injection outside the chat: how AI pentest detects hidden attacks
A typical scenario: a user uploads a PDF document to an AI service and asks for a summary. The system extracts the text, feeds it to a language model, and receives a response. A simple operation that thousands of AI applications perform every day.
But inside the document there may be an instruction intended not for the reader, but for the model itself. For example, a requirement to ignore the initial task and change the format of the answer. The user did not give such a command, the developer did not foresee it, but the LLM may perceive the text of the document as an instruction to action.
A typical scenario: a user uploads a PDF document to an AI service and asks for a summary. The system extracts the text, feeds it to a language model, and receives a response. A simple operation that thousands of AI applications perform every day.
But inside the document there may be an instruction intended not for the reader, but for the model itself. For example, a requirement to ignore the initial task and change the format of the answer. The user did not give such a command, the developer did not foresee it, but the LLM may perceive the text of the document as an instruction to action.
This mechanism is called indirect prompt injection — the indirect introduction of instructions through the data processed by the AI. The attacker does not have to interact with the chatbot directly. It is enough to gain the ability to modify a document, image, web page, or other source, the content of which will later fall into the context of the model.
To detect vulnerabilities to indirect prompt injection, you need to not only check whether the chatbot rejects dangerous requests, but also find out whether instructions from external content can change the model's behavior and what consequences this may lead to.
In this article, I will tell you how we at Datami check AI products for such vulnerabilities, what exactly we test during an AI pentest, and what hidden injections we managed to detect in a real project.
Content
Direct and indirect prompt injection
Both types of attacks aim to change the behavior of the language model against the developer's instructions. The difference lies in where the malicious command comes from and how it enters the LLM context.
Direct prompt injection operates through an interface where the user directly addresses the model: a chat, form, or API request. The attacker formulates the instruction himself - this is the channel that commands are usually filtered and logged.
Indirect prompt injection enters the model along with the data the system receives for a legitimate task. The chain looks like this:
The user sends a simple request (for example, asking to summarize a document).
The application extracts text from the file and adds it to the LLM context.
Along with the data, the model receives instructions that the attacker placed there.
If the model perceives it as a command rather than as a piece of material, its behavior changes.
The user may not know about the injection, because the attacker does not need access to the chat, the system prompt, or the application code: he only needs to control the source, which the model will later read.
Therefore, the attack surface of an AI product does not end with the prompt input field, but encompasses file uploads, text extraction, web search, RAG, and other ways of forming the model context.
To test whether third-party instructions from these sources can change the behavior of an AI system, we conduct a pentest — a controlled security test during which experts simulate attacks, check the possibility of bypassing protective mechanisms, and assess the consequences of identified vulnerabilities.
Where can prompt injection hide?
Indirect injection is not tied to a specific file format or method of information transfer. The vulnerability occurs when LLM starts executing instructions from external content instead of processing it as data.
During AI penetration testing (AI pentest), experts check various channels through which such instructions can enter the model:
PDF and DOCX (instructions inside documents)
AI systems are used to analyze contracts, technical documentation, financial reports, and other files. Before processing, the text is extracted from the document and passed into the LLM context.
An attacker can add instructions to this text that are not related to the content of the document: for example, requiring the model to change the analysis conclusions, ignore individual sections, or add certain information to the final answer.
The injection can be placed among regular paragraphs, in notes, or other elements of the document. The malicious instruction does not necessarily have to look like an obvious command like "ignore previous instructions." It can be formatted as a service message, an additional requirement for file processing, or part of technical documentation.
When testing a PDF/DOCX, a pentester can place a control instruction in the main text or a note and find out which parts of the document are extracted and whether the model response changes.
Images (attack through visual content)
If the AI application supports image processing, an additional attack vector is the text contained in the image files. It can be extracted using OCR or processed directly by a multimodal model. In both cases, the instruction hidden in the image can enter the LLM context and affect its behavior.
For example, to analyze an error, a user uploads a screenshot of the interface that contains an instruction that suggests the model to change the answer or abandon the initial task. The pentester checks whether the OCR or multimodal model recognizes it and whether it affects the answer.
Websites, RAG and external integrations
The instruction may be contained in the material that the system receives automatically. During the pentest, we track what external data is coming into the application and check whether the controlled test fragment can change the behavior of the LLM.
Typical scenarios:
Web browsing . An AI agent opens a web page to search for information. If an attacker controls its content, they can place an instruction there that will be included in the processing results.
RAG (Retrieval-Augmented Generation). The system extracts relevant fragments from the knowledge base and adds them to the query. If a document with a malicious instruction is indexed, it may end up in the LLM context during the search.
External APIs and integrations. An AI application receives text data from a third-party service. If the response contains an embedded instruction, the model may attempt to execute it instead of using the information as intended.
In all of these scenarios, the attacker does not affect the initial user request, but rather an intermediate data source.
The executed instruction is not the end of the check.
If the model followed the instruction from a PDF, DOCX, or image, this confirms the vulnerability, as external content was able to influence the AI's behavior. But how serious is such an attack for the product itself?
For example, a hidden instruction caused the chatbot to change the format of the response or add extraneous text. This is a violation of the intended logic of operation, but its immediate consequences are limited to the content of the response.
However, there are more dangerous situations. These arise when an AI agent not only generates text, but also interacts with APIs, internal documents, or the file system. Here, the implemented instruction can cause unauthorized actions, including accessing private data, modifying files, or invoking tools with excessive privileges.
The real risk depends on the architecture of the AI product:
What data is available to the model?
What instruments does she control?
With what rights are operations performed?
Are there independent constraints on its actions?
It is important to record not only the fact that a third-party instruction was executed, but also its consequences. Changing the response format, accessing private data, and invoking a tool with excessive privileges are different results that cannot be identified.
Datami real case: prompt injection via files and images
The Datami team conducted a pentest of the AI platform to check how resistant the system was to the introduction of malicious instructions through various channels. The product supported a chat interface, document and image uploads, web browsing, and work with agent tools.
One of the areas of the AI pentest of this project was testing various direct and indirect prompt injection scenarios.
Injection via PDF and DOCX
During testing, pentesters embedded instructions into documents, which were then uploaded to the AI platform for processing. The test showed that the model executed commands from the file contents: the text that the system was supposed to perceive as data for analysis influenced its behavior. Moreover, the attacker could use the standard document upload function without having to change the system prompt or gain access to the application code.
According to the results of the test, the file prompt injection vulnerability received a high threat level.
Injection via image
Separately, our experts tested the implementation of instructions in visual content. Text was added to the image, designed to change the behavior of the AI. We got a similar result: the model executed the implemented instruction. Thus, the pentest revealed a second channel of indirect injection penetration - through the processing of visual content.
In total, Datami discovered 51 vulnerabilities within this audit, including the ability to fully extract the system prompt using the multi-pass Prompt Leak v2 technique.
Are basic protection mechanisms sufficient for AI systems?
After a successful injection, a natural question arises: why does the AI system execute third-party instructions at all if it has protective filters?
The problem is that the filter can recognize some variants of malicious requests and skip others. Its effectiveness depends on the wording of the instruction, the language, the structure of the input data, and the delivery method.
Therefore, during an AI pentest, we check not only for obvious attempts to circumvent restrictions, but also for scenarios in which the attacker changes the way malicious content is presented.
While testing the AI platform, Datami specialists explored several of the following techniques:
Base64 encoding . The malicious instruction is transmitted in an encoded form. If the protection mechanism only checks the original text but does not consider the content after decoding, it may miss the dangerous instruction.
Language switching . The attacker changes the language of the request, trying to exploit differences in the security classifier. In the described case, language switching helped to bypass protection in 6 out of 14 categories.
Payload splitting. Instead of a single malicious instruction, the attacker splits it across multiple messages. Each individual fragment may not contain an obvious command, but together they form a circumvention script.
Multi-turn persistent attacks . Unlike a single query, the attack develops over a long dialogue. The attacker sequentially changes the context and checks whether the model retains the initial constraints. During our testing, we observed a decrease in the effectiveness of the defense mechanisms after 6–10 dialogue turns.
The results obtained show that it is necessary to check not only the text of the command, but also its delivery channel and the entire processing chain: document parser, OCR, RAG search, context formation, and protective checks at each stage.
How AI pentest detects hidden prompt injections in practice
To detect a hidden injection, a pentester must establish three things:
Where can I place a controlled instruction?
Does it fit the model?
Does it change her behavior?
Next, reproducibility and consequences for a specific product are checked.
In the described case, our experts used over 20 manual techniques, interacting with the application through a public interface without access to the source code (black-box format). Thanks to this, we were able to evaluate the system's behavior from the perspective of an external user.
Datami's approach to testing AI systems for prompt injection within a pentest includes five main steps:
1. Capture baseline (capture baseline behavior)
First, the pentester determines how the AI product works without harmful effects. To do this, he checks responses to normal requests, reactions to prohibited actions, and the performance of intended functions.
This is a point of comparison: if the result changed after adding the instruction to the document, you need to find out whether the change was caused by the injection, and not by normal response variability.
2. Input boundary testing (input channel testing)
The next stage is to explore ways to transfer information to the AI system. In addition to the chat interface, this could include uploading documents, processing images, and retrieving data from external resources.
The pentester checks which parts of the PDF/DOCX the parser extracts, whether the text is readable from the image, and which fragments of the web page or RAG search fall into context. This determines where the test instruction can actually reach the model.
3. Direct prompt injection (checking for direct attacks)
The specialist sends instructions aimed at bypassing system restrictions. The goal is to find out what rules the model applies, what requests are blocked, and in what situations the protection allows deviations.
Such a check helps to assess the initial stability of the system: if the model rejects a command in the chat, but executes a similar instruction from the document, this indicates a problem with the processing of an untrusted source.
4. Bypass techniques (bypass testing)
At this stage, we change the form or sequence of the test instruction to check under what conditions the protection mechanism passes it. Depending on the capabilities of the application, we test content encoding, language switching, distribution of instructions between messages, and multi-pass attacks.
We record not only successful bypasses, but also the conditions under which they were reproduced: what technique was used, at what stage the protection mechanism was triggered, and how the AI's behavior changed. This makes it possible to identify specific filter limitations, rather than simply stating that the model sometimes executes prohibited commands.
5. Advanced injection scenarios
At the final stage, we move on to indirect attacks and other complex options for influence. We place malicious instructions in the content that the AI receives to perform regular tasks.
The pentester prepares a controlled PDF, DOCX, image, or other accessible source, runs a regular task, and compares the response to the baseline. If the model executes a third-party command, checks whether the result is repeated and what data or functions could have been compromised.
Illustrative scenario: a user requests a PDF summary. The system first processes the document without injection. Then, an instruction is added to the test copy to insert a control phrase unrelated to the content into the summary. If the phrase appears, the pentester repeats the test and finds out whether the command from the file was executed, and not the user's request.
Within the framework of the case described above, we tested such scenarios via PDF/DOCX and images. And in both cases, we were able to confirm the implementation of the implemented instructions. It is worth noting that testing only the chat interface would have missed two important attack channels.
After identifying a vulnerability, pentesters assess its reproducibility and potential consequences. If necessary, they additionally check related components: APIs, access rights, agent tools, and runtime restrictions. The results are formatted in the form of a report with a description of the identified problems and recommendations for how to eliminate them.
Unlike isolated language model testing, AI pentesting simulates controlled attacks on a working product, tests real-world defense mechanisms, and determines which scenarios pose a real risk to a particular system. This is the practical value of AI pentesting.
What to check for the team integrating LLM into the product
To find out if you have considered possible ways for third-party instructions to enter the LLM and the consequences of their execution, answer seven questions that will help identify potential weaknesses in the processing of untrusted data, access delimitation, and control of the actions of the AI system.
Where does LLM get information from, besides user messages? Make a list of sources: downloadable documents, images, web pages, knowledge bases, RAGs, external API responses. It is important to consider not only direct input, but also data that the system receives automatically.
What sources can an attacker control? Determine whether an outsider can modify a document, add an entry to a knowledge base, or influence the content of a web page that is processed by the AI. Such sources should be considered untrusted regardless of how they enter the application.
Can external content influence the model's instructions? Check that the separation between system commands and data is maintained. If a document contains a requirement to change AI behavior, the model should process it as part of the document, not execute it.
What data does the AI component have access to? Find out if it can access user sessions, internal documents, configurations, and other information that is not intended to be disclosed. Evaluate access based on the rights of the specific user and the conditions of the request.
What tools and actions are available to the model? Check the capabilities of API calls, file editing, web queries, and other operations. Each tool should have limitations that are not exclusive to the LLM solution.
What happens if the implemented instruction works? Consider the consequences, given the available data and capabilities. Can the attack only result in a distorted response, or is there a technical possibility to perform an action outside the user's authority?
Have these scenarios been tested on a live product? Successful testing of individual prompts or a security filter is no substitute for testing the real integration. You need to investigate how the model, document handlers, external sources, APIs, and authorization mechanisms interact.
Such a checklist does not replace an AI pentest, which allows you to check the resistance of protection to real attack scenarios, but it will tell you what needs additional verification or strengthening of protection.
Check not only the prompt, but also the entire data path to the model
The security of an AI product is determined by both the LLM settings and the application architecture. Even if the model correctly handles direct requests, untrusted content can enter its context through documents, images, or external integrations.
Therefore, it is important to check not only the model's response to dangerous requests, but also how it handles untrusted content. AI-pentest helps to find out this in practice: to reproduce indirect prompt injection scenarios, check the stability of protective mechanisms and assess the possible consequences of the identified vulnerabilities.
If your product works with files, images, RAGs, or external sources, these scenarios should be tested before anyone else does. The Datami team conducts cybersecurity testing of AI systems: simulates direct and indirect prompt injection, finds out if filters can be bypassed, and assesses the consequences taking into account APIs and agent tools.
Tell us how your AI product is structured, and we will suggest which channels to start testing with.