[Paper Review] Prompt Stealing Attacks Against Large Language Models
The paper proposes prompt stealing attacks against LLMs using a parameter extractor and a prompt reconstructor to infer and reverse original prompts from generated answers, with experiments showing strong performance on ChatGPT and LLaMA.
The increasing reliance on large language models (LLMs) such as ChatGPT in various fields emphasizes the importance of ``prompt engineering,'' a technology to improve the quality of model outputs. With companies investing significantly in expert prompt engineers and educational resources rising to meet market demand, designing high-quality prompts has become an intriguing challenge. In this paper, we propose a novel attack against LLMs, named prompt stealing attacks. Our proposed prompt stealing attack aims to steal these well-designed prompts based on the generated answers. The prompt stealing attack contains two primary modules: the parameter extractor and the prompt reconstruction. The goal of the parameter extractor is to figure out the properties of the original prompts. We first observe that most prompts fall into one of three categories: direct prompt, role-based prompt, and in-context prompt. Our parameter extractor first tries to distinguish the type of prompts based on the generated answers. Then, it can further predict which role or how many contexts are used based on the types of prompts. Following the parameter extractor, the prompt reconstructor can be used to reconstruct the original prompts based on the generated answers and the extracted features. The final goal of the prompt reconstructor is to generate the reversed prompts, which are similar to the original prompts. Our experimental results show the remarkable performance of our proposed attacks. Our proposed attacks add a new dimension to the study of prompt engineering and call for more attention to the security issues on LLMs.
Motivation & Objective
- Highlight the economic and security implications of prompt engineering in LLM use.
- Propose a two-module framework (parameter extractor and prompt reconstructor) to reverse engineer original prompts.
- Evaluate attack effectiveness on multiple datasets and models and compare against baselines.
- Discuss defense strategies and their limitations while underscoring security considerations for LLM systems.
Proposed method
- Classify prompt types (direct, role-based, in-context) using a primary classifier and two sub-classifiers.
- Train classifiers on generated answers to predict prompt category and, for role-based prompts, the specific role or, for in-context prompts, the number of contexts.
- Use ChatGPT to generate reversed prompts based on extracted parameters and contextual information to reconstruct prompts.
- Evaluate prompt similarity (PS) and answer similarity (AS) using sentence-transformer embeddings.
- Assess attacks on two datasets (RetrievalQA and Alpaca-GPT4) and two LLMs (ChatGPT and LLaMA).
- Propose two defenses to reduce attack efficacy and measure their impact.

Experimental results
Research questions
- RQ1Can the type of original prompt be accurately inferred from the generated answers?
- RQ2How well can the original prompts be reconstructed once the type and parameters are inferred?
- RQ3Do defenses meaningfully reduce the effectiveness of prompt stealing attacks, and are they robust across models/datasets?
Key findings
- The primary classifier achieves 0.833 accuracy on RetrievalQA with ChatGPT, and 0.811 on Alpaca-GPT4.
- LLaMA-based primary classifier achieves 0.884 accuracy on RetrievalQA and 0.855 on Alpaca-GPT4.
- Role-based sub-classifier reaches 0.732 accuracy on RetrievalQA with ChatGPT (15-class task).
- In-context sub-classifier reaches 0.614 accuracy (4-class) for context number prediction.
- Prompt reconstruction achieves high prompt similarity (PS) and answer similarity (AS); for direct prompts with ChatGPT, PS=0.832 and AS=0.768.
- Incorporating parameter-extractor guidance improves reconstruction (e.g., PS=0.803, AS=0.703 for role-based prompts with RetrievalQA).
- Baseline (no parameter extraction) performs significantly worse, showing the necessity of hierarchical prediction.
- Defense strategies reduce similarity metrics but do not eliminate attack effectiveness, indicating robustness.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.