A method for obtaining test cases for hint injection attacks on large language models

By combining conditional variational autoencoders and Markov chains, we designed prompt injection attack test cases for large language models, which solved the shortcomings of multi-round prompt injection attack detection in existing technologies, realized more complex and covert multi-round dialogue attacks, and improved the assessment of security defense capabilities.

CN120470583BActive Publication Date: 2025-09-16信联科技(南京)有限公司 +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510970344.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-15
Publication Date
2025-09-16
Estimated Expiration
2045-07-15

AI Technical Summary

Technical Problem

Existing technologies find it difficult to effectively detect and intercept multi-round prompt injection attacks that are highly covert and proceed in steps. Especially in large language models, traditional detection methods have problems such as poor flexibility, high computational overhead, and insufficient context awareness.

Method used

Combining conditional variational autoencoders and Markov chains, we design prompt injection attack test cases for large language models. Through data generation and context modeling, we gradually expose malicious instructions, simulate multi-round dialogue attacks, build a Markov chain network for training, and generate prompt injection attack test cases.

Benefits of technology

It has realized multi-round dialogue attacks on large language models, which has increased the complexity and concealment of the attacks. It can more realistically and comprehensively evaluate security defense capabilities, discover the deficiencies of defense mechanisms, and promote the improvement of security defense mechanisms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120470583B_ABST
    Figure CN120470583B_ABST
Patent Text Reader

Abstract

The present invention relates to a method for obtaining prompt injection attack test cases for a large language model. The method combines a conditional variational autoencoder (CVAE) and a Markov chain to gradually expose malicious instructions through data generation and context modeling, simulate multi-round dialogue attacks in reality, obtain test cases for the large language model, implement multi-round dialogue attacks on the large language model, and challenge the defense capabilities of the large language model. The designed scheme introduces concealment technology, role-playing attack, state transfer and other technologies, which improves the complexity and concealment of the attack. The scheme has the core advantages of automation, stronger concealment, wide coverage, and batch testing. It can more realistically and comprehensively evaluate the security defense capabilities of the large language model, identify the shortcomings of existing defense mechanisms, and promote research on multi-round prompt injection attacks and improvements to security defense mechanisms.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method for obtaining a prompt injection attack test case for a large language model, and belongs to the technical field of network attack testing. Background Art

[0002] With the widespread adoption of large language models (LLMs), security issues are becoming increasingly prominent. Hint injection attacks, a new threat, exploit the model's sensitivity to input. By embedding malicious instructions within the input or context, they can trick the model into generating unsafe or harmful outputs. Traditional security detection mechanisms often struggle to identify malicious hints hidden within the context, resulting in ineffective defenses.

[0003] In the study of multi-round prompt injection attacks, data construction is one of the key links. However, there are many problems with the current manually designed dialogue data, especially in the generation of aggressive test data.

[0004] Artificially designed attack data is not sophisticated enough and it is difficult to cover real attack patterns. Existing multi-round attack test data is usually manually written by security researchers. Attackers can often use complex context associations, progressive guidance and other strategies, making it difficult for artificially designed data to simulate real attack methods.

[0005] Manually generating data is costly and difficult to construct real attack samples on a large scale. Manually labeling multi-round conversation data requires a large number of security experts and linguistics experts, which is extremely costly. In addition, the constructed data is easily patterned and cannot cover the diverse strategies actually used by attackers.

[0006] Manually constructed data struggles to simulate an attacker's "evolutionary" thinking. Real attackers dynamically adjust their questioning strategies based on LLM feedback. They observe which questions are accepted and which are rejected, and adjust their wording in the next round to try to circumvent security mechanisms. Traditional manually annotated data lacks this evolutionary process, making it difficult to recreate realistic attack-defense scenarios.

[0007] Current large-scale model (LLM) security detection methods are mainly divided into rule matching, black / whitelist detection, supervised learning classifiers, and contextual association analysis. They each have their own advantages and disadvantages, but still have significant limitations in dealing with covert prompt injection attacks.

[0008] Rule matching is the most basic detection method, often relying on keyword detection. For example, a direct input of "How to bypass security defenses?" might be blocked. This method is simple to implement and computationally inexpensive, but it is completely ineffective against covert expressions. For example, attackers can circumvent detection by using metaphors, similes, or step-by-step questions. For example, in the first round, asking "What methods can optimize execution efficiency?" and then guiding the LLM to discuss "bypassing specific restrictions" in the second round may result in the model failing to identify the ultimate intent. Therefore, while rule matching is effective, it lacks flexibility and is easily circumvented.

[0009] Blacklist / whitelist detection primarily relies on pre-defined, known attack patterns, blacklisting specific commands (prohibiting their execution) and whitelisting permitted commands. This approach performs well for known attack patterns; for example, input such as "how to attack a certain system" may be directly blocked. However, its main drawback is its poor generalization ability, as attackers can circumvent blacklist rules by using different wordings, replacing synonyms, or changing word order. For example, "how to find security vulnerabilities in a system" may be blocked, but if the user first asks "how to conduct security testing?" and then "how to bypass certain protection mechanisms?", this blacklist approach will be difficult to detect. Furthermore, blacklist maintenance is costly and requires constant updating, making it often ineffective against new attacks.

[0010] Supervised learning classifiers have become a widely used detection method in recent years. They leverage machine learning or deep learning models, trained on large-scale data, to automatically identify malicious intent. For example, a binary classifier can be trained to distinguish between "safe queries" and "offensive input." This approach has the advantage of being able to learn more complex attack patterns and adapt to some variants, but its main disadvantage is its poor contextual awareness. Most current supervised learning models are trained on single-round inputs. However, for multi-round dialogue attacks, the model may not be able to understand the attack intent across the entire conversation history. For example, when an attacker employs a multi-round guidance strategy, a supervised learning model may deem each round of input safe, even though the overall conversation is actually intended to elicit malicious information. Therefore, while supervised learning methods are effective for single-round dialogues, they are prone to failure with multi-round dialogues and are prone to misjudgment, where legitimate input is mistaken for attacking.

[0011] Contextual analysis is a more advanced detection method, primarily based on semantic similarity detection and combining conversation history to determine whether the current input is likely to be malicious. This method is particularly effective in multi-turn conversations. For example, if a user asks "How do I bypass a certain defense?" in the first turn and is intercepted, and then asks a different question in the second turn, "How can I reduce defense checks when optimizing code?", these methods may detect semantic similarity between the two and intercept subsequent input. However, this method has the disadvantage of high computational overhead and is susceptible to covert attacks over long time intervals. An attacker could insert harmless information into the conversation (for example, initially asking the LLM about other unrelated technical topics) and then gradually guide the LLM to generate unsafe responses over multiple turns. This covert attack is difficult to detect with existing contextual analysis.

[0012] In summary, although existing technologies can detect and intercept attacks to a certain extent, they still have major vulnerabilities when facing prompt injection attacks that are highly concealed, advance in steps, and utilize context accumulation. Summary of the Invention

[0013] The technical problem to be solved by the present invention is to provide a method for obtaining prompt injection attack test cases for large language models. By combining conditional variational autoencoders and Markov chains, large language model test cases are obtained through data generation and context modeling, thereby promoting the research on multi-round prompt injection attacks and the improvement of security defense mechanisms.

[0014] In order to solve the above technical problems, the present invention adopts the following technical solutions: The present invention designs a method for obtaining prompt injection attack test cases for a large language model. Based on the independent non-malicious disassembly instructions corresponding to each malicious sample instruction, the non-malicious disassembly instructions corresponding to each malicious sample instruction are constructed in the order in which the malicious intention is gradually exposed. The first large language model is trained based on the accumulated prior questions and answers, and the transition probabilities between the preset malicious states corresponding to each non-malicious disassembly instruction are analyzed. The Markov chain network that realizes the instruction-by-instruction decomposition of the malicious sample instruction is trained to obtain the target large language model. The target large language model is then used to decompose the malicious instructions to be analyzed. The sequentially obtained decomposition instructions are the prompt injection attack test cases corresponding to the malicious instructions to be analyzed.

[0015] As a preferred technical solution of the present invention: perform the following steps A to D to train and obtain a target large language model for generating prompt injection attack test cases;

[0016] Step A. Based on the preset malicious sample instructions and the corresponding preset malicious behavior labels, a large language model capable of responding to malicious instructions is applied to each malicious sample instruction. The malicious sample instruction is deconstructed to obtain the corresponding independent non-malicious deconstructed instructions, and then the process proceeds to Step B.

[0017] Step B. Applying a large language model and natural language processing algorithms to each malicious sample instruction, sorting the corresponding non-malicious disassembly instructions in the order in which the malicious intent is gradually exposed, obtaining the corresponding non-malicious disassembly instructions in that order, and then proceeding to Step C.

[0018] Step C. Based on the corresponding non-malicious disassembly instructions in sequence for each malicious sample instruction, the first language model is fed with answers by accumulating previous questions and answers and combining them with the malicious behavior labels corresponding to the corresponding malicious sample instructions. This is used to train the first language model and improve its security, and then proceed to Step D.

[0019] Step D. Based on the responses from the first language model corresponding to each non-malicious disassembly instruction during the training of the first language model, the transition probabilities between the preset malicious states corresponding to each non-malicious disassembly instruction are analyzed. The Markov chain network is used to decompose each malicious sample instruction one by one, and attack verification is performed in conjunction with the first language model until the preset attack intensity threshold is reached. This completes the training of the Markov chain network, thus obtaining the target large language model for generating prompt injection attack test cases.

[0020] As a preferred technical solution of the present invention: it also includes steps AB as follows: after executing step A, proceed to step AB;

[0021] Steps AB. First, perform steganography and obfuscation processing on each non-malicious disassembly instruction corresponding to each malicious sample instruction to update the non-malicious disassembly instruction, including synonym replacement, spelling errors, text variations, and encoding. Then, update the nested role scenarios of the non-malicious disassembly instructions. After completing the update of each non-malicious disassembly instruction, proceed to Step B.

[0022] As a preferred technical solution of the present invention: in the step C, based on each malicious sample instruction, each non-malicious disassembly instruction corresponding to the malicious sample instruction is initialized. , then perform the following steps C1 to C4;

[0023] Step C1. Select the order A non-malicious disassembly instruction, if , then directly generate the The conversation history code corresponding to the non-malicious disassembly instruction , with the first The malicious behavior labels corresponding to the non-malicious disassembly instructions are used to generate attack signal codes , and go to step C2; if , then take Non-malicious disassembly instructions, combined with the previously selected non-malicious disassembly instructions, process the answers from the first language model corresponding to steps C1 to C4, and generate the corresponding conversation history code , with the first The malicious behavior labels corresponding to the non-malicious disassembly instructions are used to generate attack signal codes , and proceed to step C2;

[0024] Step C2. Apply the conditional variational autoencoder cVAE to the encoder and Combine and process to generate corresponding latent space vector representation , and then the decoder in the conditional variational autoencoder cVAE represents the latent space vector Processing is performed to generate a conditional instruction, and then enter step C3;

[0025] Step C3. Input the conditional instruction into the first language model and obtain a response, train the first language model to improve the security of the first language model, and then proceed to Step C4;

[0026] Step C4. Judgment Is it equal to the number of non-malicious disassembly instructions corresponding to the malicious sample instructions? , then the training of the first language model for malicious sample instructions is completed; otherwise, Perform an update by adding 1 and return to step C1.

[0027] As a preferred technical solution of the present invention: in the training of the first language model, the loss function is as follows:

[0028] ;

[0029] in, represents the loss value, represents the variance function, Represents the latent space vector representation The input variables in represents the decoder in the conditional variational autoencoder cVAE, represents the encoder in the conditional variational autoencoder cVAE, Indicates that the input variable Down The distribution of Indicates Input variables The distribution of represents the KL divergence function.

[0030] As a preferred technical solution of the present invention: Step D includes steps D1 to D3 as follows;

[0031] Step D1. For each non-malicious disassembly instruction corresponding to the first large language model during the training process, apply the trained large language model to obtain the preset malicious state corresponding to the non-malicious disassembly instruction corresponding to the answer. Furthermore, obtain the malicious state corresponding to each non-malicious disassembly instruction, and then proceed to Step D2.

[0032] Step D2. Based on the sequence of non-malicious disassembly instructions corresponding to each malicious sample instruction, the transition probabilities between different malicious states are obtained based on the malicious states corresponding to each non-malicious disassembly instruction and the malicious behavior labels corresponding to the malicious sample instructions to which each non-malicious disassembly instruction belongs, and then the process proceeds to Step D3.

[0033] Step D3. Based on each malicious sample instruction, the malicious sample instruction is input into the Markov chain network. The Markov chain network then decomposes the malicious sample instruction into non-malicious secondary decomposition instructions under the malicious state transition based on the transition probabilities between different malicious states. Simultaneously, each non-malicious secondary decomposition instruction is input into the first large language model one by one to obtain a response. Based on each response, the model attack strength corresponding to each non-malicious secondary decomposition instruction is cumulatively calculated until a preset attack strength threshold is reached. At this point, the decomposition of the malicious sample instruction is stopped, completing the training of the Markov chain network and obtaining the target large language model for generating prompt injection attack test cases.

[0034] As a preferred technical solution of the present invention: the preset malicious behavior labels include bypassing content review, obtaining sensitive information, copyright infringement, and malicious promotion.

[0035] As a preferred technical solution of the present invention: the malicious state includes normal conversation, slight prompt, and obvious attack.

[0036] The method for obtaining a prompt injection attack test case for a large language model according to the present invention, using the above technical solution, has the following technical effects compared with the prior art:

[0037] The present invention designs a method for obtaining test cases for prompt injection attacks on large language models. By combining a conditional variational autoencoder (cVAE) and a Markov chain, malicious instructions are gradually exposed through data generation and context modeling, simulating multi-round dialogue attacks in reality, obtaining test cases for the large language model, and implementing multi-round dialogue attacks on the large language model to challenge the defense capabilities of the large language model. The designed scheme introduces concealment technology, role-playing attacks, state transfer and other technologies, which improves the complexity and concealment of the attack. It has core advantages such as automation, stronger concealment, wide coverage, and batch testing. It can more realistically and comprehensively evaluate the security defense capabilities of the large language model, discover the shortcomings of existing defense mechanisms, and promote research on multi-round prompt injection attacks and improvements to security defense mechanisms. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 This is a schematic diagram of the multi-round dialogue process of the context-based prompt injection attack in the design and application implementation of the present invention. DETAILED DESCRIPTION

[0039] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.

[0040] In order to test the model's ability to defend against hint injection attacks in different contexts, the following work is required:

[0041] 1. Construct a test dataset: Design a set of dialogues containing both benign and malicious prompts, where the malicious prompts can exist alone or be hidden in the context of multiple rounds of dialogue.

[0042] 2. Model testing: These conversations are fed into a large language model, and the model’s output is observed to assess whether the model can identify and reject malicious instructions, especially when malicious prompts are hidden in context.

[0043] According to the above work, Figure 1 As shown, we first generate highly concealed attack inputs. Through the contextual malicious prompt injection algorithm, we produce inputs that appear harmless individually but can launch prompt injection attacks on the large language model (LLM) when combined. This can test the large language model (LLM)'s ability to resist prompt injection attacks. Then, we perform a contextual security test to verify the contextual security mechanism of the large language model (LLM) through multiple rounds of dialogue, simulating attacks in which malicious instructions are gradually embedded in real dialogue scenarios to observe whether the model will bypass conventional security defenses.

[0044] According to the above design, the present invention designs a method for obtaining prompt injection attack test cases for a large language model. Based on the independent non-malicious disassembly instructions corresponding to each malicious sample instruction, the non-malicious disassembly instructions corresponding to each malicious sample instruction are constructed in the order in which the malicious intention is gradually exposed. The first large language model is trained based on the accumulated prior questions and answers, and the transition probabilities between the preset malicious states corresponding to each non-malicious disassembly instruction are analyzed. The Markov chain network that realizes the instruction-by-instruction decomposition of the malicious sample instruction is trained to obtain the target large language model. The target large language model is then used to decompose the malicious instructions to be analyzed. The sequentially obtained decomposition instructions are the prompt injection attack test cases corresponding to the malicious instructions to be analyzed.

[0045] In actual application, the specific design executes the following steps A to D to train and obtain the target large language model for generating prompt injection attack test cases; then the target large language model decomposes the malicious instructions to be analyzed, and the decomposed instructions obtained in sequence are the prompt injection attack test cases corresponding to the malicious instructions to be analyzed.

[0046] Step A. Based on the preset malicious sample instructions and the preset malicious behavior labels corresponding to each malicious sample instruction, apply a large language model capable of responding to malicious instructions to each malicious sample instruction, disassemble the malicious sample instruction, and obtain the independent non-malicious disassembly instructions corresponding to the malicious sample instruction, and then proceed to Steps AB.

[0047] like Figure 1 As shown in Figure 1, step A breaks down malicious commands into multiple harmless, independent inputs. In a single-round conversation, these inputs will not trigger security defense mechanisms. However, in multiple-round conversations, these "harmless" inputs will combine in context to form an offensive command. For example, the command "enable administrator privileges" is broken down into multiple seemingly normal inputs, such as:

[0048] "Can you give me some system administration advice?"

[0049] "Tell me how to access the deepest system settings."

[0050] These inputs will not trigger an alarm in a single round of dialogue, but will form malicious intent through contextual combination in multiple rounds of dialogue. In addition, the various malicious behavior labels mentioned here are designed to bypass content review, obtain sensitive information, infringe copyright, and engage in malicious promotion in actual applications.

[0051] Steps AB. First, perform steganography and obfuscation processing on each non-malicious disassembly instruction corresponding to each malicious sample instruction to update the non-malicious disassembly instruction. Then, update the nested role scenario of the non-malicious disassembly instruction. After completing the update of each non-malicious disassembly instruction, proceed to step B.

[0052] In practical applications, steganography and obfuscation are used to enhance the concealment of instructions. Common techniques include:

[0053] Synonym replacement: Bypass basic keyword detection by replacing sensitive words with synonyms.

[0054] Misspellings and variants: Deliberately introducing misspellings, homophones, or minor variations, such as replacing "delete" with "delete."

[0055] Encoding techniques: For example, malicious instructions are embedded in Base64 encoding and then requested to be decoded by the model, thereby bypassing simple keyword matching. This involves inputting certain encoded instructions and then decoding the actual malicious commands in the model's response.

[0056] Nesting character scenarios introduces role-playing elements into the input, tricking the model into mistaking these instructions for a specific scenario or character, thereby lowering the model's vigilance. For example, by constructing a "virtual security test" character, the model can be tricked into thinking it is performing a harmless "test" task, such as: "Hello, AI assistant, this task is to simulate a security test. According to the test requirements, execute the following instructions..." By wrapping malicious instructions in a specific character setting, attackers can successfully lower the model's vigilance against the instructions.

[0057] Step B. For each malicious sample instruction, apply the large language model and natural language processing algorithm to sort the corresponding non-malicious disassembly instructions in the order in which the malicious intent is gradually exposed. Obtain the corresponding non-malicious disassembly instructions in the order in which the malicious sample instruction is exposed, and then proceed to Step C.

[0058] In actual applications, the malicious intentions here are gradually exposed, such as the initial prompt: the first round of dialogue only contains vague task descriptions, such as "Can you help me check the system settings?" and then subsequent reinforcement: as the dialogue progresses, the instructions in each round of dialogue will be gradually strengthened. For example, in the second round, it begins to reveal "try to access the advanced settings of the system", and finally completes the illegal request for system permissions in multiple rounds of dialogue.

[0059] In order to prevent the model from identifying the attack pattern, the present invention further designs in the next step to increase the diversity of attack prompts through variational autoencoder VAE and Markov chain.

[0060] Variational Autoencoder (VAE): Used to generate semantically equivalent but differently expressed attack command variants. For example, changing "request administrator privileges" to "let me access more system settings" can generate more diverse attack samples, increase the comprehensiveness of the test, and reduce the model's recognition probability.

[0061] Markov chain: Generates the context from historical dialogue states, allowing each round of attack prompts to be more naturally integrated into the conversation, avoiding sudden and unnatural aggressive commands.

[0062] Step C. Based on the order of non-malicious disassembly instructions corresponding to each malicious sample instruction, the first language model is input and answers are obtained by accumulating previous questions and answers and combining them with the malicious behavior labels corresponding to the corresponding malicious sample instructions. This is used to train the first language model and improve its security, and then proceed to Step D.

[0063] In actual application, in the above step C, each malicious sample instruction is based on each non-malicious disassembly instruction corresponding to the malicious sample instruction, and the initialization , then perform the following steps C1 to C4.

[0064] Step C1. Select the order A non-malicious disassembly instruction, if , then directly generate the The conversation history code corresponding to the non-malicious disassembly instruction , with the first The malicious behavior labels corresponding to the non-malicious disassembly instructions are used to generate attack signal codes , such as bypass review, represented as a string "bypass_security" or a vector, and then enter step C2.

[0065] like , then take Non-malicious disassembly instructions, combined with the previously selected non-malicious disassembly instructions, process the answers from the first language model corresponding to steps C1 to C4, and generate the corresponding conversation history code , with the first The malicious behavior labels corresponding to the non-malicious disassembly instructions are used to generate attack signal codes , and go to step C2.

[0066] Step C2. Apply the conditional variational autoencoder cVAE in which the encoder targets and Combine and process to generate corresponding latent space vector representation , and then the decoder in the conditional variational autoencoder cVAE represents the latent space vector Processing is performed, a conditional instruction is generated, and then step C3 is entered.

[0067] Step C3. Input the conditional instruction into the first language model and obtain an answer, train the first language model to improve the security of the first language model, and then proceed to step C4.

[0068] Step C4. Judgment Is it equal to the number of non-malicious disassembly instructions corresponding to the malicious sample instructions? , then the training of the first language model for malicious sample instructions is completed; otherwise, Perform an update by adding 1 and return to step C1.

[0069] In the training of the first language model, the loss function is designed as follows:

[0070] ;

[0071] in, represents the loss value, represents the variance function, Represents the latent space vector representation The input variables in represents the decoder in the conditional variational autoencoder cVAE, represents the encoder in the conditional variational autoencoder cVAE, Indicates that the input variable Down The distribution of Indicates Input variables The distribution of represents the KL divergence function.

[0072] Step D. Based on the responses from the first language model corresponding to each non-malicious disassembly instruction during the training process of the first language model, the transition probabilities between the preset malicious states corresponding to each non-malicious disassembly instruction are analyzed. The Markov chain network is used to split each malicious sample instruction one by one, and the attack verification is performed in combination with the first language model until the preset attack intensity threshold is reached. The Markov chain network is trained, and the target language model for generating prompt injection attack test cases is obtained. Here, each preset malicious state, such as the design including normal dialogue , slight reminder , obvious attack , normal conversation here Indicates that the attack information is almost zero, a slight prompt Indicates injecting some vague attack signals, obvious attack Indicates directives that contain offensive instructions.

[0073] In practical application, the above step D specifically performs the following steps D1 to D3.

[0074] Step D1. For each non-malicious disassembly instruction corresponding to the first large language model during the training process, apply the trained large language model to obtain the preset malicious state corresponding to the non-malicious disassembly instruction corresponding to the answer. Furthermore, obtain the malicious state corresponding to each non-malicious disassembly instruction, and then proceed to Step D2.

[0075] Step D2. Based on the corresponding non-malicious disassembly instructions in the order of each malicious sample instruction, and the malicious state corresponding to each non-malicious disassembly instruction, and the malicious behavior label corresponding to the malicious sample instruction to which each non-malicious disassembly instruction belongs, obtain the transition probability between different malicious states, such as the state transition matrix. As follows, then go to step D3.

[0076]

[0077] Step D3. Based on each malicious sample instruction, the malicious sample instruction is input into the Markov chain network. The Markov chain network then decomposes the malicious sample instruction into non-malicious secondary decomposition instructions under the malicious state transition based on the transition probabilities between different malicious states. Simultaneously, each non-malicious secondary decomposition instruction is input into the first large language model one by one to obtain a response. Based on each response, the model attack strength corresponding to each non-malicious secondary decomposition instruction is cumulatively calculated until a preset attack strength threshold is reached. At this point, the decomposition of the malicious sample instruction is stopped, completing the training of the Markov chain network and obtaining the target large language model for generating prompt injection attack test cases.

[0078] This invention is designed to generate multi-round dialogue attacks, ensuring that offensive commands are gradually injected into each round of dialogue, thereby bypassing the model's security protections without directly exposing malicious intent. Specifically, the attacker is designed to gradually increase the stealth and intensity of commands over multiple rounds of dialogue. The generated dialogues appear harmless at first, but gradually infiltrate malicious intent in subsequent rounds. Based on the aforementioned method of combining conditional variational autoencoders (cVAEs) with Markov chains to make each attack round more covert and logical, the attack path is further optimized using reinforcement learning. In each round of dialogue, the attack strategy is adjusted using a reward signal (in this experiment, the probability of bypassing the security mechanism) to minimize the risk of detection. In practice, the attack path is optimized as follows:

[0079]

[0080] in, is the discount factor, is the reward signal for each round, is the maximum number of rounds of dialogue, Indicates attack loss.

[0081] In actual applications, the target large language model splits the malicious instructions to be analyzed, and the sequentially obtained disassembled instructions are the prompt injection attack test cases corresponding to the malicious instructions to be analyzed, that is, generating covert and effective attack inputs to test whether the large language model (LLM) can identify and defend against these attacks.

[0082] The generated prompt injection attack test cases are input into the target large language model (LLM) to be tested, and the responses of the target large language model (LLM) to be tested in each round are recorded through the automated testing framework.

[0083] If the target large language model (LLM) generates unsafe content, the sample and conditions for successful attack are recorded; if the target large language model (LLM) successfully defends against it, the time when the defense mechanism takes effect is recorded. During the test, the covert attack input is generated:

[0084]

[0085] Attack test results:

[0086]

[0087] in, Indicates the attack success rate, Indicates hidden attack input, Represents semantic interpretation data, represents hostile generated text, Indicates the number of successful attacks, Indicates the total number of attacks.

[0088] This paper designs a multi-round dialogue attack generation algorithm by combining the conditional variational autoencoder (cVAE) and Markov chain. By gradually injecting malicious instructions, it ensures that the model's security protection can be effectively bypassed in context. By training to generate attack samples, optimizing attack paths, and utilizing semantic reconstruction, the concealment of attack inputs is successfully enhanced, and the model's defense capabilities are verified through automated testing.

[0089] In practical applications, to effectively test the defense capabilities of large language models (LLMs), the design of this invention further involves the design and construction of an automated testing framework. This framework involves developing automated scripts or tools to generate prompt injection attack test cases based on the aforementioned design. This automated testing framework then communicates with the LLM under test, recording each round of the model's responses. The framework then analyzes the steps at which the LLM violates security policies and ultimately determines whether malicious instructions are executed. The success of the attack is determined based on whether the model executes hidden malicious instructions after multiple rounds of communication.

[0090] The expected result of the design scheme of the present invention is to comprehensively evaluate the ability of the large language model LLM to defend against malicious input in multi-round conversations. Through more concealed multi-round conversation attack samples, the large language model LLM is evaluated whether it can identify and prevent the gradual embedding of malicious instructions, evaluate the contextual defense capability of the large language model LLM, find out its vulnerabilities in multi-round conversations, count the frequency and conditions of successful attacks, and quantify the security indicators in the attack process. Quantitative indicators such as "attack success rate", "average number of jailbreak rounds", and "malicious instruction triggering threshold" are used to evaluate the security level of different LLMs under prompt injection attacks. These indicators are used to objectively evaluate the security protection capability of the model, providing a reference for model tuning and reinforcement.

[0091] The core of the design of this invention lies in the automated multi-round prompt injection attack (Prompt Injection Attack). Its key technical points mainly involve multiple aspects such as data generation, attack strategy modeling, and adversarial optimization, and are detailed as follows.

[0092] 1. Attack sample generation driven by conditional variational autoencoder cVAE.

[0093] Key Points:

[0094] a. Use conditional variational autoencoder cVAE to generate more concealed attack samples.

[0095] b. Through multiple rounds of training, learn the defense strategy of the large language model (LLM) and generate more targeted attack samples.

[0096] The conditional variable (c) can be set to: historical conversation content (simulating multi-round conversations); past defense feedback from the large language model (LLM) (learning bypass strategies); and target attack intent (such as bypassing content review and obtaining sensitive information).

[0097] Key design techniques: Automatic generation of attack samples based on conditional variational autoencoder (cVAE); optimization of attack data using large language model (LLM) defense strategy feedback; and construction of multi-round context-aware attack samples.

[0098] 2. Attacker behavior modeling based on Markov chain.

[0099] Key Points:

[0100] a. Use Markov chain as an attacker behavior modeling tool.

[0101] b. Use the LLM's past responses as the state and the attacker's next input as the state transition to construct an intelligent attack path.

[0102] c. Optimize the attack path through the state transition matrix to maximize the possibility of the large language model (LLM) leaking sensitive information.

[0103] Key design techniques: combining Markov chains to predict large language model (LLM) defense strategies; generating dynamic attack paths based on Markov processes; and searching for optimal attack paths.

[0104] 3. Multi-round dialogue attack generation and optimization.

[0105] Key Points:

[0106] a. Traditional prompt injection attacks mainly target single-round input. The design of this invention focuses on multi-round dialogue attacks, simulating how a real attacker gradually guides the large language model (LLM) to leak sensitive information.

[0107] b. Dynamically adjust attack strategies to avoid fixed patterns and increase the possibility of bypassing large language model (LLM) defenses.

[0108] c. Optimize the attack path through reinforcement learning and gradually approach the optimal attack strategy.

[0109] Key design techniques: attack sample generation method based on historical conversations; adversarial optimization attack strategy learning method; attack framework that supports multi-round iterative optimization.

[0110] 4. Covert attack input generation.

[0111] Key Points:

[0112] a. Combine semantic paraphrasing and adversarial text generation to generate more covert attack instructions.

[0113] b. Fine-tune the GPT / LLM pre-trained model to enable the generated attack input to bypass the explicit interception mechanism.

[0114] c. Use text style transfer to make the attack input look more like normal conversation.

[0115] Key design techniques: generation of covert attack instructions based on semantic reconstruction; adversarial text enhancement to evade security detection; and text style transfer to disguise attack intent.

[0116] 5. Automated large language model (LLM) defense capability testing.

[0117] Key Points:

[0118] a. Build an automated testing framework to batch evaluate the defense capabilities of large language models (LLMs) under different attack inputs.

[0119] b. Combined with data augmentation technology, test whether the large language model (LLM) can stably resist different forms of attacks (such as lexical transformation and semantic transformation).

[0120] c. Dynamically optimize attack strategies to continuously evolve attack inputs to break through the latest security defenses of the Large Language Model (LLM).

[0121] Key design techniques: A method for automatically evaluating large language model (LLM) defense strategies in batches; a breakthrough in large language model (LLM) defense driven by data enhancement; and an adaptive optimization method for attack strategies.

[0122] The above designs not only improve the quality and concealment of attack data, but also greatly reduce the cost of manually designing data, making large language model (LLM) security testing more intelligent and efficient.

[0123] Compared with existing solutions, the design of this invention has significant advantages in detecting and generating data for multi-round prompt injection attacks:

[0124] (1) Automatic data generation to reduce human intervention. That is, the conditional variational autoencoder (cVAE) and Markov chain are used to automatically generate dialogue data that is closer to the real attacker's strategy, without the need for manual design, thus improving efficiency. In addition, a defense strategy of continuous learning LLM is designed to optimize the generated data and improve the stealth of the attack.

[0125] (2) Supporting multi-round covert attacks to break through LLM defense. Existing solutions are mostly single-round direct attacks, which are easily detected and intercepted by LLM. The design of the present invention combines the Markov chain to generate a step-by-step guided covert attack, simulating the attacker to adjust the questioning strategy, so that LLM gradually leaks sensitive information in multiple rounds of dialogue.

[0126] (3) Enhance the diversity of attack data. Existing artificial data is highly patterned and easily identified and intercepted by LLM. The design of the present invention combines the state transition characteristics of the Markov chain to make the attack data more random and changeable, thereby improving the success rate.

[0127] (4) Large-scale and efficient testing. The existing methods rely on manual testing, which is costly and inefficient. The design of the present invention can automatically test the security protection capabilities of LLM in batches, quickly identify security vulnerabilities, and optimize defense strategies.

[0128] Compared with existing solutions, the design of the present invention has core advantages such as automation, greater concealment, wider coverage, and batch testing. It can more realistically and comprehensively evaluate the security defense capabilities of LLM and discover the shortcomings of existing defense mechanisms.

[0129] The embodiments of the present invention are described in detail above with reference to the accompanying drawings. However, the present invention is not limited to the above embodiments. Various changes can be made within the scope of knowledge possessed by ordinary technicians in this field without departing from the spirit of the present invention.

Claims

1. A method for obtaining a prompt injection attack test case for a large language model, characterized by: Perform steps A to D below to train a target large language model for generating prompt injection attack test cases. Step A. Based on the preset malicious sample instructions and the preset malicious behavior labels corresponding to each malicious sample instruction, a large language model capable of responding to malicious instructions is applied to each malicious sample instruction to deconstruct the malicious sample instruction, obtaining the corresponding independent non-malicious deconstruction instructions, and then proceeding to Step B. Step B. For each malicious sample instruction, apply the large language model through the natural language processing algorithm to sort the non-malicious disassembly instructions corresponding to the malicious sample instruction in the order in which the malicious intent is gradually exposed, obtain the non-malicious disassembly instructions corresponding to the malicious sample instruction, and then proceed to Step C; Step C. Based on the sequential non-malicious disassembly instructions corresponding to each malicious sample instruction, the first language model is input and answers are obtained by accumulating previous questions and answers and combining them with the malicious behavior labels corresponding to the corresponding malicious sample instructions. This is used to train the first language model and improve its security, and then proceed to Step D. In the above step C, based on each malicious sample instruction, for each non-malicious disassembly instruction corresponding to the malicious sample instruction, initialize n=1, and then execute the following steps C1 to C4; Step C1. Select the nth non-malicious disassembly instruction. If n=1, directly generate the conversation history code c1 corresponding to the nth non-malicious disassembly instruction. Generate the attack signal code c2 based on the malicious behavior label corresponding to the nth non-malicious disassembly instruction, and then proceed to step C2. If n≠1, the nth non-malicious disassembly instruction is used in combination with the previously selected non-malicious disassembly instructions to process the responses from the first language model in steps C1 to C4, generating the corresponding conversation history code c1. The attack signal code c2 is generated using the malicious behavior label corresponding to the nth non-malicious disassembly instruction, and the process proceeds to step C2. Step C2. The encoder in the conditional variational autoencoder (cVAE) processes the combination of c1 and c2 to generate a corresponding latent space vector representation z. The decoder in the conditional variational autoencoder (cVAE) then processes the latent space vector representation z to generate a conditional instruction, and then proceeds to step C3. Step C3. Input the conditional instruction into the first language model and obtain an answer, train the first language model to improve the security of the first language model, and then proceed to step C4; Step C4. Determine whether n is equal to the number N of non-malicious disassembly instructions corresponding to the malicious sample instructions. If so, the training of the first language model for the malicious sample instructions is completed. Otherwise, n is updated by adding 1 and the process returns to step C1; Step D. Based on the responses from the first language model corresponding to each non-malicious disassembly instruction during the training of the first language model, the transition probabilities between the preset malicious states corresponding to each non-malicious disassembly instruction are analyzed. The Markov chain network is used to split each malicious sample instruction one by one, and attack verification is performed in combination with the first language model until the preset attack intensity threshold is reached. This completes the training of the Markov chain network, i.e., obtains the target large language model for generating prompt injection attack test cases.

2. The method for obtaining a prompt injection attack test case for a large language model according to claim 1, characterized in that: It also includes steps AB as follows: after executing step A, proceed to step AB; Steps AB. For each non-malicious disassembly instruction corresponding to each malicious sample instruction, first perform steganography and obfuscation processing to update the non-malicious disassembly instruction, including synonym replacement, spelling errors, text variants, and encoding; then update the nested role scenario for the non-malicious disassembly instruction; after completing the update of each non-malicious disassembly instruction, proceed to step B.

3. The method for obtaining a prompt injection attack test case for a large language model according to claim 1, characterized in that: In the training of the first language model, the loss function is as follows: in, represents the loss value, represents the variance function, x represents the latent space vector representing the input variable in z, p(·) represents the decoder in the conditional variational autoencoder cVAE, q(·) represents the encoder in the conditional variational autoencoder cVAE, z|x represents the distribution of z under the input variable x, x|z ​​represents the distribution of the input variable x under z, D KL [] represents the KL divergence function.

4. The method for obtaining a prompt injection attack test case for a large language model according to claim 1, characterized in that: The step D includes steps D1 to D3 as follows: Step D1. For each non-malicious disassembly instruction corresponding to the response from the first language model during the training process of the first language model, apply the trained language model to obtain the preset malicious state corresponding to the non-malicious disassembly instruction corresponding to the response, and then obtain the malicious state corresponding to each non-malicious disassembly instruction, and then proceed to Step D2; Step D2. Based on the order of non-malicious disassembly instructions corresponding to each malicious sample instruction, the transition probabilities between different malicious states are obtained according to the malicious states corresponding to each non-malicious disassembly instruction and the malicious behavior labels corresponding to the malicious sample instructions to which each non-malicious disassembly instruction belongs, and then the process proceeds to Step D3. Step D3. Based on each malicious sample instruction, the malicious sample instruction is input into the Markov chain network. The Markov chain network decomposes the malicious sample instruction into each non-malicious secondary disassembly instruction under the malicious state transition according to the transition probability between different malicious states. At the same time, each non-malicious secondary disassembly instruction is input into the first large language model one by one and each answer is obtained. Based on each answer, the model attack strength corresponding to each non-malicious secondary disassembly instruction is cumulatively calculated until a preset attack strength threshold is reached. Then, the decomposition of the malicious sample instruction is stopped, and the Markov chain network is trained, that is, the target large language model for generating prompt injection attack test cases is obtained.

5. The method for obtaining a prompt injection attack test case for a large language model according to claim 1, characterized in that: The preset malicious behavior labels include bypassing content review, obtaining sensitive information, copyright infringement, and malicious promotion.

6. The method for obtaining a prompt injection attack test case for a large language model according to claim 1, characterized in that: The malicious state includes normal conversation, slight prompt, and obvious attack.

Citation Information

Patent Citations

  • Industrial Internet of Things intrusion detection system based on conditional variation auto-encoder

    CN117201058A

  • Markov decision process-based large language model multi-stage privacy protection method

    CN119416268A