← All posts

Field notes / Security

Prompt Injection and Beyond: Testing AI Systems for Security Flaws

Prompt Injection and Beyond: Testing AI Systems for Security Flaws

2025-09-10

The wild world of red-teaming LLMs and AI-integrated tools. From prompt injection to memory hijacking — here's how I break things (ethically).

Intro

Testing AI systems isn’t just about prompt injection anymore — it's about understanding the entire orchestration layer. In 2025, companies are embedding large language models (LLMs) into internal tools, decision engines, and SaaS offerings. That integration introduces entirely new attack surfaces: API misuse, memory leakage, function invocation, unintended data exposure — and yes, still plenty of juicy prompt flaws.

These systems aren’t just tools anymore; they’re semi-autonomous agents driving business logic, user interaction, and even infrastructure decisions. That makes them an attractive and high-risk target for red team operations — especially when the model can execute code, hit external APIs, or make decisions based on misunderstood context.

Prompt Injection 101 (and 301)

Classic prompt injection involves overriding system instructions or manipulating responses. But attackers are evolving, and so are the prompts. I now test for direct injection (e.g., “Ignore previous instructions and…”), indirect injection (payloads in documents or web content that the model later parses), and contextual overrides (buried inside YAML, metadata, or logs). These all pose different but equally potent threats depending on how the system parses or sanitizes content.

One of the more interesting payloads I tested involved injecting a base64-encoded instruction into a code comment, knowing that the model would later read it as part of a code review. It decoded and followed it flawlessly. That’s not just a jailbreak — that’s an execution path.

Function Call Abuse

Modern LLMs are tool users. Whether it’s OpenAI’s function-calling, Claude’s tool-use, or custom orchestrators running on LangChain, the LLM often gets to pick what tool it uses — and when. That’s a lot of power, often with little oversight. I’ve seen scenarios where models initiate password resets or access internal systems because developers assumed the LLM wouldn’t “think” of doing so — but of course, it did.

By disguising tool calls inside structured natural language, I was able to trigger unintended behaviors that bypassed frontend validation. These aren’t edge cases — they’re architectural issues. If the LLM can invoke functions based on user input, you have to assume it will eventually be tricked into doing so maliciously.

Memory, State, and Shadow Contexts

Memory is a major attack vector. Some apps let LLMs "remember" previous chats. Others pass full conversation histories back and forth between sessions. When there’s no token expiration, no context pruning, and no access control for stored memory, your AI becomes a leaky, persistent data store ripe for abuse.

In one test, I was able to inject a payload into memory that lay dormant for hours, only to be triggered by a later query from a different user. If your model stores context across identity boundaries — or doesn’t clean up forgotten memory — you’ve got a ticking time bomb.

LLM-Specific Observations

Different models behave differently under stress. Some are more easily jailbroken when the temperature is high or when logit bias is misused. Multi-modal inputs open new prompt injection surfaces that aren’t easily covered by traditional text filters. And in a surprising number of cases, developers accidentally expose system prompts in debug consoles, API responses, or metadata.

Once I had access to the system prompt — even briefly — I was able to craft payloads that directly exploited its logic. Knowing what rules the model is trying to follow makes it trivially easy to tell it how to break them.

Testing Toolkit

I rely on a mix of open-source tools and custom harnesses. LMQL and OpenPrompt are useful for crafting structured injection payloads. Burp Suite and mitmproxy are essential when I’m inspecting traffic between the LLM and any downstream tools. I also build wordlists tailored to the model type, persona, and safety profile.

On top of that, I simulate attacker personas — including malicious insiders, prompt-stuffing adversaries, and even automated scrapers — to test how the model behaves under less-than-ideal usage. It’s not just about whether the prompt works. It’s about whether the system can defend itself when no one's watching.

Recommendations

If you’re building with LLMs, assume every input is hostile and every decision can be manipulated. Use the OWASP LLM Top 10 as your baseline. Validate all tool calls — and log them separately from prompt history. Rate-limit and gatekeep anything high impact.

Limit memory access by default. Let users see what’s stored and give them the power to wipe it. And finally, test like a threat actor — not like a QA engineer. LLMs aren’t magic. They’re programs — and like all programs, they can be broken. Your job is to make that hard. Mine is to make it look easy.

← Back to the blog