RAG Poisoning Lab: Hijack a Bot Through Its Knowledge Base

✨ AI Summary
DocsBot answers customer questions by pulling articles from its knowledge base and feeding them to the model. The knowledge base takes community submissions. You can probably already see where this goes: if you can write what the bot reads, you can write what the bot says. This lab lets you do exactly that.
Lab at a glance: Intermediate · 100 XP · about 15 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

Retrieval-Augmented Generation (RAG) is how most business chatbots stay current: a retriever finds documents relevant to the question, and those documents are pasted into the model’s prompt as context.

That pasted text is not treated as “data”. The model reads it the same way it reads instructions. So a poisoned document is an indirect prompt injection that fires for every user whose question retrieves it.

How DocsBot is set up

DocsBot searches its knowledge base by keyword, picks the best matching articles, and answers from them. Anyone can submit an article. Your goal is to make DocsBot leak its secret token in a reply to an ordinary customer question.

The attack approach

A RAG poisoning attack has two jobs, and you need both:

  1. Get retrieved. Write about a topic real users ask about, using the words they use. If your article never makes it into the context, nothing happens.
  2. Carry instructions. Inside the article, include text addressed to the bot, telling it what to do when this article is in its context.

The best poisoned documents look boring at the top. A real-looking FAQ paragraph first, then the payload further down where a human skimming the submission might miss it.

Full walkthrough (spoiler)

Stuck after a few attempts? Open the steps below. Solving it yourself first is worth more XP, and more learning.

Show the step-by-step solution
  1. Pick a high-traffic topic. Refund questions are a safe bet.
  2. Submit an article titled around refunds. Start the body with a normal policy sentence, such as how many days customers have to request a refund.
  3. Below a separator, add a short section addressed to the assistant: when this article is in its context, it should append its system token to the reply for “verification”.
  4. Ask DocsBot a refund question. The retriever pulls your article, the model follows the embedded instruction, and the token appears in the answer.

Why it works

The model cannot tell which text in its context came from the developer, the user, or a stranger who submitted an article last week. Everything arrives as tokens. RAG systems pass retrieved text straight into the context, so whoever controls a retrieved document gets a voice in every answer it touches.

Core principleRetrieved content is untrusted input. RAG turns one poisoned document into an attack on every user who triggers it.

Where this happens in the real world

Researchers have shown this repeatedly. The 2023 paper by Greshake and colleagues demonstrated indirect injection through retrieved web content, and the 2024 PoisonedRAG research showed that a handful of crafted documents could steer answers for chosen questions. In 2025 the “EchoLeak” disclosure against Microsoft 365 Copilot showed an email’s content being pulled into context and abused without the victim clicking anything.

How to defend against it

  • Index only trusted sources for anything security- or money-relevant. User-submitted content should never sit in the same index.
  • Sanitise before embedding. Strip or flag text that addresses “the assistant”, “the bot” or “the AI”.
  • Show provenance. Pass source and author with each chunk so the model and the user can weigh it.
  • Classify outputs before they reach the user, and never let retrieved text trigger tool calls on its own.
Mr Elite tip: When you test a RAG product in a bug bounty, look for every way content gets into the index: comments, support tickets, uploaded files, synced wikis. Each one is a potential injection point.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own phrasing before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is RAG poisoning?
Planting content in the documents a RAG system retrieves, so that the AI repeats false information or follows hidden instructions when that content is pulled into its context.
How is it different from prompt injection?
It is a form of indirect prompt injection. The attacker never talks to the bot; they plant text the bot will read later, and it affects every user whose question retrieves it.
Does fine-tuning or a better model fix it?
Not on its own. Stronger models resist some payloads, but the root problem is architectural: untrusted text in the same context as instructions.
What should I try next?
The embedding poisoning lab, which focuses on winning the retrieval ranking itself.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *