When Prompts Go Rogue: Analyzing a Prompt Injection Code Execution in Vanna.AI
The Vanna.AI library generates Plotly chart code via an LLM prompt that includes user input, then executes it with Python's exec. An attacker could inject a prompt to make the LLM output arbitrary Python code, leading to remote code execution.
Published on jfrog.com
In the rapidly evolving fields of large language models (LLMs) and machine learning, new frameworks and applications emerge daily, pushing the boundaries of these technologies.
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 library passes user-controlled input into an LLM prompt and then executes the generated Python code with exec without sufficient validation or sandboxing.
Impact
An attacker could execute arbitrary Python code on the server, leading to full remote code execution.
What the attacker needed
Access to the ask function; LLM API key
How it was found
- Call the ask method with a prompt that instructs the LLM to generate a SQL query containing a string payload.
- The generated SQL query includes the payload as a string literal.
- The SQL query is passed into the prompt for generating Plotly code.
- The LLM outputs Python code that includes the payload.
- The generated code is executed via exec, running the payload.
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.
Large language models (LLMs) are AI systems that generate text. Vanna.AI uses an LLM to turn questions into SQL queries and chart code. Because the chart code is generated from user input and then run as Python code, an attacker can trick the LLM into producing malicious code that runs on the server.
What is AI / LLM?
Prompt injection, data exfiltration and tool abuse in features built on language models, and the ordinary bugs around them.