Vulnerability detection method and device, electronic equipment and storage medium
Through the backtracking and control flow graph analysis of the target function parameters in the code, the problem of low vulnerability detection accuracy in the existing technology is solved, and more efficient vulnerability detection and stronger security are achieved.
Patent Information
- Application Number
- CN202311451802.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-02
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2043-11-02
AI Technical Summary
The existing technology has low accuracy in code vulnerability detection, making it difficult to promptly discover and resolve security risks in application systems, such as SQL injection, cross-site scripting attacks, and buffer overflow vulnerabilities.
By obtaining the parameters of the target function in the code to be detected, backtracking is performed to determine the source of the parameters. Combined with Lex and Yacc analysis and control flow graph analysis, it is determined whether there are loopholes in the code and improves the accuracy of vulnerability detection.
It improves the accuracy of vulnerability detection, reduces false positives and false negatives, enhances the detection capabilities of common vulnerabilities, and improves the security of application systems.
Smart Images

Figure CN118821135A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of network security technology, and in particular to a vulnerability detection method, device, electronic device and storage medium. Background Art
[0002] In the process of application system design and development, due to factors such as imperfect development specifications, inadequate implementation, and uneven technical levels of developers, it is easy to cause security vulnerabilities in the developed code, such as common Structured Query Language (SQL) injection vulnerabilities, Cross Site Scripting (CSS) vulnerabilities, buffer overflow vulnerabilities, and sensitive information leakage vulnerabilities in configuration files, etc. If these vulnerabilities are not discovered and properly resolved in a timely manner, they will bring great security risks to the application system after it goes online.
[0003] In terms of the discovery and detection of code vulnerabilities, related technologies manually search for vulnerabilities in the code, and the accuracy of vulnerability detection is low. Summary of the invention
[0004] The present disclosure provides a vulnerability detection method, device, electronic device and storage medium.
[0005] According to a first aspect of the present disclosure, a vulnerability detection method is provided, the method comprising: obtaining a code to be detected;
[0006] When there is a target function in the code to be detected, backtrack the parameters of the target function to obtain a backtracking result, and determine whether there is a vulnerability in the code to be detected based on the backtracking result.
[0007] According to a second aspect of the present disclosure, a vulnerability detection device is provided, the device comprising: an acquisition module, used to acquire a code to be detected; a detection module, used to backtrack the parameters of the target function when there is a target function in the code to be detected, obtain a backtracking result, and determine whether the code to be detected has a vulnerability based on the backtracking result.
[0008] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the program, the method described above is implemented.
[0009] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the above method of the present disclosure is implemented.
[0010] The vulnerability detection method, device, electronic device and storage medium provided by the embodiments of the present disclosure obtain the code to be detected; when there is a target function in the code to be detected, the source of the parameters is determined by backtracing the parameters of the target function, and whether there is a vulnerability in the code to be detected is further determined, thereby improving the accuracy of vulnerability detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Further details, features and advantages of the present disclosure are disclosed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:
[0012] Figure 1 A flowchart of a vulnerability detection method provided for an exemplary embodiment of the present disclosure;
[0013] Figure 2 A schematic block diagram of functional modules of a vulnerability detection device provided by an exemplary embodiment of the present disclosure;
[0014] Figure 3 A structural block diagram of an electronic device provided for an exemplary embodiment of the present disclosure;
[0015] Figure 4 A structural block diagram of a computer system provided for an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0016] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0017] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0018] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions of other terms will be given in the description below. It should be noted that the concepts of "first", "second", etc. mentioned in this disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0019] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0020] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0021] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.
[0022] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.
[0023] As an optional but non-limiting implementation, in response to receiving an active request from the user, the method of sending a prompt message to the user may be, for example, a pop-up window, in which the prompt message may be presented in text. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device. It is understandable that the above notification and the process of obtaining user authorization are only illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet relevant laws and regulations may also be applied to the implementation of the present disclosure.
[0024] The present disclosure provides a vulnerability detection method, which is as follows:
[0025] First, we collect enough common defect patterns from code analysis experience, abstractly form a rule base for different vulnerability types, pre-sort out the functions that can cause harm, namely sink functions, in the scanning engine, and locate all places where the harmful functions appear in the code. Then, based on Lex (Lexical Analyzer Generator) and Yacc (Yet another compiler compiler), we parse the corresponding source code into AST (Abstract Syntax Tree), backtrack based on the abstract syntax tree, and analyze whether the parameters of the harmful function are controllable to determine whether there is a vulnerability.
[0026] Among them, this method includes two detection methods. One is to detect the code by string matching static code text (regular matching mode), which can find relatively simple vulnerabilities such as hard coding, using unsafe random number functions or using unsafe encryption algorithms; the other is to locate the sink function, trace back its parameters, and determine whether the parameters are controllable (parameter controllable mode), so as to determine whether there is a vulnerability. This method can find vulnerabilities such as SQL injection and command injection. By using the two detection modes together, most common vulnerability types can be detected.
[0027] In one possible implementation, the scanning engine is written in Python. The engine implements processes such as rule preprocessing (classifying rules), finding sink functions, and backtracking parameters. It uses the pure Python library javalang dedicated to processing Java source code. Javalang provides a lexical analyzer and parser for Java8.
[0028] The rule base is written in XML language. The vulnerability information comes from the public CVE and the principle of vulnerability generation. A rule contains the following information: vulnerability name (name), programming language (language), scanning mode (match), taint function (sinks), danger level (level), code example (test), and the corresponding matching rules are set according to the scanning mode. In addition, in addition to the single rule for each vulnerability, a general Source function table is established. The table contains functions used in WEB application development to obtain various types of information from the front end, such as the get Parameter() function. The engine needs to continuously call the Source file during the scanning process to determine whether the vulnerability exists.
[0029] The steps to detect the code are as follows:
[0030] After the scan starts, the scanning engine reads the rule base one by one to determine which scanning mode the current rule should adopt. If it is a regular matching mode, it will only match the code content based on the regular expression in the rule. If it can match the result, it is considered that there is a vulnerability in the code. If the current rule is a parameter controllable mode, the parameter controllable mode scan will be performed.
[0031] In a possible implementation, when performing parameter-controllable mode scanning, it is detected whether there is a sink function in the code. If there is a sink function, the parameters of the sink function are backtracked.
[0032] When a sink function is detected in a custom function in the code, the parameters of the sink function inside the custom function are backtracked with the function declaration as the boundary. If the source function can be backtracked inside the custom function, the parameters are determined to be user-controllable and the vulnerability is confirmed. If there is still no source function when backtracking to the function declaration, it is impossible to determine whether the vulnerability exists. It is necessary to detect whether the parameters of the custom function contain the parameters of the sink function. If not, stop the backtracking and the vulnerability does not exist. If it is contained, it indicates that the custom function may be called elsewhere and cause the vulnerability. Therefore, it is necessary to add the custom function to the original sink function list, relocate the sink point, and backtrack the parameters.
[0033] In one possible implementation, there may be functions with the same name in different codes, which may lead to a large number of false positives. Therefore, when adding a custom function to the initial sink function list, the custom function is renamed based on the file package where the custom function is located, so that the name of each sink function remains unique. The above process is repeated for multiple layers of calls until all sink functions and their parameters are traced back.
[0034] In the process of backtracking the parameters of the sink function, the corresponding source code is parsed into AST based on Lex and Yacc, and backtracking is performed based on the abstract syntax tree. When program control blocks such as jumps, loops, and branches are detected, CFG (Control Flow Graph) analysis is introduced. Among them, the control flow analysis uses the soot framework to convert the code into IR (Intermediate Representation). Soot uses a Body to represent the code of a method block, and each Body generates a control flow graph according to the Backward Flow Analysis analysis mode. Each node and its predecessor and successor nodes are stored in the control flow graph, which can be formally expressed as:
[0035] Front drive
[0036]
[0037] Successor
[0038]
[0039] Where b represents the current node, Pred(b) represents the predecessor node of node b, N represents all nodes in the basic block where b is located, and E represents all flows in the basic block. Predecessor nodes refer to other nodes that flow to the current node b, and successor nodes refer to other nodes that flow from the current node b. It means that there is a node n belonging to N, and the flow direction e belongs to E, where the direction of e is from n to b, then node n is the predecessor node of b. It means that there is a node n belonging to N, and the flow e belongs to E, where the direction of e is from b to n, then node n is the successor node of b.
[0040] If a basic block with a control statement is encountered during the backtracking process, the predecessor and successor nodes of the basic block are first identified, and then the flow direction of the nodes inside the corresponding block is found through the Directed Graph interface of soot, so as to list all the jumps, loops, and branches inside the block one by one, and backtrack one by one. Finally, whether there is a vulnerability is determined by judging whether the parameters of the sink function are controllable.
[0041] Through the above method, it is possible to detect whether there is a sink function in the code. When there is a sink function in the code, the parameters of the sink function are backtraced, and when a control statement is detected, a control flow graph is generated based on the control statement, and then each branch of the control statement is backtraced, thereby reducing false positives and missed positives of vulnerabilities and improving the accuracy of vulnerability detection. In addition, control flow analysis is introduced only when a control statement is detected, thereby improving the efficiency of vulnerability detection.
[0042] Based on the above embodiments, in another embodiment provided by the present disclosure, a vulnerability detection method is also provided, such as Figure 1 As shown, the method may include the following steps:
[0043] In step S100, a code to be detected is obtained.
[0044] In step S200, when there is a target function in the code to be detected, backtraces are performed on the parameters of the target function to obtain a backtracing result, and based on the backtracing result, it is determined whether there is a vulnerability in the code to be detected.
[0045] Among them, the target function is the sink function, and the sink function is a function that may trigger security issues, such as the eval function in the PHP language, the run function in the Java language, etc.
[0046] In one possible implementation, the sink function may consist of a package name, a class name, a return value, a function name, parameters, an infected location, and a vulnerability type.
[0047] Through the above method, when the target function exists in the code to be detected, the parameters of the target function can be backtracked to determine the source of the parameters, and further determine whether the code to be detected has a vulnerability, thereby improving the accuracy of vulnerability detection.
[0048] In order to more clearly illustrate the present disclosure, based on the above embodiment, the above step S200 further includes:
[0049] In step S210, when there is a control statement in the code to be detected, control flow information is generated based on the control statement to determine multiple control branches corresponding to the control statement, and each of the multiple control branches is traversed for backtracing.
[0050] Among them, control flow information includes control flow graphs. A control flow graph is an abstract representation of a process or program, representing all paths that will be traversed during the execution of a program. It uses a graph to represent the possible execution directions of all basic blocks within a process, and can also reflect the real-time execution process of a program.
[0051] In a possible implementation, when a control statement is detected during the backtracking of the parameters of the target function, control flow analysis is introduced. The control flow analysis uses the soot framework to convert the code into an intermediate representation. Soot uses a Body to represent the code of a method block, and each Body generates a control flow graph according to the Backward Flow Analysis analysis mode.
[0052] Through the above method, when a control statement is detected during the backtracing process, a control flow graph can be generated based on the control statement, and then each branch of the control statement can be backtraced to avoid missing certain conditional branches and causing false positives or negatives of vulnerabilities, thereby improving the accuracy of vulnerability detection. In addition, control flow analysis is introduced only when a control statement is detected, thereby improving the efficiency of vulnerability detection.
[0053] In order to explain the present disclosure more clearly, based on the above embodiment, the above method further includes the following steps:
[0054] In step S300, when the source function corresponding to the target function is not traced back, it is determined whether the parameters of the first function to which the target function belongs include the parameters of the target function.
[0055] The source function is a source function, which is a function that can be manually input into the program. The source function is composed of a package name, a class name, a return value, a function name, and a parameter identifier. The first function is a function of the target function in the code to be detected. It can be a function customized by the user during coding or other functions. The present disclosure does not limit the type of the first function.
[0056] In one possible implementation, when the source function corresponding to the parameters of the sink function is not backtracked and the parameters of the first function do not include the parameters of the sink function, it means that there is no vulnerability in the first function in the code to be detected, and the backtracking is stopped.
[0057] In step S400, when the parameters of the first function include the parameters of the target function, the first function is used as a new target function and added to the target function list.
[0058] Among them, the target function list is the initial sink function list.
[0059] In one possible implementation, if a sink function exists in the first function but the source function corresponding to the sink function is not traced back, it is determined whether the parameters of the first function contain the parameters of the sink function. If so, it indicates that the first function may be called elsewhere and cause a vulnerability. Therefore, the first function is used as a new sink function and added to the initial sink function list.
[0060] Among them, when adding a new sink function to the initial sink function list, the function name of the new sink function and the file information thereof are obtained, and the file information includes the file package name. The new sink function is named based on the function name and the file package name. For example, the new sink function can be named in the form of "file package name" + "function name". In the subsequent scanning process, the first function is searched and backtraced in the full code. When searching for the first function, the import package name of the file that calls the first function and whether the content of the file that calls the first function contains the function name are automatically analyzed. Optionally, when there are multiple levels of calling relationships, the first function is searched and backtraced in a loop until all values of the first function in the initial sink function list have been searched and backtraced.
[0061] Through the above implementation, when there is a target function but the corresponding source function is not traced back, the function to which the target function belongs is used as a new target function and added to the target function list. In subsequent detection, vulnerabilities caused by functions containing the target function being called by different files can be found, further improving the accuracy of vulnerability detection. In addition, when a new target function is added to the target function list, the new sink function can be named based on the function name of the new sink function and the file package name to which it belongs, so that the sink function name in the initial sink function list remains unique, reducing the problem of false positives caused by the same function name.
[0062] In order to explain the present disclosure more clearly, based on the above embodiment, the above step S210 also includes:
[0063] In step S2101, a predecessor node and a successor node of the control statement are obtained, and flow direction information between the predecessor node and the successor node is determined, and multiple control branches corresponding to the control statement are determined based on the flow direction information.
[0064] In one possible implementation, the control flow graph stores each node in the control statement and its predecessor and successor nodes, which can be formally expressed as:
[0065] Front drive
[0066]
[0067] Successor
[0068]
[0069] Where b represents the current node, Pred(b) represents the predecessor node of node b, N represents all nodes in the basic block where b is located, and E represents all flows in the basic block. Predecessor nodes refer to other nodes that flow to the current node b, and successor nodes refer to other nodes that flow from the current node b. It means that there is a node n belonging to N, and the flow direction e belongs to E, where the direction of e is from n to b, then node n is the predecessor node of b. It means that there is a node n belonging to N, and the flow e belongs to E, where the direction of e is from b to n, then node n is the successor node of b.
[0070] After determining the predecessor and successor nodes of a control statement, you can use Soot's Directed Graph interface to find the flow between the nodes within the control statement basic block, so that all jumps, loops, and branches within the basic block can be listed one by one and backtracked one by one.
[0071] In order to explain the present disclosure more clearly, based on the above embodiment, the above method further includes the following steps:
[0072] In step S500, an abstract syntax tree is constructed based on the code to be detected.
[0073] Exemplarily, the code to be tested is parsed into functions, basic blocks, expressions, and operands. Functions include main functions and other functions, and expressions include operands and operators. Specifically, the code to be tested is divided into a main function and a set of other functions. Each function (Func for short) is composed of a basic block (Block for short); the basic block contains statements that are executed sequentially, and each statement is called an expression, Op for short; in each expression, there are different variables and operators, and each variable is called an operand, Operand for short. Therefore, for any code of a Web application, four objects, Func, Block, Op, and Operand, are parsed.
[0074] Multiple Blocks form Func, Block links to all Ops under the basic block, and each Op links to multiple Operands, eventually connecting the entire Web application code. For each variable Operand used, its defined Op can be found, so Operand can be connected to its effective definition, that is, add Ops attributes to Operand to point to the Op that defines this variable; then, through the open source PHP-Parser, the operands of the expression are used as the leaves of the tree structure, and the operation symbols of the expression are used as the roots of the tree structure, and the abstract syntax tree is constructed in a loop and iteration.
[0075] Exemplarily, the basic blocks constituting the function are linked to the corresponding expressions; the expressions are linked to the corresponding operands; based on PHP-Parser, the operands are taken as leaves of the tree structure, and the operators are taken as roots of the tree structure, and the abstract syntax tree is constructed in a loop and iteration.
[0076] In step S600, the parameters of the target function are backtracked based on the abstract syntax tree.
[0077] In a possible implementation, all nodes, declarations, and assignment relationships in the code are obtained based on the abstract syntax tree, each node in the abstract syntax tree is traversed, and backtracking is performed based on the assignment relationship of the variables corresponding to the parameters.
[0078] In order to more clearly illustrate the present disclosure, based on the above embodiment, the above method further includes:
[0079] In step S700, when tracing back to the source function corresponding to the parameter of the target function, it is determined that there is a vulnerability in the code to be detected.
[0080] Optionally, when it is determined that the code to be detected has a vulnerability, vulnerability alert information is generated, wherein the vulnerability alert information may include the name of the sink function that causes the vulnerability, the location of the vulnerability, and file information that calls the function.
[0081] Through the method provided by the present disclosure, the code to be detected can be obtained. When there is a target function in the code to be detected, the parameters of the target function are backtracked. In the process of backtracking the target parameters, when a control statement is detected, control flow analysis is introduced, and each branch of the control statement is backtracked based on the control flow graph, so as to avoid missing certain branches in the backtracking process and causing missed vulnerabilities or false positive vulnerabilities, thereby improving the accuracy of vulnerability detection. In addition, when there is a target function but it is not backtracked to the corresponding source function, the function to which the target function belongs is used as a new target function and added to the target function list. In subsequent detections, vulnerabilities caused by the function containing the target function being called by different files can be found, further improving the accuracy of vulnerability detection.
[0082] In the case of dividing each functional module according to each function, an embodiment of the present disclosure provides a vulnerability detection device, which may be a server or a chip applied to a server. Figure 2 This is a schematic block diagram of the functional modules of a vulnerability detection device provided by an exemplary embodiment of the present disclosure. Figure 2 As shown, the vulnerability detection device includes:
[0083] The acquisition module 201 is used to acquire the code to be detected.
[0084] The detection module 202 is used to backtrack the parameters of the target function when there is a target function in the code to be detected, obtain a backtracking result, and determine whether there is a vulnerability in the code to be detected based on the backtracking result.
[0085] In a possible implementation, the device further includes: a determination module for generating control flow information based on control statements when there are control statements in the code to be detected, so as to determine multiple control branches corresponding to the control statements, and traverse each of the multiple control branches for backtracking.
[0086] In a possible implementation, the detection module 202 is also used to: when the source function corresponding to the target function is not traced back, determine whether the parameters of the first function to which the target function belongs include the parameters of the target function; when the parameters of the first function include the parameters of the target function, take the first function and the file package name to which it belongs as a new target function and add them to the target function list.
[0087] In a possible implementation, the acquisition module 201 is further used to: acquire the file package name to which the function name of the first function belongs, and the above-mentioned device also includes: a naming module, which is used to name the new target function based on the function name and the file package name.
[0088] In a possible implementation, the determination module is further used to obtain a predecessor node and a successor node of the control statement, determine flow information between the predecessor node and the successor node, and determine multiple control branches corresponding to the control statement based on the flow information of the nodes.
[0089] In a possible implementation, the apparatus further includes a construction module, configured to construct an abstract syntax tree based on the code to be detected; the detection module 202 is further configured to backtrack parameters of the target function based on the abstract syntax tree.
[0090] In a possible implementation, the detection module 202 is further configured to: determine whether a vulnerability exists in the code to be detected when tracing back to a source function corresponding to a parameter of the target function.
[0091] An embodiment of the present disclosure also provides an electronic device, comprising: at least one processor; and a memory for storing instructions executable by the at least one processor; wherein the at least one processor is configured to execute the instructions to implement the above method disclosed in the embodiment of the present disclosure.
[0092] Figure 3 The structure diagram of an electronic device provided by an exemplary embodiment of the present disclosure is shown in FIG. Figure 3 As shown, the electronic device 1800 includes at least one processor 1801 and a memory 1802 coupled to the processor 1801. The processor 1801 can execute corresponding steps in the above method disclosed in the embodiment of the present disclosure.
[0093] The processor 1801 may also be referred to as a central processing unit (CPU), which may be an integrated circuit chip having signal processing capabilities. Each step in the method disclosed in the embodiment of the present disclosure may be completed by an integrated logic circuit of hardware in the processor 1801 or by instructions in the form of software. The processor 1801 may be a general-purpose processor, a digital signal processor (DSP), an ASIC, a field-programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present disclosure may be directly embodied as being executed by a hardware decoding processor, or may be executed by a combination of hardware and software modules in a decoding processor. The software module may be located in a memory 1802, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, or other mature storage media in the art. The processor 1801 reads the information in the memory 1802 and completes the steps of the method in combination with its hardware.
[0094] In addition, when various operations / processes according to the present disclosure are implemented by software and / or firmware, they can be transmitted from a storage medium or a network to a computer system having a dedicated hardware structure, such as Figure 4 The computer system 1900 shown is installed with the programs constituting the software. When the various programs are installed, the computer system can perform various functions, including the functions described above. Figure 4 A structural block diagram of a computer system provided for an exemplary embodiment of the present disclosure.
[0095] Computer system 1900 is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. Electronic devices can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0096] like Figure 4As shown, the computer system 1900 includes a computing unit 1901, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 1902 or a computer program loaded from a storage unit 1908 to a random access memory (RAM) 1903. In the RAM 1903, various programs and data required for the operation of the computer system 1900 can also be stored. The computing unit 1901, the ROM 1902, and the RAM 1903 are connected to each other via a bus 1904. An input / output (I / O) interface 1905 is also connected to the bus 1904.
[0097] A plurality of components in the computer system 1900 are connected to the I / O interface 1905, including: an input unit 1906, an output unit 1907, a storage unit 1908, and a communication unit 1909. The input unit 1906 may be any type of device capable of inputting information to the computer system 1900, and the input unit 1906 may receive input digital or character information, and generate key signal inputs related to user settings and / or function control of the electronic device. The output unit 1907 may be any type of device capable of presenting information, and may include, but is not limited to, a display, a speaker, a video / audio output terminal, a vibrator, and / or a printer. The storage unit 1908 may include, but is not limited to, a disk, an optical disk. The communication unit 1909 allows the computer system 1900 to exchange information / data with other devices over a network such as the Internet, and may include, but is not limited to, a modem, a network card, an infrared communication device, a wireless communication transceiver, and / or a chipset, such as a Bluetooth™ device, a WiFi device, a WiMax device, a cellular communication device, and / or the like.
[0098] The computing unit 1901 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 1901 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 1901 performs the various methods and processes described above. For example, in some embodiments, the above methods disclosed in the embodiments of the present disclosure may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 1908. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 1900 via the ROM 1902 and / or the communication unit 1909. In some embodiments, the computing unit 1901 may be configured to perform the above methods disclosed in the embodiments of the present disclosure in any other appropriate manner (e.g., by means of firmware).
[0099] The embodiment of the present disclosure further provides a computer-readable storage medium, wherein when instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the above method disclosed in the embodiment of the present disclosure.
[0100] The computer-readable storage medium in the disclosed embodiments may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. The computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. More specifically, the computer-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0101] The computer-readable medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
[0102] The embodiments of the present disclosure further provide a computer program product, including a computer program, wherein when the computer program is executed by a processor, the above method disclosed in the embodiments of the present disclosure is implemented.
[0103] In embodiments of the present disclosure, computer program codes for performing the operations of the present disclosure may be written in one or more programming languages or combinations thereof, including but not limited to object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer.
[0104] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0105] The modules, components or units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the names of the modules, components or units do not, in some cases, limit the modules, components or units themselves.
[0106] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip (SOCs), complex programmable logic devices (CPLDs), and the like.
[0107] The above descriptions are only some embodiments of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, a technical solution formed by replacing the above features with the technical features with similar functions disclosed in the present disclosure (but not limited to).
[0108] Although some specific embodiments of the present disclosure have been described in detail by way of example, it should be understood by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the present disclosure. It should be understood by those skilled in the art that the above embodiments may be modified without departing from the scope and spirit of the present disclosure. The scope of the present disclosure is defined by the appended claims.
Claims
1. A vulnerability detection method, characterized in that: The method comprises: Get the code to be tested; In the case that the target function exists in the code to be detected, backtracing is performed on the parameters of the target function to obtain a backtracing result, and based on the backtracing result, it is determined whether the code to be detected has a vulnerability.
2. The method according to claim 1, characterized in that The backtracking of the parameters of the objective function includes: In the case where the code to be detected has a control statement, control flow information is generated based on the control statement to determine a plurality of control branches corresponding to the control statement, and each of the plurality of control branches is traversed for backtracing.
3. The method according to claim 1, characterized in that The method further comprises: In the case where the source function corresponding to the parameter of the target function is not traced back, determining whether the parameter of the first function to which the target function belongs includes the parameter of the target function; In the case where the parameters of the first function include the parameters of the objective function, the first function is used as a new objective function and added to the objective function list.
4. The method according to claim 3, characterized in that The taking the first function as a new objective function and adding it to the objective function list includes: Obtaining a function name of the first function and file information to which the first function belongs; The new target function is named based on the function name and the file information, and the named new target function is added to the target function list.
5. The method according to claim 2, characterized in that: The generating control flow information based on the control statement to determine a plurality of control branches corresponding to the control statement includes: A predecessor node and a successor node of the control statement are obtained, and flow direction information between the predecessor node and the successor node is determined, and multiple control branches corresponding to the control statement are determined based on the flow direction information.
6. The method according to claim 1, characterized in that The backtracking of the parameters of the objective function further includes: Constructing an abstract syntax tree based on the code to be detected; The parameters of the target function are backtracked based on the abstract syntax tree.
7. The method according to claim 1, characterized in that The determining whether the code to be detected has a vulnerability based on the backtracking result includes: When tracing back to the source function corresponding to the parameter of the target function, it is determined that the code to be detected has a vulnerability.
8. A vulnerability detection device, characterized in that: The device comprises: An acquisition module is used to obtain the code to be detected; The detection module is used to backtrack the parameters of the target function when there is a target function in the code to be detected, obtain a backtracking result, and determine whether there is a vulnerability in the code to be detected based on the backtracking result.
9. An electronic device, characterized in that: include: at least one processor; a memory for storing the at least one processor-executable instruction; The at least one processor is configured to execute the instructions to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the method as claimed in any one of claims 1 to 7.
Citation Information
Patent Citations
Data detection method, apparatus and electronic apparatus
CN109508296A
Vulnerability detection method and device based on assembly codes and electronic equipment
CN112906004A
Vulnerability detection method and device, electronic equipment and storage medium
CN114579969A
Method for providing source code analysis service
KR101507469B1
Method And Apparatus For Analysing Source Code Vulnerability By Using TraceBack
KR101696694B1
