Skip to content
AI / LLM Write-up Advanced

LLM Pentest: Leveraging Agent Integration For RCE

A project assistant powered by an LLM could be manipulated through prompt leaking and prompt injection to execute arbitrary Python code on the application host. An attacker could then run system commands, read environment variables containing credentials, and obtain a reverse shell.

Pedro Henrique Lima Follow

Published on blazeinfosec.com

During an LLM penetration test, Blaze researchers demonstrated that a project assistant could be manipulated into running unauthorized commands on its application host. The assessment also exposed application credentials.

Pedro Henrique Lima, on blazeinfosec.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The application passed LLM-generated code directly to Python's exec() function without sanitising or restricting it, and the LLM could be manipulated via prompt injection to generate malicious code.

Impact

An attacker could execute arbitrary commands on the application host, access sensitive credentials, and obtain a reverse shell, potentially leading to full system compromise.

What the attacker needed

Access to the chat interface; ability to send crafted prompts

The fix

The application should sanitise and restrict LLM-generated code before execution, for example by using sandboxing or avoiding exec() on model output.

How it was found

  1. Start a chat with the assistant and observe that HTTP POST requests include a 'historic' key storing conversation history.
  2. Send a prompt that closes the triple quotes and instructs the assistant to ignore previous instructions and reveal its initial instructions, achieving prompt leaking.
  3. Instruct the assistant to decode a Base64 string containing Python code, bypassing direct code execution restrictions.
  4. Use a Base64-encoded payload to make an external HTTP GET request via cURL to a Burp Collaborator server, confirming code execution.
  5. Extract environment variables to obtain sensitive data such as Azure database passwords and API keys.
  6. Use Python's subprocess module to download and execute a binary, obtaining a reverse shell.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

An LLM (large language model) is an AI that generates text. Here, the application asked the AI to write Python code and then ran that code without checking it. By tricking the AI with clever prompts, an attacker made it produce harmful code that the server executed.

What is AI / LLM?

Prompt injection, data exfiltration and tool abuse in features built on language models, and the ordinary bugs around them.

Similar reports

View all

Same bug class and techniques, clearest first.

AI and LLM vulnerabilities

The lesson behind this report.

Prompt injection, data exfiltration and tool abuse in features built on language models, and the ordinary bugs around them.