A JavaScript engine security testing method and testing system

By combining syntax analysis, recurrent neural network and variational autoencoder methods in JavaScript engine testing, high syntax accuracy and diversity test cases are generated, which solves the problem of low security in JavaScript engine testing in the existing technology and improves the Syntax correctness and security of test cases.

CN112685314BActive Publication Date: 2024-11-26WUHU MANXIU TECHNOLOGY CO LTD
View PDF 14 Cites 0 Cited by

Patent Information

Application Number
CN202110006727.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-01-05
Publication Date
2024-11-26
Estimated Expiration
2041-01-05

AI Technical Summary

Technical Problem

The existing technology has problems with high syntax error rate and low security in JavaScript engine testing. Especially in black box testing scenarios, it is difficult to generate test cases with high syntax accuracy and high security.

Method used

Using a syntax analysis-based method, combining recurrent neural network (RNN) and variational autoencoder (VAE), a corpus is generated through syntax parsing, and a recurrent neural network variational autoencoder is trained to generate new corpus and assemble it into new test cases. Used to perform security testing on JavaScript engines.

Benefits of technology

It realizes test case generation with high syntax accuracy and diversity, improves the security of the JavaScript engine, ensures the syntax accuracy and security of the test cases, and is suitable for secure scanning of the JS engine.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112685314B_ABST
    Figure CN112685314B_ABST
Patent Text Reader

Abstract

The present invention relates to a JavaScript engine security testing method and testing system, and relates to the field of computer network industry security, in order to solve the problem of low security of JS engine testing. The testing method comprises: obtaining JavaScript test cases; parsing the test cases to generate a corpus; using the corpus to build and train a recurrent neural network variational autoencoder; using the trained recurrent neural network variational autoencoder to process latent variables to generate new corpus; assembling the new corpus into new test cases; and using the new test cases to perform security testing on the system. Using the present invention, new JavaScript test cases with high grammatical accuracy can be efficiently generated to perform security scanning on the JS engine.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer network industry security, and in particular to a JavaScript engine security testing method and testing system based on syntax analysis technology and variational autoencoder. Background Art

[0002] As the main entrance to the Internet, browser security vulnerabilities may cause information and property losses to many individuals and organizations. According to the statistics of the National Vulnerability Database (NVD) of the United States in 2017, 43% of browser vulnerabilities can be attributed to the browser's built-in JavaScript engine (JS engine for short; it is a program used to execute JavaScript code in web pages). Therefore, testing the browser's JS engine and improving its security factor is crucial to building a secure Internet environment.

[0003] The main browser JS engines include SpiderMonkey (Firefox browser), V8 (Chrome browser; also the new engine of Edge browser, and the engine of node.js), JavaScriptCore (Safari browser) and Chakra (formerly used in Edge browser; security updates end on 2020 / 03 / 09).

[0004] Software security testing technology is divided into three categories according to the degree of information about the target software: white box (source code can be obtained), gray box (no code, but the internal structure of the software can be partially understood based on the documentation) and black box (only binary files). White box testing has the most testing methods available, and there are also tools that have been proven effective in practice, such as AFL (American Fuzzy Lop). However, in most scenarios, users can only obtain binary files. Black box testing technology has a wider range of application scenarios, so the present invention discusses a black box testing system.

[0005] According to the generation method of test cases (input information provided to the target software), existing security testing methods can be divided into two categories: random and structural. In the JS engine testing scenario, the random method refers to randomly generating JS code with different content and length, or randomly modifying the normal JS code and providing it as input to the JS engine. The structural method refers to modifying existing code files or generating new code files with the help of explicit code construction rules, or using implicit structural rules extracted from large amounts of data by neural network learners.

[0006] The random method can theoretically cover all vulnerabilities, but for test cases with complex structures such as JS code, most of the randomly generated or modified files will be rejected by the JS engine during the syntax check phase due to syntax errors, and cannot trigger the deep logic of the engine, making it practically infeasible. The structural method makes the scanning efficiency high because it ensures that the syntax check passes as much as possible, but if the grammar rules or learners are too accurate, omissions may occur. Therefore, a JavaScript engine security testing method with high syntax accuracy and high security is urgently needed. Summary of the invention

[0007] The purpose of the present invention is to provide a JavaScript engine security testing method and testing system, which, based on grammatical analysis, combines the learning ability of RNN (Recurrent Neural Network) for indefinite length sequences and the diversity of VAE (Variational Auto-Encoder) outputs to generate test cases with high grammatical accuracy, high security and diversity.

[0008] To achieve the above object, the present invention provides the following solutions:

[0009] Get JavaScript test cases;

[0010] Performing grammatical analysis on the test case to generate a corpus;

[0011] Using the corpus to build and train a recurrent neural network variational autoencoder to obtain a trained recurrent neural network variational autoencoder;

[0012] Using the trained recurrent neural network variational autoencoder to process latent variables to generate new corpus, the latent variables are input random variables;

[0013] Assembling the new corpus into new test cases;

[0014] The new test case is used to perform security testing on the system.

[0015] The present invention also provides a testing system corresponding to the JavaScript engine security testing method, the system comprising:

[0016] A test case acquisition module is used to acquire test cases;

[0017] A syntax analysis module, used for performing syntax analysis on the test case and generating a corpus;

[0018] A variational learner module, used for training a learner and generating new corpus based on the corpus;

[0019] A corpus assembly module, used to assemble the new corpus output by the learner to obtain a new test case;

[0020] The scanning and monitoring module is used to input the new test case into the JavaScript engine and monitor whether the behavior of the new test case is abnormal.

[0021] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:

[0022] The present invention provides a JavaScript engine security testing method and a testing system, which can solve the problem of low security of JavaScript engine testing in the prior art. Specifically, on the basis of grammatical analysis, combined with the learning ability of a recurrent neural network for indefinite-length sequences and the diversity advantages of a variational autoencoder output, a new JavaScript test case with high grammatical correctness and indefinite length can be efficiently generated. The test case is used to perform a security scan on the JS engine, which meets the requirements of JS engine security testing. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0024] Figure 1 A flowchart of a JavaScript engine security testing method provided in Embodiment 1 of the present invention;

[0025] Figure 2 This is a schematic diagram of the structure of the recurrent neural network variational autoencoder training phase provided in the first embodiment of the present invention;

[0026] Figure 3 A schematic diagram of the structure of the new corpus generation stage of the recurrent neural network variational autoencoder provided in the first embodiment of the present invention;

[0027] Figure 4 This is a schematic diagram of the structure of the JavaScript engine security testing system provided in the second embodiment of the present invention.

[0028] Explanation of symbols: 201: test case acquisition module; 202: syntax analysis module; 203: variational learner module; 204: corpus assembly module; 205: scanning and monitoring module. DETAILED DESCRIPTION

[0029] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0030] The purpose of the present invention is to provide a JavaScript engine security testing method and testing system. On the basis of grammatical analysis, the learning ability of RNN (Recurrent Neural Network) for indefinite length sequences and the diversity of VAE (Variational Auto-Encoder) output are combined to generate test cases with high grammatical accuracy, high security and diversity. The test cases are used to test the JS engine, which can improve the security of the system.

[0031] An ideal scanning system can generate as many diverse test cases as possible that are rarer than regular inputs while ensuring a high grammatical correctness. To ensure grammatical correctness, the system is required to have prior grammatical knowledge or the ability to learn grammatical knowledge. To this end, AST (Abstract Syntax Tree) can be considered as the basic data structure of the entire system. As a tree data structure parsed from the code file, AST eliminates characters in the code that are useless for analysis (brackets, line breaks, spaces, etc.), and expresses the code logic with nodes (containing all attribute information such as the name and type of each element) and tree structures (reflecting the order of calculation), which is easier to perform grammatical analysis than the source code itself. Parse the JS code into AST, and use the elements in the tree as training data. With the help of the strong representation ability of the neural network learner, the system can learn the correct grammatical structure, and then generate new test cases on this basis.

[0032] The common methods of using neural networks to generate test cases are various types of RNN (Recurrent Neural Network); this is because RNN is suitable for processing serialized data of indefinite length. However, since RNN predicts word by word (predicts the second word based on the given first word, and then predicts the third word based on the existing two words, and so on), it does not attempt to learn global features (syntax, grammar, the topic being discussed, etc.), which leads to the problem that the generated new test cases are prone to syntactic or grammatical errors.

[0033] VAE (Variational Auto-Encoder) consists of three parts: encoder, sampler and decoder. With the help of some simplified assumptions (global features expressed as "hidden variables" conform to simple statistical distributions, such as independent Gaussian distributions in each dimension), VAE can realize the encoding of global features of data (encoder), sample in the encoding space (sampler), and generate new data through the decoding process (decoder). As an approximate inference tool, variational methods are difficult to accurately learn the distribution characteristics of the original data; however, this problem is manifested as more diversified outputs in security testing scenarios, which is an advantage. VAE, which uses RNN as a component, can combine the advantages of both to generate new, grammatically correct, and indefinite length test cases to meet the needs of JS engine security testing.

[0034] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0035] Embodiment 1

[0036] See also Figure 1 , a JavaScript engine security testing method provided in this embodiment includes:

[0037] S1. Get JavaScript test cases;

[0038] The input data of the present invention is a test case. The data set selected in this embodiment is the JavaScript code obtained from Github (https: / / www.sri.inf.ethz.ch / js150) and the ECMAScript test set Test262 (https: / / github.com / tc39 / test262).

[0039] S2, parse the test case to generate a corpus;

[0040] The syntax parsing part can be divided into three steps: renaming, parsing and conversion.

[0041] 1) Renaming means renaming the variables and the function names for each test case according to the order in which the variables and the function names appear in the test case to obtain a renamed test case;

[0042] In order to enable the model to generate the second half of the sequence based on the first half of the sequence, or generate a new sequence from scratch, the model is required to learn the general rules of the order of the code. However, the training data comes from different projects and there is no unified rule for the naming of the corpus. Therefore, the variables and function names are renamed according to the order in which they appear in the test cases. Specifically, for any test case file, the first variable that appears in the code is renamed to v0, the second to v1, and so on; the first function that appears in the code is uniformly renamed to f0, the second to f1, and so on.

[0043] 2) Parsing refers to parsing each of the renamed test cases into an AST (Abstract Syntax Tree);

[0044] 3) Conversion: Decompose the abstract syntax tree into a sequence of basic syntax elements, recorded as a side corpus sequence.

[0045] Specifically, the tree-like AST is decomposed into a sequence of basic grammatical elements, called a "corpus sequence". The AST is decomposed into edges formed by node types and node attributes, and stored as an "edge corpus sequence" (hereinafter referred to as "edge sequence") in a preset traversal order (such as pre-order depth first). Each test case corresponds to such an edge sequence.

[0046] At this point, the syntax parsing part is completed, and an edge sequence is obtained (as the "corpus" required for subsequent steps), and the edge sequence is the input sequence of the training variational autoencoder.

[0047] S3, using the corpus to build and train a recurrent neural network variational autoencoder to obtain a trained recurrent neural network variational autoencoder;

[0048] Specifically, build and train an RNN variational autoencoder. For the structure, please refer to Figure 2 First, we borrow the idea of ​​word embedding, and convert the edge sequence into a continuous variable by passing it through a corpus embedding layer in turn and according to the correspondence between numbers and strings in the corpus embedding layer (embedding layer); after the corpus embedding layer, there is an encoder composed of a single-layer RNN, that is, the continuous variable is input into the encoder composed of a single-layer recurrent neural network to output the distribution parameters of the latent variable (such as the expectation and variance of the Gaussian distribution), and the latent variable is sampled according to this distribution parameter to obtain a multidimensional variable; the multidimensional variable is input into the decoder composed of a single-layer RNN; the decoder outputs a digital sequence, which needs to go through the translation step to translate the digital sequence into a string sequence. The translation process uses the correspondence between (numbers and strings) determined in the corpus embedding process. That is, the output sequence is a string sequence.

[0049] During the training phase, the edge sequence (after word embedding transformation) is input at each time step of the encoder and decoder. The loss function L is minimized by adjusting the model parameters of the recurrent neural network variational autoencoder.

[0050] L=∑ (x,y) l(x,y) (1)

[0051] Among them, ∑ (x,y) represents the sum of the entire set of training data, and l(x,y) is the loss function for each piece of data:

[0052] l(x,y)=a·l type (x,y)+l name (x,y) (2)

[0053] l type =-∑ j (T j true * log(T j pred )) (3)

[0054] l type and l name They represent the prediction error of node type and node attribute respectively. When the prediction is completely consistent with the actual situation, l is zero, otherwise l is greater than zero;

[0055] a is an adjustable parameter used to adjust the weight of the prediction error degree of the node type and the prediction error degree of the node attribute. If the weight of the prediction error degree of the node attribute needs to be increased, a is increased; if the weight of the prediction error degree of the node type needs to be increased, a is decreased;

[0056] ∑ j represents the sum of all the node types, T j pred is the predicted node type, T j true is the actual node type;

[0057] l name =-∑ i (N i true * log(N i pred )) (4)

[0058] ∑ i Indicates the sum of all the node attributes, N i pred is the predicted node attribute, N itrue The actual node attributes.

[0059] S4. Processing latent variables using the trained recurrent neural network variational autoencoder to generate new corpus, wherein the latent variables are input random variables;

[0060] See also Figure 3 , in the stage of generating new corpus, starting from latent variable sampling, specifically, inputting the latent variable into the trained recurrent neural network variational autoencoder for sampling to obtain multi-dimensional variables;

[0061] The multidimensional variable is input into a decoder composed of a single-layer recurrent neural network to output a digital sequence;

[0062] According to the correspondence between numbers and strings determined by the corpus embedding layer, the number sequence is translated into a string sequence, that is, a new edge sequence is obtained.

[0063] S5, assembling the new corpus into a new test case;

[0064] Specifically, the side corpus sequence is composed into an abstract syntax tree according to the preset traversal order, and the abstract syntax tree is restored to JavaScript code using an escodegen tool.

[0065] S6. Perform security testing on the system using the new test case.

[0066] A JavaScript engine security testing method designed in this embodiment parses the test case into an AST (abstract syntax tree) and uses the elements in the tree as training data. With the help of the strong representation ability of the neural network learner, the system can learn the correct grammatical structure and improve the grammatical accuracy, and then generate new test cases on this basis. In the method of generating test cases using neural networks, a combination of RNN (recurrent neural network) and VAE (variational autoencoder) is adopted, which can combine the learning ability of RNN for indefinite length sequences and the diversity of VAE outputs, thereby generating high grammatical accuracy and diverse test cases. Using this test case to test the system can improve the security of the system.

[0067] Embodiment 2

[0068] In view of the above method, the present invention also discloses a JS engine security testing system based on a syntax analyzer and a variational learner, please refer to Figure 4 , the system comprising:

[0069] The test case acquisition module 201 is used to acquire test cases.

[0070] The syntax analysis module 202 is used to perform syntax analysis on the test case and generate a corpus. The tool used to parse the code into AST is esprima.

[0071] The variational learner module 203 is used to train the learner and generate new corpus according to the corpus. The hardware information used by the learner is: graphics card Tesla V100 (single core), processor Intel Xeon CPU2.00GHz, memory 25GB.

[0072] The corpus assembly module 204 is used to assemble the new corpus output by the learner to obtain new test cases. The tool used to generate code from AST is escodegen.

[0073] The scanning and monitoring module 205 is used to input the test case into the JS engine and monitor whether its behavior is abnormal. More specifically, the JS engine (such as a pre-compiled SpiderMonkey binary file) is called to run the new test case and capture the standard error (stderr); if an error (such as SIGSEGV) occurs during the operation, it will be displayed that the new test case has located an error (bug), record it and continue the test; if no error is reported during the operation, the test will continue.

[0074] As for the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method part.

[0075] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of ​​the present invention. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A JavaScript engine security testing method, characterized in that: The method comprises: Get JavaScript test cases; Performing grammatical parsing on the test case to generate a corpus; performing grammatical parsing on the test case to generate a corpus specifically includes: Renaming: for each of the test cases, renaming the variable and the function name according to the order in which the variable and the function name appear in the test case to obtain a renamed test case; Parsing: Parsing each of the renamed test cases into an abstract syntax tree; Conversion: decomposing the abstract syntax tree into a sequence of basic syntax elements, recorded as a side corpus sequence; decomposing the abstract syntax tree into a sequence of basic syntax elements, recorded as a side corpus sequence specifically includes: Decomposing the abstract syntax tree into edges; wherein the edges are formed by nodes having node types and node attributes; The edges are stored as edge corpus sequences according to a preset traversal order; the edge corpus sequences are input data of a recurrent neural network variational autoencoder; Using the corpus to build and train a recurrent neural network variational autoencoder to obtain a trained recurrent neural network variational autoencoder; using the corpus to build and train a recurrent neural network variational autoencoder specifically includes: Input the side corpus sequence into the corpus embedding layer and convert it into a continuous variable according to the correspondence between numbers and strings; Inputting the continuous variable into an encoder composed of a single-layer recurrent neural network to obtain distribution parameters of latent variables; Sampling the latent variable according to the distribution parameter to obtain a multidimensional variable; Input the multidimensional variable into a decoder composed of a single-layer recurrent neural network and then output a digital sequence; According to the correspondence between numbers and strings determined by the corpus embedding layer, the number sequence is translated into a string sequence; Using the trained recurrent neural network variational autoencoder to process latent variables to generate new corpus; the latent variables are input random variables; Assembling the new corpus into new test cases; The new test case is used to perform security testing on the system.

2. The JavaScript engine security testing method according to claim 1, characterized in that: The step of obtaining the trained recurrent neural network variational autoencoder specifically includes: adjusting the model parameters of the recurrent neural network variational autoencoder so that the loss function L is minimized; L=∑ (x,y) l(x,y)(1) Among them, ∑ (x,y) represents the sum of the entire set of training data, and l(x,y) is the loss function for each piece of data: l(x,y)=a·l type (x,y)+l name (x,y) (2) l type =-∑ j (T j true * log(T j pred ))(3) l type and l name They represent the prediction error of node type and node attribute respectively. When the prediction is completely consistent with the actual situation, l is zero, otherwise l is greater than zero; a is an adjustable parameter used to adjust the weight of the prediction error degree of the node type and the prediction error degree of the node attribute. If the weight of the prediction error degree of the node attribute needs to be increased, a is increased; if the weight of the prediction error degree of the node type needs to be increased, a is decreased; ∑ j represents the sum of all the node types, T j pred is the predicted node type, T j true is the actual node type; L name =-∑ i (N i true * log(N i pred ))(4) ∑ i Indicates the sum of all the node attributes, N i pred is the predicted node attribute, N i true The actual node attributes.

3. The JavaScript engine security testing method according to claim 1, characterized in that: The processing of latent variables by using the trained recurrent neural network variational autoencoder to generate new corpus specifically includes: Inputting the latent variable into the trained recurrent neural network variational autoencoder for sampling to obtain a multidimensional variable; The multidimensional variable is input into a decoder composed of a single-layer recurrent neural network to output a digital sequence; According to the correspondence between numbers and character strings determined by the corpus embedding layer, the number sequence is translated into a character string sequence.

4. The JavaScript engine security testing method according to claim 1, characterized in that: The assembling of the new corpus into a new test case specifically includes: Composing the side corpus sequence into an abstract syntax tree according to the preset traversal order; The abstract syntax tree is restored to JavaScript code using the escodegen tool.

5. A test system corresponding to a JavaScript engine security test method according to any one of claims 1 to 4, characterized in that: The system comprises: A test case acquisition module is used to acquire test cases; A syntax analysis module, used for performing syntax analysis on the test case and generating a corpus; A variational learner module, used for training a learner and generating new corpus based on the corpus; A corpus assembly module, used to assemble the new corpus output by the learner to obtain a new test case; The scanning and monitoring module is used to input the new test case into the JavaScript engine and monitor whether the behavior of the new test case is abnormal.

6. The test system corresponding to the JavaScript engine security test method according to claim 5 is characterized in that: The tool for parsing the test case is esprima.

7. The test system corresponding to the JavaScript engine security test method according to claim 5 is characterized in that: The scanning and monitoring module is specifically used for: Calling the JavaScript engine to run the new test case; If an error occurs during the run, it will be displayed that the new test case has located an error, record it and continue the test; If no error is reported during the run, continue testing.

Citation Information

Patent Citations

  • Test case generation method restrained by context-free grammar

    CN102141959A

  • Intelligent detection method for Java script malicious code facing to the webpage

    CN102663296A

  • Detecting method of browser extension loophole based on behavior sequence

    CN103971054A

  • A browser fuzzy test method based on AST mutation

    CN109446079A

  • Test flow determination method and device applied to website

    CN110334023A