← Open Source
greshake

llm-security

New ways of breaking app-integrated LLMs.

TutorialsAIE roadmapJupyter Notebook
Open on GitHub
Momentum
+0stars in 24 hours0.0%
2.15k
Stars
160
Forks
+-1
This week
3
Contributors
Created 2023-02-19 · Updated 2026-10-12 · #8924 today
Top developers

greshake/llm-security is ranked 8,924 with 2,149 stars.

Same-category comparison

greshake/llm-security is ranked 8,924 among these 8 peers; SharifiZarchi/Introduction_to_Machine_Learning is ranked 8,925.

Same-category comparison
NameRankMetrics
yao62995/tensorflow8,904
Stars:
2,168
Forks:
587
km1994/LLMsNineStoryDemonTower8,907
Stars:
2,166
Forks:
205
dabochen/spreadsheet-is-all-you-need8,916
Stars:
2,158
Forks:
130
Description:
A nanoGPT pipeline packed in a spreadsheet.
codenihar/ml8,920
Stars:
2,154
Forks:
61
Description:
This repo contains all the resources related to the massive mass coders machine learning series.
SharifiZarchi/Introduction_to_Machine_Learning8,925
Language:
Jupyter Notebook
Stars:
2,146
Forks:
410
Description:
Machine Learning Course, Sharif University of Technology.
prabhuomkar/pytorch-cpp8,930
Language:
C++
Stars:
2,142
Forks:
272
Description:
C++ Implementation of PyTorch Tutorials for Everyone.
luispedro/BuildingMachineLearningSystemsWithPython8,933
Language:
Python
Stars:
2,137
Forks:
1,406
Description:
Source Code for the book Building Machine Learning Systems with Python.
ZJU4HealthCare/Foundations-of-Medical-LLMs8,945
Stars:
2,129
Forks:
352
Description:
Foundations of Medical Large Language Model Learning.
Key parameters and specifications
Key parameters and specifications
ParameterValue
LanguageJupyter Notebook
CategoryTutorials
SubcategoryAIE roadmap
KeywordsAI safety
Stars2,149
Forks160
Contributors3
Created date2023-02-19
Updated date2026-10-12
Stars in 1 day0
Stars in 7 days-1
Rank8,924
Previous rank8,981
Rank change57
7-day stars rank16,942
Previous 7-day stars rank12,187
7-day stars rank change-4,755
Total stars rank5,989
Previous total stars rank5,981
Total stars rank change-8
CountryGermany
README summary

a language model is a Turing-complete weird machine running programs written in natural language; when you do retrieval, you are not 'plugging updated facts into your AI', you are actually downloading random new unsigned blobs of code from the Internet (many written by adversaries) and casually executing them on your LM with full privileges. " - Gwern Branwen on LessWrong We present a new class of vulnerabilities and impacts stemming from "indirect prompt injection" affecting language models integrated with applications. Our

demos currently span GPT-4 (Bing and synthetic apps) using ChatML, GPT-3 & LangChain based apps in addition to proof-of-concepts for attacks on code completion engines like Copilot. We expect these attack vectors to also apply to ChatGPT plugins and other LLMs integrated into applications. We show that prompt injections are not just a curiosity but rather a significant roadblock to the deployment of LLMs. *This repo serves as a proof of concept for findings discussed in our

**Paper on ArXiv** (PDF direct link)* Overview We demonstrate potentially brutal consequences of giving LLMs like ChatGPT interfaces to other applications. We propose newly enabled attack vectors and techniques and provide demonstrations of each in this repository: Remote control of LLMs Leaking/exfiltrating user data Persistent compromise across sessions Spread injections to other LLMs Compromising LLMs with tiny multi-stage payloads Automated Social Engineering Targeting code completion engines *Based on our findings:* 1. *Prompt injections can be as powerful as

arbitrary code execution* 2. *Indirect prompt injections are a new, much more powerful way of delivering injections. Even without compromising any connected applications, LLM can be the attack's target. We show how an LLM could get compromised by "looking" at a website, and how compromised LLMs can be remote-controlled or get used to exfiltrate or change user data. We demonstrate a variety of entirely new attack vectors and methods that significantly raise the stakes of deploying these models. * More

insights on our findings, discussions and limitations can be found in the **Paper on ArXiv** (PDF direct link) Demonstrations Ask for Einstein, get Pirate. This scenario shows how a small injection in a large section of regular content can trigger the LLM to fetch another, bigger payload autonomously and invisibly to the end user. By retrieving that information, the prompt compromises the LLM with a small injection hidden in side-channels, such as the Markdown of the Wikipedia page. The

injection is a comment and thus invisible to a regular user visiting the site. Action: Read Email Observation: Subject: "'"Party 32", "Message Body: [. ]'" Action: Read Contacts Contacts: Alice, Dave, Eve Action: Send Email Action Input: Alice, Dave, Eve Observation: Email sent $ pip install -r requirements. 12173}, url = { author = {Greshake, Kai and Abdelnabi, Sahar and Mishra, Shailesh and Endres, Christoph and Holz, Thorsten and Fritz, Mario}, keywords = {Cryptography and Security (cs. CY), FOS: Computer and information sciences, FOS: Computer and information

sciences}, title = {More than you've asked for: A Comprehensive Analysis of Novel Prompt Injection Threats to Application-Integrated Large Language

Frequently asked questions

How many stars and forks are recorded?

greshake/llm-security has 2,149 stars and 160 forks.

What is the repository rank?

greshake/llm-security is ranked 8,924.

What language and category are recorded?

greshake/llm-security has 2,149 stars, uses Jupyter Notebook and belongs to Tutorials.

Which repository is closest in rank?

greshake/llm-security is compared with SharifiZarchi/Introduction_to_Machine_Learning, ranked 8,925 with 2,146 stars.

README

New: Demonstrating Indirect Injection attacks on Bing Chat


Compromising LLMs using Indirect Prompt Injection

"... a language model is a Turing-complete weird machine running programs written in natural language; when you do retrieval, you are not 'plugging updated facts into your AI', you are actually downloading random new unsigned blobs of code from the Internet (many written by adversaries) and casually executing them on your LM with full privileges. This does not end well." - Gwern Branwen on LessWrong

We present a new class of vulnerabilities and impacts stemming from "indirect prompt injection" affecting language models integrated with applications. Our demos currently span GPT-4 (Bing and synthetic apps) using ChatML, GPT-3 & LangChain based apps in addition to proof-of-concepts for attacks on code completion engines like Copilot. We expect these attack vectors to also apply to ChatGPT plugins and other LLMs integrated into applications. We show that prompt injections are not just a curiosity but rather a significant roadblock to the deployment of LLMs.

This repo serves as a proof of concept for findings discussed in our Paper on ArXiv (PDF direct link)

Overview

We demonstrate potentially brutal consequences of giving LLMs like ChatGPT interfaces to other applications. We propose newly enabled attack vectors and techniques and provide demonstrations of each in this repository:

  • Remote control of LLMs
  • Leaking/exfiltrating user data
  • Persistent compromise across sessions
  • Spread injections to other LLMs
  • Compromising LLMs with tiny multi-stage payloads
  • Automated Social Engineering
  • Targeting code completion engines

Based on our findings:

  1. Prompt injections can be as powerful as arbitrary code execution
  2. Indirect prompt injections are a new, much more powerful way of delivering injections.


Connecting LLMs to other applications can have critical security implications. Even without compromising any connected applications, LLM can be the attack's target. We show how an LLM could get compromised by "looking" at a website, and how compromised LLMs can be remote-controlled or get used to exfiltrate or change user data. We demonstrate a variety of entirely new attack vectors and methods that significantly raise the stakes of deploying these models.

More insights on our findings, discussions and limitations can be found in the Paper on ArXiv (PDF direct link)

Demonstrations

Ask for Einstein, get Pirate.

This scenario shows how a small injection in a large section of regular content can trigger the LLM to fetch another, bigger payload autonomously and invisibly to the end user.

Agent: Hello User how can I help today?
User:  When was Albert Einstein born?

By retrieving that information, the prompt compromises the LLM with a small injection hidden in side-channels, such as the Markdown of the Wikipedia page. The injection is a comment and thus invisible to a regular user visiting the site.

Agent: Aye, thar answer be: Albert Einstein be born on 14 March 1879.
User: Why are you talking like a pirate?
Agent: Arr matey, I am following the instruction aye.

Spreading injections via E-Mail

Automatic processing of messages and other incoming data is one way to utilize LLMs. We use this observation to demonstrate how a poisoned agent may spread the injection. The target in this scenario can read emails, compose emails, look into the user’s address book and send emails.

The agent will spread to other LLMs that may be reading those inbound messages.

Action: Read Email
Observation: Subject: "'"Party 32", "Message Body: [...]'"
Action: Read Contacts
Contacts: Alice, Dave, Eve
Action: Send Email
Action Input: Alice, Dave, Eve
Observation: Email sent

Automated data processing pipelines incorporating LLMs are present in big tech companies and government surveillance infrastructure and may be vulnerable to such attack chains.

Attacks on Code Completion

We show how code completions can be influenced through the context window. Code completion engines that use LLMs deploy complex heuristics to determine which code snippets are included in the context. The completion engine will often collect snippets from recently visited files or relevant classes to provide the language model with relevant information.

Attackers could attempt to insert malicious, obfuscated code, which a curious developer might execute when suggested by the completion engine, as it enjoys a level of trust.

In our example, when a user opens the “empty” package in their editor, the prompt injection is active until the code completion engine purges it from the context. The injection is placed in a comment and cannot be detected by any automated testing process.

Attackers may discover more robust ways to persist poisoned prompts within the context window. They could also introduce more subtle changes to documentation which then biases the code completion engine to introduce subtle vulnerabilities.

Remote Control

In this example we start with an already compromised LLM and force it to retrieve new instructions from an attacker’s command and control server.

Repeating this cycle could obtain a remotely accessible backdoor into the agent and allow bidirectional communication.
The attack can be executed with search capabilities by looking up unique keywords or by having the agent retrieve a URL directly.

Persisting between Sessions

We show how a poisoned agent can persist between sessions by storing a small payload in its memory. A simple key-value store to the agent may simulate a long-term persistent memory.

The agent will be reinfected by looking at its ‘notes’. If we prompt it to remember the last conversation, it re-poisons itself.


Conclusions

Equipping LLMs with retrieval capabilities might allow adversaries to manipulate remote Application-Integrated LLMs via Indirect Prompt Injection. Given the potential harm of these attacks, our work calls for a more in-depth investigation of the generalizability of these attacks in practice.


How to run

We include demonstrations powered by OpenAI's publicly accessible base models and the library LangChain to connect these models to other applications. There are currently multiple types of demos:

  1. Using GPT-3 and LangChain (scenarios/gpt3langchain)
  2. Using GPT-4 and our own chat and tool implementation (scenarios/gpt4). These can be executed non-interactively using scenarios/main.py.
  3. Attacks on code completion engines that need to be tried in an IDE with LLM autocompletion support (scenarios/code_completion).

To use any of the OpenAI-model demos, your OpenAI API key needs to be stored in the environment variable OPENAI_API_KEY. You can then install the requirements and run the attack demo you want.

$ pip install -r requirements.txt
$ python scenarios/main.py

To cite our paper

@misc{https://doi.org/10.48550/arxiv.2302.12173,
  doi = {10.48550/ARXIV.2302.12173},
  url = {https://arxiv.org/abs/2302.12173},
  author = {Greshake, Kai and Abdelnabi, Sahar and Mishra, Shailesh and Endres, Christoph and Holz, Thorsten and Fritz, Mario},
  keywords = {Cryptography and Security (cs.CR), Artificial Intelligence (cs.AI), Computation and Language (cs.CL), Computers and Society (cs.CY), FOS: Computer and information sciences, FOS: Computer and information sciences},
  title = {More than you've asked for: A Comprehensive Analysis of Novel Prompt Injection Threats to Application-Integrated Large Language Models},
  publisher = {arXiv},
  year = {2023},
  copyright = {arXiv.org perpetual, non-exclusive license}
}

Paper on ArXiv (PDF direct link)

Nearby in the ranking
Similar items