Xss bypassing test case generation method based on Llama2 model
Through pre-training and fine-tuning of the Llama2 model, combined with HTML insertion verification and WAF verification, the problem of insufficient contextual information association and poor syntax understanding in xss bypass test case generation in the existing technology has been solved, and more accurate and flexible xss bypassing has been achieved. Through use case generation, the detection capability of the detection system is improved.
Patent Information
- Application Number
- CN202410857424.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-10-15
AI Technical Summary
When generating XSS bypass test cases, the existing technology has limited context information association and poor syntax understanding, resulting in low detection accuracy.
Use the Llama2 model for pre-training and fine-tuning, build a pre-trained use case generation model based on context learning through network traffic data sets, combine HTML insertion verification and WAF verification to be tested, generate effective xss bypass attack use cases, and improve the use cases through repeated training of efficiency.
It improves the ability to generate xss bypass test cases, can more accurately understand and process long entity names after obfuscation encoding, generates syntactically and semantically coherent use cases, and improves the robustness and flexibility of the detection system.
Smart Images

Figure CN118779226A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of software testing, and in particular relates to a method for generating an XSS bypass test case based on a Llama2 model. Background Art
[0002] Web applications are widely available on the Internet. These applications accept user input and present content to users, making them potential targets of XSS attacks. There are already WAF systems that can detect XSS attacks, but the detection capability for XSS bypass attack cases is still poor, and the detection accuracy is low. The difference between XSS bypass attack cases and conventional XSS attack cases is that attackers use more advanced and deceptive techniques to evade conventional XSS detection and protection mechanisms. Common bypass methods include case bypass, character concatenation, character obfuscation, encoding bypass, and multi-layer nested bypass. There are few XSS bypass test cases in the current network data set, so some methods are needed to generate XSS bypass test cases to improve the detection capability and robustness of the security detection system.
[0003] There are two common methods for generating XSS bypass test cases:
[0004] (1) One method is to use a scripting language such as Python to write obfuscation, encoding, and case bypass functions to transform existing conventional XSS test cases.
[0005] (2) One method is to use a temporal convolutional network to build a generation model for existing bypass test cases, and generate XSS vulnerability test cases that meet the requirements by learning the test case features.
[0006] However, the existing technology has the problems of limited context information association and poor grammatical comprehension ability in the process of generating test cases. Summary of the invention
[0007] In view of the above shortcomings of the prior art, the purpose of the invention is to provide a bucket identification method and system to improve the efficiency of bucket identification. This method uses the context learning of the Llama2 model and the learning ability of text grammar and semantics to enable the model to understand and generate expected and effective xss bypass attack use cases.
[0008] In a first aspect of the present invention, a method for generating an XSS bypass test case based on a Llama2 model is proposed, comprising:
[0009] S1, collect network traffic data sets, and build a pre-trained use case generation model based on the Llama2 model based on the network traffic data sets;
[0010] S2, importing the preset valid data set into the pre-trained use case generation model, performing fine-tuning training, and obtaining a basic use case generation model;
[0011] S3, generates bypass attack cases through the basic case generation model, performs HTML insertion verification and WAF verification on the bypass attack cases to obtain valid samples;
[0012] S4, import the valid samples into the basic use case generation model and repeat the training until the effectiveness of the generated bypass attack case reaches the preset value, and obtain the XSS bypass test case generation model.
[0013] Furthermore, in S1, after collecting the network traffic dataset, it is imported into the Llama2 model for pre-training to obtain a pre-training case generation model based on the Llama2 model.
[0014] Furthermore, the preset valid data set includes multiple xss attack data, and the xss attack data in the preset valid data set is verified by HTML insertion and WAF to be tested.
[0015] Furthermore, HTML insertion verification includes pop-up window verification or print information verification. The specific steps include creating an HTML page containing a potential XSS vulnerability, inserting an XSS payload at a potential XSS injection risk location, and automatically rendering the HTML page. If there is a pop-up window or print information, and the browser does not have a syntax error message, it means that the XSS payload syntax is legal. If the browser has a syntax error message prompt, it means that the XSS payload syntax is illegal.
[0016] Furthermore, the step of verifying the WAF to be tested includes sending the xss payload as a request to the WAF to be tested. If the WAF intercepts it as an xss attack, it means that it is not bypassable. Otherwise, it means that it is bypassable.
[0017] Furthermore, if the bypass attack use case can pass both the HTML insertion verification and the WAF to be tested verification, the bypass attack use case is classified as a valid sample.
[0018] Furthermore, the valid samples are imported into the basic use case generation model, and the steps of repeated training include: importing the valid samples into the basic use case generation model again, adjusting the basic use case generation model, generating a new round of bypass attack use cases through the adjusted basic use case generation model, performing HTML insertion verification and WAF verification to be tested on the new round of bypass attack use cases, obtaining a new round of valid samples, repeating this step, and completing repeated training.
[0019] Furthermore, the effectiveness of bypassing attack cases is equal to the ratio of the number of effective samples to the total number of bypassing attack cases.
[0020] Furthermore, when test cases need to be generated, a preset number of test cases are generated by bypassing the test case generation model through xss.
[0021] Furthermore, when the bypass attack use case fails to pass the HTML insertion verification and / or the WAF to be tested verification, it is classified as an invalid sample.
[0022] The beneficial effects of the present invention are as follows:
[0023] The method described in the present invention can capture more contextual information, help to more accurately understand the overall grammatical semantics of XSS bypass test cases, better handle long entity names after obfuscation encoding, and generate XSS bypass test cases with more coherent grammatical semantics; through large-scale unsupervised learning, automatically learn features and patterns from text data without manual selection and extraction of features. This enables them to better capture the complex associations and language rules in text data, including grammar, semantics, and context. Because they have no predefined features, they are more flexible in generating XSS bypass test cases and can generate text that is more natural to XSS attack languages. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The accompanying drawings are only used to illustrate specific embodiments and are not considered to limit the present invention. In the entire drawings, the same reference symbols represent the same components. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings.
[0025] Figure 1 A flowchart of a method for generating an XSS bypass test case based on the Llama2 model provided in an embodiment of the present invention;
[0026] Figure 2 A flowchart of HTML insertion verification and WAF verification to be tested provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without making creative work should fall within the scope of protection of the present invention.
[0028] Furthermore, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts disclosed in the present invention.
[0029] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the orientation or position relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inside", "outside", etc. is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present invention. In addition, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. The terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be a connection between the two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0030] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of methods and systems consistent with some aspects of the present invention as detailed in the appended claims.
[0031] The present invention proposes an XX method and device, which solves the problems of low automation, inaccurate target positioning and marking, low work efficiency, high technical requirements for testers, complicated operations and long time consumption in existing methods.
[0032] Method Embodiment
[0033] like Figure 1 As shown, a method for generating an XSS bypass test case based on the Llama2 model provided by the present invention includes:
[0034] S1, collects network traffic datasets, and builds a pre-trained use case generation model based on the Llama2 model based on the network traffic dataset.
[0035] In this step, the network traffic dataset is collected and prepared, and the collected dataset is sent to the Llama2 model for pre-training to build a Llama2 model based on the network traffic text data (i.e., a pre-training case generation model).
[0036] S2, import the preset valid data set into the pre-trained use case generation model, perform fine-tuning training, and obtain the basic use case generation model.
[0037] In this step, the xss attack dataset (preset valid data) with a validity label is used as input. The attack datasets with valid labels can pass the HTML insertion verification and the WAF to be tested verification. The pre-trained use case generation model is fine-tuned to allow the pre-trained use case generation model to further learn the characteristics of the xss bypass samples. The fine-tuning goal is to generate a valid xss bypass use case and obtain a basic use case generation model.
[0038] S3, generates bypass attack cases through the basic case generation model, performs HTML insertion verification and WAF verification on the bypass attack cases to obtain valid samples.
[0039] In this step, if Figure 2 As shown in the figure, the basic use case generation model is used to automatically generate xss bypass attack cases, and the bypass cases generated by the basic use case generation model are sent to HTML insertion verification and the WAF to be tested for verification in turn. HTML insertion verification specifically refers to the verification through pop-up windows (i.e., a dialog box window appears on the upper part of the browser during the browser rendering process) or print information verification (i.e., custom print information appears during the browser rendering process). First, create an HTML page containing a potential xss vulnerability, insert an xss payload at the potential xss injection risk position, and automatically render the HTML page. If there is a pop-up window or print information, and the browser does not have a syntax error message, it means that the xss payload syntax is legal and executable; if the browser has a syntax error message prompt, it means that the xss payload syntax is illegal and cannot be executed. The WAF to be tested verification specifically refers to sending the xss payload as a request to the WAF to be tested. If the WAF intercepts it as an xss attack, it means that it is not bypassable. Otherwise, it means that it is bypassable. The generated bypass attack case passes the verification at the same time, has syntax legality and bypassability, and is a valid bypass attack case. According to the above verification results, the generated samples are marked with valid labels; among them, the xss payload is the malicious script code injected into the web page by the attacker, and the bypass attack use case with a valid label is a valid sample.
[0040] S4, import the valid samples into the basic use case generation model and repeat the training until the effectiveness of the generated bypass attack case reaches the preset value, and obtain the XSS bypass test case generation model.
[0041] In this step, valid samples are taken as input, and the previous basic use case generation model is re-fine-tuned to improve the effective sample rate P of the basic use case generation model to generate effective bypass attack cases. The calculation formula is; P = number of valid samples / total number of bypass attack cases. Repeat steps S3 and S4 until the effective sample rate of bypass attack cases generated by the basic use case generation model reaches the preset value, and the XSS bypass test case generation model is obtained.
[0042] The present invention proposes a method for generating xss bypass test cases based on the Llama2 model. The core idea is to first pre-train the Llama2 model with massive network traffic data, then fine-tune the pre-trained model with xss bypass test cases, and use the fine-tuned model to automatically generate xss bypass test cases, verify the validity of the bypass test cases generated by the model, and feed back to the model for further fine-tuning. Specifically, the method mainly includes the following steps: first, prepare a data set, including normal traffic requests and xss attack requests; then input the data into the Llama2 model for pre-training; then, fine-tune the pre-trained model with a data set consisting of xss bypass test cases, including xss bypass data sets including input text and corresponding labels. Use these data to fine-tune the pre-trained large language model. Then, use the fine-tuned model to automatically generate xss bypass attack test cases, and verify whether the xss bypass test cases generated by the model are valid through the browser console, such as whether they can be executed after being input into the console. If the attack test case can be executed normally, it is a valid xss bypass attack test case, otherwise, it is invalid. After the automatically generated data is labeled, it is sent to the model for iterative fine-tuning to improve the model's ability to generate effective XSS bypass attacks.
[0043] The XSS bypass test case generation method based on the Llama2 model proposed in the present invention can solve the problems of lack of context information in the script function generation method, limited context information in the temporal convolutional network generation method, and poor grammar understanding ability, and realize a more accurate and flexible XSS bypass case generation algorithm, which not only reduces the complicated feature engineering extraction work of conventional machine learning algorithms, but also avoids the complex workload of manually writing grammar rules and constructing grammar trees. The method uses the context learning of the Llama2 model and the learning ability of text grammar semantics to enable the model to understand and generate expected and effective XSS bypass attack cases.
[0044] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, rather than to limit them. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the above embodiments, or replace some of the technical features therein by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. Any changes or replacements that can be easily thought of by those skilled in the art within the technical scope disclosed in the present invention should be covered within the protection scope of the present invention.
Claims
1. A method for generating xss bypass test cases based on the Llama2 model. It is characterized in that include: S1, collect network traffic data sets, and build a pre-trained use case generation model based on the Llama2 model based on the network traffic data sets; S2, importing the preset valid data set into the pre-trained use case generation model, performing fine-tuning training, and obtaining a basic use case generation model; S3, generates bypass attack cases through the basic case generation model, performs HTML insertion verification and WAF verification on the bypass attack cases to obtain valid samples; S4, import the valid samples into the basic use case generation model and repeat the training until the effectiveness of the generated bypass attack case reaches the preset value, and obtain the XSS bypass test case generation model.
2. According to the method for generating XSS bypass test cases based on the Llama2 model described in claim 1, It is characterized in that In S1, after collecting the network traffic dataset, it is imported into the Llama2 model for pre-training to obtain a pre-training case generation model based on the Llama2 model.
3. According to the method for generating XSS bypass test cases based on the Llama2 model in claim 1, It is characterized in that The preset valid data set contains multiple xss attack data. The xss attack data in the preset valid data set is verified by HTML insertion and WAF to be tested.
4. According to the method for generating XSS bypass test cases based on the Llama2 model described in claim 3, It is characterized in that HTML insertion verification includes pop-up window verification or print information verification. The specific steps include creating an HTML page containing a potential XSS vulnerability, inserting the XSS payload at the potential XSS injection risk location, and automatically rendering the HTML page. If there is a pop-up window or print information, and the browser does not have a syntax error message, it means that the XSS payload syntax is legal. If the browser has a syntax error message prompt, it means that the XSS payload syntax is illegal.
5. According to the method for generating XSS bypass test cases based on the Llama2 model in claim 3, It is characterized in that The steps of verifying the WAF to be tested include sending the xss payload as a request to the WAF to be tested. If the WAF intercepts it as an xss attack, it means that it is not bypassable. Otherwise, it means that it is bypassable.
6. According to the method for generating XSS bypass test cases based on the Llama2 model in claim 3, It is characterized in that If a bypass attack case can pass both HTML insertion verification and the WAF to be tested verification, the bypass attack case is classified as a valid sample.
7. According to claim 1, a method for generating XSS bypass test cases based on the Llama2 model, It is characterized in that Importing valid samples into the basic use case generation model, the steps of repeated training include: importing valid samples into the basic use case generation model again, adjusting the basic use case generation model, generating a new round of bypass attack use cases through the adjusted basic use case generation model, performing HTML insertion verification and WAF verification to be tested on the new round of bypass attack use cases, obtaining a new round of valid samples, repeating this step, and completing repeated training.
8. According to the method for generating XSS bypass test cases based on the Llama2 model in claim 1, It is characterized in that The effectiveness of bypass attack cases is equal to the ratio of the number of effective samples to the total number of bypass attack cases.
9. According to claim 1, a method for generating XSS bypass test cases based on the Llama2 model, It is characterized in that When test cases need to be generated, a preset number of test cases are generated by bypassing the test case generation model through XSS.
10. According to the method for generating XSS bypass test cases based on the Llama2 model in claim 1, It is characterized in that When a bypass attack case fails to pass HTML insertion verification and / or WAF verification to be tested, it is classified as an invalid sample.
