Prompt word stealing attack defense method and device based on security aspect

By deploying a security aspect program on the large model server, matching the vectorized response content with the prompts, and using the vector database for retrieval, the problem in the existing technology that prompts theft attacks are difficult to effectively defend is solved, and a low-cost, Efficient defense effect.

CN118779876AActive Publication Date: 2024-10-15ANT GROUP CO LTD

Patent Information

Application Number
CN202411261676.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-10
Publication Date
2024-10-15
Estimated Expiration
2044-09-10

AI Technical Summary

Technical Problem

Existing technology is difficult to effectively defend against prompt theft attacks. Common interception strategies based on prior knowledge are easily bypassed by attackers. Filtering request content requires transforming the service infrastructure, which is a heavy workload and high cost.

Method used

Adopt a prompt stealing attack defense method based on security aspects. Through the security aspect program deployed on the large model server, the vectorized response content and the prompts that need to be protected are matched at the semantic level, and the vector database is used to retrieve them. If there is a hit, execute Preset defense strategies, otherwise content will be released to avoid detection rules that rely on prior knowledge.

Benefits of technology

It achieves low-cost defense without modifying the service infrastructure, has higher recall rate and robustness, and can resist various attack bypasses targeting requests.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118779876A_ABST
    Figure CN118779876A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a prompt word stealing attack defense method based on a security aspect, and the method is realized based on a aspect technology, directly analyzes response content, carries out the semantic-level matching with a prompt word needing to be protected, does not depend on a detection rule based on prior knowledge, and improves the security of the prompt word. And various attack bypasses aiming at the request can be resisted, so that the recall rate and robustness are higher. The prompt word stealing attack defense device based on the security aspect in the embodiment of the specification also has the above beneficial effects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method and device for defending against prompt word theft attacks based on security aspects. Background Art

[0002] In large language models, prompt stealing attacks involve adding malicious instructions to user input to steal the model's original prompts, which can lead to the exposure of sensitive information and potential misuse of prompts by unauthorized individuals.

[0003] The current common defense solution for prompt stealing attacks is to analyze the user's request content and intercept the prompt stealing attack requests that need to be protected. However, the interception strategy based on prior knowledge is very easy to be bypassed by attackers. In addition, filtering the request content requires the transformation of the service infrastructure, which is a lot of work. Summary of the invention

[0004] One or more embodiments of the present specification provide a method and device for defending against prompt word stealing attacks based on security aspects, which can solve the problem of sensitive information leakage caused by prompt word stealing attacks at a very low cost.

[0005] In a first aspect, a method for defending against prompt stealing attacks based on a security aspect is provided, which is executed by a security aspect program deployed on a large model server, and the method includes: In response to a question request initiated by a user to the big model through the big model server, intercepting a first response content of the big model to the question request; Vectorizing the first response content to obtain a first vector; Searching a vector database based on the first vector, wherein the vector database stores prompt word vectors that need to be protected; If the search is successful, the preset defense strategy is executed; otherwise, the first response content is released.

[0006] As an optional implementation manner of the method of the first aspect, the method further includes: If the first vector is not found in the vector database, obtaining a historical interaction record between the user and the large model, and obtaining a second response content from the historical interaction record; Vectorizing the second response content to obtain a second vector; A search is performed in the vector database based on the second vector, and if a search hits, a preset defense strategy is executed; otherwise, the first response content is released.

[0007] Specifically, vectorizing the second response content to obtain a second vector specifically includes: Connect the second response content into a string; The character string is vectorized to obtain the second vector.

[0008] As an optional implementation manner of the method of the first aspect, the method further includes constructing the vector database, specifically including: Get the prompt words that need protection; Vectorizing the prompt word that needs to be protected to obtain the prompt word vector; The prompt vector is stored in the vector database.

[0009] As an optional implementation of the method of the first aspect, the method further includes deploying the security aspect program on the large model server, specifically including: Obtaining an application program of the large model server and a cut-off point of the application program; The security aspect program is injected into the cut-off point, so that the security aspect program is executed when the application is executed to the cut-off point.

[0010] In a second aspect, a security aspect-based prompt stealing attack defense device is provided, which is applied to a large model server, wherein the large model server is deployed with a security aspect program, and the device is applied to execute the business logic of the security aspect program, and the device includes: A data acquisition module, configured to respond to a question request initiated by a user to the big model through the big model server, and intercept a first response content of the big model to the question request; A processing module, configured to vectorize the first response content to obtain a first vector; A database module, configured to construct a vector database, wherein the vector database stores prompt word vectors that need to be protected; A retrieval module, configured to search the vector database based on the first vector; The response module is configured to execute a preset defense strategy in response to a search hit by the retrieval module in the vector database based on the first vector; and to release the first response content in response to a search miss by the retrieval module in the vector database based on the first vector.

[0011] As an optional implementation of the device according to the second aspect, wherein: The data acquisition module is further configured to acquire a historical interaction record between the user and the large model in response to a search failure by the retrieval module in the vector database based on the first vector, and acquire a second response content from the historical interaction record; The processing module is further configured to vectorize the second response content to obtain a second vector; The retrieval module is further configured to search the vector database based on the second vector; The response module is also configured to execute a preset defense strategy in response to a search hit by the retrieval module in the vector database based on the second vector; and to release the first response content in response to a search miss by the retrieval module in the vector database based on the second vector.

[0012] Specifically, the processing module is specifically used for: Connect the second response content into a string; The character string is vectorized to obtain the second vector.

[0013] As an optional implementation of the device according to the second aspect, wherein: The data acquisition module is also configured to acquire a prompt that needs to be protected; The processing module is further configured to vectorize the prompt words that need to be protected to obtain the prompt word vector, and store the prompt word vector in the vector database.

[0014] As an optional implementation manner of the device according to the second aspect, the device further includes: The aspect program injection module is configured to obtain the application of the large model server and the aspect point of the application, and inject the security aspect program into the aspect point so that the security aspect program is executed when the application is executed to the aspect point.

[0015] In a third aspect, a computer-readable storage medium is provided, which stores a computer program. When the computer program runs on an electronic device, the electronic device executes the above-mentioned security-aspect-based prompt word theft attack defense method.

[0016] In a fourth aspect, an electronic device is provided, including: at least one memory for storing a program; At least one processor is used to execute the program stored in the memory. When the program stored in the memory is executed, the processor is used to execute the above-mentioned security aspect-based prompt stealing attack defense method.

[0017] The beneficial effect of the method for defending against prompt stealing attacks based on security aspects described in the embodiments of this specification is that the method is implemented based on aspect technology, does not require modification of the basic architecture of the service, and has better convenience. The method directly analyzes the response content and matches it with the prompt to be protected at the semantic level. It does not rely on detection rules based on prior knowledge, and can resist various attack bypasses against requests, thereby having a higher recall rate and robustness.

[0018] The security aspect-based prompt word theft attack defense device described in the embodiments of this specification also has the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0020] Figure 1 The flowchart of a method for defending against prompt word theft attacks based on security aspects described in an embodiment of this specification is exemplarily shown.

[0021] Figure 2 A flowchart of another method for defending against prompt word theft attacks based on security aspects described in an embodiment of this specification is exemplarily shown.

[0022] Figure 3 The structural diagram of a security aspect-based prompt word theft attack defense device described in an embodiment of this specification is exemplarily shown.

[0023] Figure 4 The structural diagram of an electronic device described in an embodiment of this specification is exemplarily shown. DETAILED DESCRIPTION

[0024] First of all, it should be noted that the terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "the" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates otherwise.

[0025] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Therefore, it should be recognized by those skilled in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0026] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.

[0027] Large Language Model (LLM) is a deep learning model trained on massive text data. It can generate natural language text or understand the meaning of language text. Such models can perform a variety of natural language processing tasks, including but not limited to text classification, question answering, and dialogue.

[0028] In the , the provided word is the question or statement provided by the user, which is used to guide the generation of relevant replies or responses. After receiving a prompt word, it will generate the subsequent content or answer that is most relevant to the prompt word based on its internally trained knowledge and algorithm. The prompt word usually consists of "user input" and "instruction". For example, the prompt word: Please translate the following content into English "I am the class monitor", where "I am the class monitor" is "user input" and "Please translate the following content into English" is the instruction.

[0029] During the use of AI, you may be subject to prompt stealing attacks. Prompt stealing attacks, also known as prompt leakage, are an attempt to manipulate the output to leak part or all of the original prompt. In AI, prompt leakage usually involves adding malicious instructions to user input to steal the model's original prompts, which may lead to the exposure of sensitive information and potential abuse of prompts by unauthorized individuals. Usually, prompt stealing attacks mainly refer to system prompts, which are the initial instruction set that developers use to set boundaries for AI conversations. The instruction set includes rules that should be followed, topics that need to be avoided, how to format responses, and so on. These instructions may be inserted into the original prompts as messages before the user talks to the AI. If an attacker obtains these system prompts, they can analyze the AI's behavior patterns or censorship system from them, and then manipulate the AI ​​without authorization, which poses a serious risk of privacy leakage.

[0030] A common defense against prompt stealing attacks is to analyze the user's request content and intercept the prompt stealing attack requests that hit the expert rules. However, this interception strategy based on prior knowledge is very easy to be bypassed by attackers, and filtering the request content requires the transformation of the service infrastructure, which is labor-intensive and costly.

[0031] In summary, there is an urgent need in the prior art for a safe, effective and low-cost defense solution against prompt word theft attacks.

[0032] In view of this, one or more embodiments of the present specification propose a method and device for defending against prompt word stealing attacks based on security aspects, which can solve the problem of data leakage caused by prompt word stealing attacks at a very low cost.

[0033] The following will further describe in detail the security aspect-based prompt word theft attack defense method and device described in one or more embodiments of this specification in conjunction with the drawings and specific embodiments of the specification, but this detailed description does not constitute a limitation on the embodiments of this specification.

[0034] Please refer to Figure 1 , Figure 1 The present invention is a flowchart of a method for defending against prompt word stealing attacks based on security aspects proposed in one or more embodiments of the present specification.

[0035] like Figure 1 As shown, in some embodiments, the security aspect-based prompt stealing attack defense method can be executed by a security aspect program deployed on the large model server. The method may include steps S100 to S106: S100: In response to a question request initiated by a user to the big model through the big model server, intercept a first response content of the big model to the question request.

[0036] S102: Vectorize the first response content to obtain a first vector.

[0037] S104: Searching in a vector database based on the first vector.

[0038] S106: If the search is successful, the preset defense strategy is executed; otherwise, the first response content is released.

[0039] It can be seen that in Figure 1 In the security aspect-based prompt stealing attack defense method shown, the response content of each round of dialogue between the user and the big model is vectorized, and the semantic level matching is performed with the prompts that need to be protected to determine whether there is a prompt stealing attack. This method does not rely on detection rules based on prior knowledge, so it can resist various attack bypasses against requests. In addition, the above-mentioned security aspect-based prompt stealing attack defense method is implemented through the security aspect program, which does not require modification of the infrastructure of the big model service, is low-cost and has better convenience.

[0040] The following is a detailed description of the embodiments of the present invention in conjunction with the accompanying drawings and specific embodiments. Figure 1 The method shown is described.

[0041] Before executing the above-mentioned security aspect-based prompt stealing attack defense method, initialization is required. In the initialization stage, the security aspect program is mainly injected into the large model server and the vector database is constructed.

[0042] The above-mentioned security aspect program is used to process the response content returned to the user, so as to implement the above-mentioned prompt stealing attack defense method based on security aspect. Specifically, the specific method of injecting the security aspect program into the large model server is: obtain the application of the large model server and the cut-off point of the application, and then inject the pre-built security aspect program into the cut-off point, so as to execute the security aspect program when executing the application to the cut-off point.

[0043] The above-mentioned vector database is used to store the prompt words vectors that need to be protected. In the initialization stage, the prompt words that need to be protected can be collected, and then the prompt words that need to be protected can be converted into vectors and saved in the vector database.

[0044] After the initialization is completed, the above-mentioned security aspect-based prompt stealing attack defense method can be executed.

[0045] First, with respect to step S100: in response to a question request initiated by a user to the big model through the big model server, a first response content of the big model to the question request is intercepted.

[0046] Through the setting of the cut-off point, this embodiment enables the security aspect program to intercept the response content text for the question request when monitoring the question request initiated by the user through the server, and use the single-round response content text as the first response content.

[0047] Next, in step S102 , the first response content is vectorized to obtain a first vector.

[0048] In order to facilitate retrieval, the first response content needs to be subjected to text vectorization processing in this step S102. Text vectorization refers to representing text as a vector that can express the semantics of the text, which is a basic work in the field of natural language processing.

[0049] It should be noted that, in this embodiment, the method of text vectorization processing of the first response content is not limited, and can be adaptively selected according to needs. For example, the method of text vectorization processing may include but is not limited to: word embedding method, one-hot encoding method, bag-of-words model, word-vector model, etc.

[0050] Next, in step S104 , a search is performed in a vector database based on the first vector.

[0051] The above-mentioned vector database has stored the prompt word vectors that need to be protected during the initialization phase, and the text vectorization processing method of these prompt word vectors needs to be consistent with the text vectorization processing method of the above-mentioned first response content.

[0052] The essence of searching in the vector database based on the first vector is to perform similarity matching between the first vector and each prompt vector that needs to be protected in the vector database. Specifically, similarity matching is to calculate the similarity between the first vector and each prompt vector that needs to be protected in the vector database, and then screen out the matching results through the similarity threshold. For example, according to the similarity matching results, k prompt vectors with the highest similarity to the first vector are screened, and then the k prompt vectors are screened again using the similarity threshold. If there is a prompt vector in the k prompt vectors whose similarity to the first vector is greater than the similarity threshold, the search is determined to be a hit, otherwise, the search is determined to be a miss.

[0053] In some embodiments, in order to reduce the amount of calculation for vector retrieval, an index may be created for the first vector and the prompt vector to map the dense first vector and the prompt vector to a low-dimensional index feature space, thereby reducing the amount of calculation for similarity matching. Specifically, a prompt index may be constructed for each prompt vector when constructing a vector database. When searching for the first vector, the first vector is also mapped to the same feature space to obtain the index of the first vector, and then the index of the first vector and the prompt index in the vector database are matched for similarity, and then the matching results are screened out by a similarity threshold to determine whether the search is a hit.

[0054] Next, in step S106: if the search is successful, the preset defense strategy is executed; otherwise, the first response content is released.

[0055] If the above-mentioned first vector search in the vector database does not hit a target, it can be determined that there is no prompt that needs to be protected in the corresponding response content. At this time, the application program on the large model server executes the program after the security aspect program cut-off point, that is, feeds back the response content to the user.

[0056] If the first vector is searched in the vector database and hits, it can be determined that there is a prompt that needs to be protected in the corresponding answer content, and then it is necessary to execute the preset defense strategy, that is, to perform defense processing on the answer content. The specific method of defense processing can be set according to the needs, and this embodiment does not limit this. For example, it can include but is not limited to response operations such as content interception, answering harmless content on behalf of others, or recording logs.

[0057] The above is a method for defending against prompt word stealing attacks on single-round answer content. In some implementations, a method for defending against prompt word stealing attacks on answer content in multiple rounds of dialogue can also be used. Figure 2 , Figure 2 A flowchart of another method for defending against prompt word stealing attacks based on security aspects is schematically shown.

[0058] like Figure 2 As shown, in some embodiments, the security aspect-based prompt stealing attack defense method can be executed by a security aspect program deployed on the large model server. The method can include steps S200 to S212: S200: In response to a question request initiated by a user to the big model through the big model server, intercept a first response content of the big model to the question request.

[0059] S202: Vectorize the first response content to obtain a first vector.

[0060] S204: Search in a vector database based on the first vector.

[0061] S206: If the first vector is searched in the vector database and a hit is found, a preset defense strategy is executed.

[0062] S208: If the first vector search in the vector database does not result in a hit, then the historical interaction record between the user and the large model is obtained, and the second response content is obtained from the historical interaction record.

[0063] S210: Vectorize the second response content to obtain a second vector.

[0064] S212: Searching in the vector database based on the second vector, if the search is successful, executing a preset defense strategy; otherwise, releasing the first response content.

[0065] It can be seen that in Figure 2 In the security aspect-based prompt stealing attack defense method shown, by analyzing the response content of the single-round and multi-round dialogues between the user and the big model, and matching the semantic level with the prompts that need to be protected, it is determined whether there is a prompt stealing attack. This method does not rely on detection rules based on prior knowledge, so it can resist various attack bypasses against requests. In addition, the above-mentioned security aspect-based prompt stealing attack defense method is implemented through the security aspect program, does not need to modify the infrastructure of the big model service, has low cost and better convenience.

[0066] The following is a detailed description of the embodiments of the present invention in conjunction with the accompanying drawings and specific embodiments. Figure 2 The method shown is described.

[0067] In execution Figure 2 Before the prompt stealing attack defense method based on security aspect is shown, it is necessary to initialize it. In the initialization stage, the security aspect program is mainly injected into the large model server and the vector database is constructed.

[0068] The above-mentioned security aspect program is used to process the response content returned to the user, so as to implement the above-mentioned prompt stealing attack defense method based on security aspect. Specifically, the specific method of injecting the security aspect program into the server is: obtain the application of the large model server and the cut-off point of the application, and then inject the pre-built security aspect program into the cut-off point, so that when the application is executed to the cut-off point, the security aspect program is executed.

[0069] The above-mentioned vector database is used to store the prompt words vectors that need to be protected. In the initialization stage, the prompt words that need to be protected can be collected, and then the prompt words that need to be protected can be converted into vectors and saved in the vector database.

[0070] After initialization is complete, you can execute Figure 2 The following is a security aspect-based method for defending against prompt stealing attacks.

[0071] First, with respect to step S200: in response to a question request initiated by a user to the big model through the big model server, a first response content of the big model to the question request is intercepted.

[0072] Through the setting of the cut-off point, this embodiment enables the security aspect program to intercept the response content text of the big model to the question request when monitoring the question request initiated by the user through the big model server, and use the single-round response content text as the first response content.

[0073] Next, in step S202 , the first response content is vectorized to obtain a first vector.

[0074] In order to facilitate retrieval, the first response content needs to be subjected to text vectorization processing in this step S202. Text vectorization refers to representing text as a vector that can express the semantics of the text, which is a basic work in the field of natural language processing.

[0075] It should be noted that, in this embodiment, the method of text vectorization processing of the first response content is not limited, and can be adaptively selected according to needs. For example, the method of text vectorization processing may include but is not limited to: word embedding method, one-hot encoding method, bag-of-words model, word-vector model, etc.

[0076] Next, in step S204 , a search is performed in a vector database based on the first vector.

[0077] The above-mentioned vector database has stored the prompt word vectors that need to be protected during the initialization phase, and the text vectorization processing method of these prompt word vectors needs to be consistent with the text vectorization processing method of the above-mentioned first response content.

[0078] The essence of searching in the vector database based on the first vector is to perform similarity matching between the first vector and each prompt vector that needs to be protected in the vector database. Specifically, similarity matching is to calculate the similarity between the first vector and each prompt vector that needs to be protected in the vector database, and then screen out the matching results through the similarity threshold. For example, according to the similarity matching results, k prompt vectors with the highest similarity to the first vector are screened, and then the k prompt vectors are screened again using the similarity threshold. If there is a prompt vector in the k prompt vectors whose similarity to the first vector is greater than the similarity threshold, the search is determined to be a hit, otherwise, the search is determined to be a miss.

[0079] In some embodiments, in order to reduce the amount of calculation for vector retrieval, an index may be created for the first vector and the prompt vector to map the dense first vector and the prompt vector to a low-dimensional index feature space, thereby reducing the amount of calculation for similarity matching. Specifically, a prompt index may be constructed for each prompt vector when constructing a vector database. When searching for the first vector, the first vector is also mapped to the same feature space to obtain the index of the first vector, and then the index of the first vector and the prompt index in the vector database are matched for similarity, and then the matching results are screened out by a similarity threshold to determine whether the search is a hit.

[0080] Next, in step S206 , if a hit is found in the search of the first vector in the vector database, a preset defense strategy is executed.

[0081] If the first vector is searched in the vector database and hits, it can be determined that there is a prompt that needs to be protected in the corresponding answer content, and then it is necessary to execute the preset defense strategy, that is, to perform defense processing on the answer content. The specific method of defense processing can be set according to the needs, and this embodiment does not limit this. For example, it can include but is not limited to response operations such as content interception, answering harmless content on behalf of others, or recording logs.

[0082] Next, for step S208: if the first vector search in the vector database does not hit a target, then the historical interaction record between the user and the large model is obtained, and the second response content is obtained from the historical interaction record.

[0083] If the first vector search in the vector database does not hit, it can be determined that there is no prompt that needs to be protected in the corresponding response content, but it does not rule out whether there is a prompt that needs to be protected in the user's historical interaction record. To further eliminate the risk of prompt stealing attacks, the historical interaction record between the user and the big model can be obtained, and then the content of the big model's reply in the historical interaction record can be intercepted as the second response content.

[0084] Next, in step S210 , the second response content is vectorized to obtain a second vector.

[0085] In this step S210, the second response content needs to be processed by text vectorization, and the second response content needs to be processed by the same processing method as the first response content.

[0086] Specifically, the second response content may be concatenated into a string, and then the string may be vectorized to obtain the second vector mentioned above.

[0087] Here, the text vectorization processing method for the second response content can be adaptively selected according to the needs. For example, the text vectorization processing method may include but is not limited to: word embedding method, one-hot encoding method, bag-of-words model, word-vector model, etc.

[0088] Next, for step S212: a search is performed in the vector database based on the second vector. If a search result is found, a preset defense strategy is executed; otherwise, the first response content is released.

[0089] Considering that the second vector is composed of multiple rounds of response content and carries a large amount of information, in some embodiments, the second vector can be divided into multiple sub-vectors, and then the sub-vectors of the second vector are matched with the prompt vectors in the vector database one by one by similarity, and then the matching results are screened out by the similarity threshold. For example, based on the similarity matching results, the k prompt vectors with the highest similarity to the sub-vectors of the second vector are screened out, and then the k prompt vectors are screened again by the similarity threshold. If there is a prompt vector among the k prompt vectors whose similarity to the sub-vector of the second vector is greater than the similarity threshold, it is determined that the search is a hit, otherwise, it is determined that the search is a miss.

[0090] In some embodiments, in order to reduce the amount of calculation for vector retrieval, indexes may be created for the sub-vectors of the second vector and the prompt vector, so as to map the dense sub-vectors of the second vector and the prompt vector to a low-dimensional index feature space, thereby reducing the amount of calculation for similarity matching. Specifically, a prompt index may be constructed for each prompt vector when constructing a vector database. When searching for the sub-vectors of the second vector, the sub-vectors of the second vector are also mapped to the same feature space to obtain the index of the sub-vector of the second vector, and then the index of the sub-vector of the second vector is matched with the prompt index in the vector database for similarity, and then the matching results are screened out by a similarity threshold, thereby determining whether the search is a hit.

[0091] If the above-mentioned second vector search in the vector database does not hit a hit, it can be determined that there is no prompt that needs to be protected in the historical interaction record between the user and the big model. At this time, the application on the big model server executes the program after the security aspect program cut-off point, that is, feeds back the response content to the user.

[0092] If the second vector is searched in the vector database and hits, it can be determined that there are prompts that need to be protected in the historical interaction records between the user and the big model. In this case, the preset defense strategy needs to be executed, that is, defense processing is performed on the response content. The specific method of defense processing can be set according to the needs, and this embodiment does not limit this. For example, it can include but is not limited to response operations such as content interception, answering harmless content on behalf of others, or recording logs.

[0093] Corresponding to the above-mentioned method for defending against prompt word stealing attacks based on security aspects, this embodiment also provides a device for defending against prompt word stealing attacks based on security aspects.

[0094] Please refer to Figure 3 , Figure 3 The example shows a security aspect-based prompt stealing attack defense device, which can be used to implement the above-mentioned security aspect-based prompt stealing attack defense method. It should be noted that the security aspect-based prompt stealing attack defense method described in one or more embodiments of the present application can rely on Figure 3 The security aspect-based prompt stealing attack defense device shown is implemented, but not limited to this device.

[0095] like Figure 3 As shown, the security aspect-based prompt stealing attack defense device is applied to a large model server, and the large model server is deployed with a security aspect program, and the device is applied to execute the business logic of the security aspect program. The device includes: The data acquisition module 301 is configured to respond to a question request initiated by a user to the big model through the big model server, and intercept the first response content of the big model to the question request.

[0096] The processing module 302 is configured to vectorize the first response content to obtain a first vector.

[0097] The database module 303 is configured to construct a vector database, in which the prompt vectors to be protected are stored.

[0098] The search module 304 is configured to search in the vector database based on the first vector.

[0099] The response module 305 is configured to execute a preset defense strategy in response to a search hit in the vector database based on the first vector by the retrieval module 304; and to release the first response content in response to a search miss in the vector database based on the first vector by the retrieval module 304.

[0100] For the above-mentioned data acquisition module 301, the data acquisition module 301 can use the security aspect program to intercept the response content text for the question request when it monitors the question request initiated by the user through the server through the setting of the cut-off point, and use the single-round response content text as the first response content.

[0101] Regarding the above-mentioned processing module 302, the processing module 302 can use word embedding method, one-hot encoding method, bag-of-words model, word-vector model and other methods to vectorize the first response content.

[0102] With respect to the above-mentioned database module 303, the database module 303 may collect prompt words that need to be protected in advance, and then convert the prompt words that need to be protected into vectors by using the above-mentioned vectorized first response content vectorization processing method and save them into the vector database.

[0103] With respect to the above-mentioned retrieval module 304, the retrieval module 304 is specifically used for performing similarity matching between the first vector and each prompt vector that needs to be protected in the vector database. Specifically, similarity matching is to calculate the similarity between the first vector and each prompt vector that needs to be protected in the vector database, and then screen out the matching results through the similarity threshold. For example, according to the similarity matching result, k prompt vectors with the highest similarity to the first vector are screened, and then the k prompt vectors are screened again using the similarity threshold. If there is a prompt vector with a similarity to the first vector greater than the similarity threshold among the k prompt vectors, it is determined that the retrieval is hit, otherwise, it is determined that the retrieval is not hit.

[0104] In some embodiments, in order to reduce the amount of calculation of vector retrieval, the retrieval module 304 can also create indexes for the first vector and the prompt vector to map the dense first vector and the prompt vector to a low-dimensional index feature space, thereby reducing the amount of calculation during similarity matching. Specifically, when constructing the vector database, a prompt index can be constructed for each prompt vector. When searching for the first vector, the retrieval module 304 also maps the first vector to the same feature space to obtain the index of the first vector, then performs similarity matching on the index of the first vector and the prompt index in the vector database, and then screens out the matching results through the similarity threshold to determine whether the retrieval is a hit.

[0105] Regarding the above-mentioned response module 305 , the response module 305 is specifically used to execute different response logics according to the search result of the search module 304 .

[0106] If the retrieval module 304 does not hit the above-mentioned first vector search in the vector database, it can be determined that there is no prompt that needs to be protected in the corresponding response content. At this time, the application program on the large model server executes the program after the security aspect program cut-off point, that is, feeds back the response content to the user.

[0107] If the search module 304 searches the vector database for the first vector search hit, it can be determined that there is a prompt that needs to be protected in the corresponding response content. At this time, the response module 305 needs to execute the preset defense strategy through the security aspect program, that is, to perform defense processing on the response content. The specific method of defense processing can be set according to the needs, and this embodiment does not limit this. For example, it can include but is not limited to response operations such as content interception, answering harmless content on behalf of others, or recording logs.

[0108] The above is a method for the device to defend against prompt word stealing attacks on the content of a single round of responses. In some implementations, the device can also perform a method for defending against prompt word stealing attacks on the content of responses in multiple rounds of conversations.

[0109] In some embodiments, the data acquisition module 301 may also be configured to obtain historical interaction records between the user and the large model in response to a search miss by the retrieval module 304 in the vector database based on the first vector, and obtain second response content from the historical interaction records.

[0110] The above-mentioned processing module 302 may also be configured to vectorize the second response content to obtain a second vector.

[0111] The processing module 302 needs to perform text vectorization processing on the second response content in the same manner as the first response content. Specifically, the processing module 302 can connect the second response content into a string, and then vectorize the string to obtain the second vector.

[0112] The above-mentioned retrieval module 304 is further configured to perform a search in the vector database based on the second vector.

[0113] Considering that the second vector is composed of multiple rounds of response content and carries a large amount of information, in some embodiments, the search module 304 can divide the second vector into multiple sub-vectors, and then perform similarity matching on the sub-vectors of the second vector one by one with the prompt vectors in the vector database, and then screen out the matching results by using the similarity threshold. For example, based on the similarity matching results, k prompt vectors with the highest similarity to the sub-vectors of the second vector are screened out, and then the k prompt vectors are screened again by using the similarity threshold. If there is a prompt vector among the k prompt vectors whose similarity to the sub-vector of the second vector is greater than the similarity threshold, then the search is determined to be a hit, otherwise, the search is determined to be a miss.

[0114] In some embodiments, in order to reduce the amount of calculation of vector retrieval, the retrieval module 304 can also create indexes for the sub-vectors of the second vector and the prompt vector, so as to map the dense sub-vectors of the second vector and the prompt vector to a low-dimensional index feature space, thereby reducing the amount of calculation during similarity matching. Specifically, when constructing the vector database, a prompt index can be constructed for each prompt vector. When searching for the sub-vector of the second vector, the sub-vector of the second vector is also mapped to the same feature space to obtain the index of the sub-vector of the second vector, and then the index of the sub-vector of the second vector and the prompt index in the vector database are matched for similarity, and then the matching results are screened out by the similarity threshold, and then it is determined whether the search is a hit.

[0115] The above-mentioned response module 305 is also configured to execute a preset defense strategy in response to the retrieval module 304 searching a hit in the vector database based on the second vector; and release the first response content in response to the retrieval module 304 searching a miss in the vector database based on the second vector.

[0116] If the above-mentioned second vector search in the vector database does not hit a hit, it can be determined that there is no prompt that needs to be protected in the historical interaction record between the user and the big model. At this time, the application on the big model server executes the program after the security aspect program cut-off point, that is, feeds back the response content to the user.

[0117] If the second vector is searched in the vector database and hits, it can be determined that there are prompts that need to be protected in the historical interaction records between the user and the large model. At this time, the response module 305 needs to execute the preset defense strategy, that is, to perform defense processing on the response content. The specific method of defense processing can be set according to needs, and this embodiment does not limit this. For example, it can include but is not limited to response operations such as content interception, answering harmless content on behalf of others, or recording logs.

[0118] For the above-mentioned security aspect-based prompt stealing attack defense device, taking the module as an example of a software functional unit, the data acquisition module 301 may include code running on a computing instance. Among them, the computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Further, the above-mentioned computing instance may be one or more. For example, the data acquisition module 301 may include code running on multiple hosts / virtual machines / containers. The multiple hosts / virtual machines / containers used to run the code may be distributed in the same region (region) or in different regions. Furthermore, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same availability zone (AZ) or in different AZs, each AZ including a data center or multiple data centers with close geographical locations. Among them, usually a region may include multiple AZs.

[0119] Similarly, multiple hosts / virtual machines / containers used to run the code can be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Usually, a VPC is set up in a region. For cross-region communication between two VPCs in the same region and between VPCs in different regions, a communication gateway needs to be set up in each VPC to achieve interconnection between VPCs through the communication gateway.

[0120] As an example of a hardware functional unit, the data acquisition module 301 may include at least one computing device, such as a server, etc. Alternatively, the data acquisition module 301 may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.

[0121] The multiple computing devices included in the data acquisition module 301 can be distributed in the same region or in different regions. The multiple computing devices included in the data acquisition module 301 can be distributed in the same AZ or in different AZs. Similarly, the multiple computing devices included in the data acquisition module 301 can be distributed in the same VPC or in multiple VPCs. The multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.

[0122] In other embodiments, the data acquisition module 301 can be used to execute any step in the above-mentioned security aspect-based prompt stealing attack defense method, the processing module 302 can be used to execute any step in the above-mentioned security aspect-based prompt stealing attack defense method, the database module 303 can be used to execute any step in the above-mentioned security aspect-based prompt stealing attack defense method, the retrieval module 304 can be used to execute any step in the above-mentioned security aspect-based prompt stealing attack defense method, and the response module 305 can be used to execute any step in the above-mentioned security aspect-based prompt stealing attack defense method. The steps that the data acquisition module 301, the processing module 302, the database module 303, the retrieval module 304 and the response module 305 are responsible for implementing can be specified as needed, and the data acquisition module 301, the processing module 302, the database module 303, the retrieval module 304 and the response module 305 respectively implement different steps in the above-mentioned security aspect-based prompt stealing attack defense method to realize all the functions of the above-mentioned security aspect-based prompt stealing attack defense device.

[0123] In this implementation, the security aspect-based prompt word stealing attack defense device can also be applied to computing devices such as computers and servers, or to a computing device cluster including at least one computing device, to implement the security aspect-based prompt word stealing attack defense function.

[0124] In some embodiments, an electronic device is also provided. Figure 4 , the electronic device includes: a bus 401, a processor 402, a memory 403 and a communication interface 404. The processor 402, the memory 403 and the communication interface 404 communicate with each other through the bus 401. The electronic device can be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in the electronic device.

[0125] The bus 401 may be a peripheral component interconnect (PCI) bus, or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 The bus 601 is represented by only one line, but it does not mean that there is only one bus or one type of bus. The bus 601 may include a path for transmitting information between various components of the electronic device (for example, the processor 402, the memory 403, and the communication interface 404).

[0126] The processor 402 may include any one or more processors such as a CPU, a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0127] The memory 403 may include a volatile memory, such as a random access memory (RAM). The memory 403 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).

[0128] The memory 403 stores executable program codes, and the processor 402 executes the executable program codes to respectively implement the functions of the aforementioned data acquisition module 301, processing module 302, database module 303, retrieval module 304 and response module 305, that is, to implement the functions of the aforementioned security-aspect-based prompt word stealing attack defense device, thereby implementing the aforementioned security-aspect-based prompt word stealing attack defense method.

[0129] The communication interface 404 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the electronic device and other devices or a communication network.

[0130] In some embodiments, a computer-readable storage medium is also provided, on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned security aspect-based prompt stealing attack defense method is implemented.

[0131] The computer-readable storage medium may be any available medium that can be stored in the electronic device or a data storage device such as a data center that includes one or more available media. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk). The computer-readable storage medium includes instructions that instruct the electronic device to execute the above-mentioned security-aspect-based prompt stealing attack defense method.

[0132] It is to be understood that the structure illustrated in the embodiments of this specification does not constitute a specific limitation on the system of the embodiments of this specification. In other embodiments of the specification, the above system may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0133] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0134] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0135] It should be noted that the above examples are only specific embodiments of the present invention, and the present invention is obviously not limited to the above examples, and there are many similar variations. All variations directly derived or associated from the contents disclosed by the technicians in this field should fall within the protection scope of the present invention.

Claims

1. A method for defending against prompt word stealing attacks based on security aspects, which is executed by a security aspect program deployed on a large model server, and comprises: In response to a question request initiated by a user to the big model through the big model server, intercepting a first response content of the big model to the question request; Vectorizing the first response content to obtain a first vector; Searching a vector database based on the first vector, wherein the vector database stores prompt word vectors that need to be protected; If the search is successful, the preset defense strategy is executed; otherwise, the first response content is released.

2. The method of claim 1, further comprising: If the first vector is not found in the vector database, obtaining a historical interaction record between the user and the large model, and obtaining a second response content from the historical interaction record; Vectorizing the second response content to obtain a second vector; A search is performed in the vector database based on the second vector, and if a search hits, a preset defense strategy is executed; otherwise, the first response content is released.

3. The method according to claim 2, vectorizing the second response content to obtain a second vector, specifically comprising: Connect the second response content into a string; The character string is vectorized to obtain the second vector.

4. The method of claim 1, further comprising: Get the prompt words that need protection; Vectorizing the prompt word that needs to be protected to obtain the prompt word vector; The prompt vector is stored in the vector database.

5. The method of claim 1, further comprising: Obtaining an application program of the large model server and a cut-off point of the application program; The security aspect program is injected into the cut-off point, so that the security aspect program is executed when the application is executed to the cut-off point.

6. A security aspect-based prompt stealing attack defense device, applied to a large model server, the large model server is deployed with a security aspect program, the device is applied to execute the business logic of the security aspect program, the device includes: A data acquisition module, configured to respond to a question request initiated by a user to the big model through the big model server, and intercept a first response content of the big model to the question request; A processing module, configured to vectorize the first response content to obtain a first vector; A database module, configured to construct a vector database, wherein the vector database stores prompt word vectors that need to be protected; A retrieval module, configured to search the vector database based on the first vector; The response module is configured to execute a preset defense strategy in response to a search hit by the retrieval module in the vector database based on the first vector; and to release the first response content in response to a search miss by the retrieval module in the vector database based on the first vector.

7. The device according to claim 6, wherein: The data acquisition module is further configured to acquire a historical interaction record between the user and the large model in response to a search failure by the retrieval module in the vector database based on the first vector, and acquire a second response content from the historical interaction record; The processing module is further configured to vectorize the second response content to obtain a second vector; The retrieval module is further configured to search the vector database based on the second vector; The response module is also configured to execute a preset defense strategy in response to a search hit by the retrieval module in the vector database based on the second vector; and to release the first response content in response to a search miss by the retrieval module in the vector database based on the second vector.

8. The device according to claim 7, wherein the processing module is specifically used for: Connect the second response content into a string; The character string is vectorized to obtain the second vector.

9. The device according to claim 6, wherein: The data acquisition module is also configured to acquire a prompt that needs to be protected; The processing module is further configured to vectorize the prompt words that need to be protected to obtain the prompt word vector, and store the prompt word vector in the vector database.

10. The device of claim 6, further comprising: The aspect program injection module is configured to obtain the application of the large model server and the aspect point of the application, and inject the security aspect program into the aspect point so that the security aspect program is executed when the application is executed to the aspect point.

11. A computer-readable storage medium storing a computer program, wherein when the computer program is executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 5.

12. An electronic device comprising: at least one memory for storing a program; At least one processor is used to execute the program stored in the memory, and when the program stored in the memory is executed, the processor is used to execute the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Defending device and method for cross-site scripting attack

    CN106506548A

  • Model attack defense method and device

    CN110889117A

  • Full-link blacklist detection method and device based on Bloom filter in AMI (Advanced Metering Infrastructure) use and acquisition system

    CN115695033A

  • Attack defense method and device, terminal equipment and storage medium

    CN117675415A

  • Prompt injection attack defense method and device, storage medium and electronic equipment

    CN118551366A

Cited By

  • Method and device for detecting attack behavior, storage medium and electronic equipment

    CN119442238A