Code risk detection method and device, electronic equipment and computer storage medium
By identifying key risk codes and constructing target prompt words, and using large language models to perform taint transfer analysis, the problem of high false positive rates in code security detection is solved, and detection efficiency and accuracy are improved.
Patent Information
- Application Number
- CN202410552728.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-06
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-05-06
AI Technical Summary
In the process of code security risk detection, existing technology is prone to produce a large number of false risk reports, causing security engineers to spend a lot of time conducting risk inspections, affecting efficiency.
By obtaining the code risk detection results of the source code, determine the key risk codes, generate taint transfer analysis prompt words and key risk code prompt words, construct the target prompt words, use the target large language model to perform taint transfer analysis, update the code risk detection results, and reduce False positive.
Effectively eliminate redundant code, improve the understanding accuracy and processing efficiency of large language models, reduce false alarm troubleshooting time, and improve the accuracy and efficiency of code risk detection.
Smart Images

Figure CN118673497A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a code risk detection method, device, electronic device and computer storage medium. Background Art
[0002] In recent years, with the increasing cybersecurity risks, code security issues have received more and more attention. In the process of code security risk detection, in order to avoid underreporting of risks, a large number of risk false positives are often generated, requiring security engineers to spend a lot of time on risk investigation. Summary of the invention
[0003] This specification provides a code risk detection method, device, electronic device and computer storage medium, and the technical solution is as follows:
[0004] In a first aspect, this specification provides a code risk detection method, the method comprising:
[0005] Obtaining a code risk detection result for the source code, and determining a key risk code corresponding to the code risk detection result;
[0006] Generate a taint transfer analysis prompt word based on the key risk code, and generate a key risk code prompt word based on the key risk code;
[0007] Constructing a target prompt word based on the key risk code prompt word and the taint transfer analysis prompt word;
[0008] A target large language model is used to determine a taint transfer analysis result based on the target prompt word, and the code risk detection result is updated based on the taint transfer analysis result to obtain a target code risk detection result.
[0009] In a second aspect, this specification provides a code risk detection device, the device comprising:
[0010] An acquisition module, adapted to acquire a code risk detection result for a source code, and determine a key risk code corresponding to the code risk detection result;
[0011] A generating module, adapted to generate a taint transfer analysis prompt word based on the key risk code, and generate a key risk code prompt word based on the key risk code;
[0012] A construction module, adapted to construct a target prompt word based on the key risk code prompt word and the taint transfer analysis prompt word;
[0013] The updating module is adapted to determine the taint transfer analysis result based on the target prompt word by using a target large language model, and to update the code risk detection result based on the taint transfer analysis result to obtain a target code risk detection result.
[0014] In a third aspect, the present specification provides a computer storage medium, wherein the computer storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the above-mentioned method steps.
[0015] In a fourth aspect, the present specification provides an electronic device, which may include: a processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the above-mentioned method steps.
[0016] In a fifth aspect, the present specification provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded by a processor to execute any one of the above method steps.
[0017] The beneficial effects brought about by the technical solutions provided in some embodiments of the present specification include at least: by obtaining the code risk detection results corresponding to the source code, and then determining the key risk codes corresponding to the code risk detection results, thereby eliminating the redundant useless codes compared to the code risk detection results, and then constructing the key risk code prompt words based on the key risk codes, thereby avoiding the interference of other redundant useless codes on the target large language model when constructing the target prompt words subsequently, and reducing the input of the subsequent target large language model.
[0018] At the same time, the taint transfer analysis prompt words for key risk codes are determined, and the target prompt words of the target large language model are constructed through the key code prompt words and the taint transfer analysis prompt words, thereby effectively improving the target large language model's understanding accuracy of the target prompt words and the processing efficiency of the taint transfer analysis. Finally, the risk detection results are updated based on the obtained taint transfer results, and the risk detection results are screened for false positives, thereby solving the problem that in the process of security risk detection of the code, in order to avoid the omission of risks, a large number of risk false positives are often generated, which requires security engineers to spend a lot of time on risk investigation. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in this specification or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1A schematic diagram of a scenario of a code risk detection system provided in this specification;
[0021] Figure 2 A flowchart of a code risk detection method provided in an embodiment of this specification;
[0022] Figure 3 A schematic diagram of a process for determining a key risk code proposed in an embodiment of this specification;
[0023] Figure 4 A schematic diagram of another process for determining a key risk code proposed in an embodiment of this specification;
[0024] Figure 5 A schematic diagram of a process for determining a key risk code prompt word proposed in an embodiment of this specification;
[0025] Figure 6 A schematic diagram of a process of constructing a target prompt word proposed in an embodiment of this specification;
[0026] Figure 7 A schematic diagram of a process for constructing code prior knowledge prompt words proposed in an embodiment of this specification;
[0027] Figure 8 A schematic diagram of a process for determining a stain transfer analysis result proposed in an embodiment of this specification;
[0028] Fig. 9 A schematic diagram of a process for determining a reference prompt word corresponding to a reference function proposed in an embodiment of this specification;
[0029] Fig.10 A code risk detection device proposed in the embodiments of this specification;
[0030] Fig.11 A schematic diagram of the structure of an electronic device provided in this manual;
[0031] Fig.12 A schematic diagram of the operating system and user space provided for this manual;
[0032] Fig.13 for Fig.12 The architecture diagram of the Android operating system;
[0033] Fig.14 for Fig.12 Architecture diagram of the IOS operating system. DETAILED DESCRIPTION
[0034] The following will be combined with the drawings in this specification to clearly and completely describe the technical solutions in this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.
[0035] In the description of this specification, it should be understood that the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In the description of this specification, it should be noted that, unless otherwise clearly specified and limited, "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices. For those of ordinary skill in the art, the specific meanings of the above terms in this specification can be understood in specific circumstances. In addition, in the description of this specification, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B, which can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are an "or" relationship.
[0036] The present specification is described in detail below with reference to specific embodiments.
[0037] See also Figure 1 , Figure 1 This is a scenario diagram of a code risk detection system provided in this specification. Figure 1 As shown, the code risk detection system may include at least a client cluster and a service platform 100 .
[0038] The client cluster may include at least one client, such as Figure 1 As shown, it specifically includes client 1 corresponding to user 1, client 2 corresponding to user 2, ..., client n corresponding to user n, where n is an integer greater than 0.
[0039] Each client in the client cluster may be an electronic device with communication function, including but not limited to: wearable device, handheld device, personal computer, tablet computer, vehicle-mounted device, smart phone, computing device or other processing device connected to a wireless modem, etc. Electronic devices may be called different names in different networks, such as: user equipment, access terminal, user unit, user station, mobile station, mobile station, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication device, user agent or user device, cellular phone, cordless phone, personal digital assistant (PDA), electronic device in 5G network or future evolution network, etc.
[0040] The service platform 100 can be a separate server device, such as a rack-mounted, blade, tower, or cabinet-mounted server device, or a workstation, mainframe computer, or other hardware device with strong computing power; it can also be a server cluster composed of multiple servers, and the servers in the service cluster can be composed in a symmetrical manner, wherein each server has equivalent functions and status in the transaction link, and each server can provide services to the outside independently, and the independent service can be understood as not requiring the assistance of other servers.
[0041] In one or more embodiments of the present specification, the service platform 100 may establish a communication connection with at least one client in the client cluster, and complete data interaction during the code risk detection process based on the communication connection, such as online transaction data interaction. For example, the service platform 100 may recommend content to the client based on the target neural network model obtained by the code risk detection method of the present specification. For example, the service platform 100 may obtain training data from the client, such as the first training data.
[0042] It should be noted that the service platform 100 and at least one client in the client cluster establish a communication connection through a network for interactive communication, wherein the network can be a wireless network or a wired network, the wireless network includes but is not limited to a cellular network, a wireless local area network, an infrared network or a Bluetooth network, and the wired network includes but is not limited to Ethernet, a universal serial bus (USB) or a controller local area network. In one or more embodiments of the specification, technologies and / or formats including Hyper Text Mark-up Language (HTML), Extensible Markup Language (XML), etc. are used to represent data (such as a target compressed package) exchanged through a network. In addition, conventional encryption technologies such as Secure Socket Layer (SSL), Transport Layer Security (TLS), Virtual Private Network (VPN), Internet Protocol Security (IPsec), etc. can also be used to encrypt all or some links. In other embodiments, customized and / or dedicated data communication technologies can also be used to replace or supplement the above data communication technologies.
[0043] The code risk detection system embodiment provided in this specification and the code risk detection method in one or more embodiments belong to the same concept. The execution subject corresponding to the code risk detection method involved in one or more embodiments of the specification can be the above-mentioned service platform 100; the execution subject corresponding to the code risk detection method involved in one or more embodiments of the specification can also be the electronic device corresponding to the client, which is determined based on the actual application environment. The implementation process of the code risk detection system embodiment can be detailed in the following method embodiment, which will not be repeated here.
[0044] based on Figure 1 The scenario diagram is shown, and the code risk detection method provided by one or more embodiments of this specification is introduced in detail below.
[0045] See also Figure 2 , Figure 2 A flowchart of a code risk detection method provided in an embodiment of this specification is provided. The method can be implemented by a computer program and can be run on a code risk detection device based on the von Neumann system. The computer program can be integrated into an application or run as an independent tool application. The code risk detection device can be a service platform.
[0046] Specifically, the code risk detection method includes:
[0047] S202: Obtain code risk detection results for source code, and determine key risk codes corresponding to the code risk detection results.
[0048] Optionally, obtain code risk detection results for source code, including:
[0049] Perform code risk detection on the source code to obtain code risk detection results for the source code.
[0050] Among them, code risk detection includes but is not limited to program static analysis, which refers to the method of analyzing programs without running the program. Usually, for security risk scenarios, static program analysis uses data flow / taint analysis algorithms to analyze programs, calculate the relationship between program variables between functions and within functions, and ultimately determine whether there are security risks in the code under specific conditions.
[0051] Optionally, obtain code risk detection results for source code, including:
[0052] The source code is subjected to risk detection based on the code risk detection model to obtain a code risk detection result for the source code; wherein the code risk detection model can be obtained by training the model based on the initial code risk detection model through sample code and reference risk labels corresponding to the sample code.
[0053] The source code is input into the code risk detection model, and the source code is processed by the code risk detection model to obtain the code risk detection result.
[0054] Usually, in order to ensure that potential security risks are not missed as much as possible, the code risk detection results for the source code may contain false positives. Therefore, the code risk detection results need to be screened to eliminate the detection results corresponding to the false positives.
[0055] The code risk detection result generally refers to the risk function call information of one or more possible security risk vulnerabilities in the source code. Since the function code corresponding to the code risk detection result is usually all the function codes of all the risk functions in the risk function call information, but not all the codes in the function code of the risk function will cause the function to become a risk function, it is necessary to filter out useless codes in the codes of each risk function, so as to determine the key risk codes that make each function a risk function.
[0056] S204: Generate taint transfer analysis prompt words based on the key risk code, and generate key risk code prompt words based on the key risk code.
[0057] After all the key risk codes of the source code are determined, in order to improve the processing efficiency of all the key risk codes, all the key risk codes can be divided according to the functions corresponding to all the key risk codes, such as grouping the key risk codes corresponding to one, two or more functions into one group, thereby obtaining multiple groups of key risk code sets for all the key risk codes. Of course, all the key risk codes can also be grouped into one group.
[0058] Therefore, when generating the taint transfer analysis prompt words and the key risk code prompt words based on the key risk code, the taint transfer analysis prompt words and the key risk code prompt words can be generated based on all the key risk codes; or, the taint transfer analysis prompt words and the key risk code prompt words corresponding to each group of key risk code sets can be generated based on multiple groups of key risk code sets. It should be understood that each group of key risk code sets can correspond to one taint transfer analysis prompt word and one key risk code prompt word.
[0059] Here, taint transfer may refer to the data flow transfer process of tainted variables in source code, and tainted variables may be untrusted data or confidential data in a function. The taint transfer analysis prompt word is used to instruct the target large language model to perform taint transfer analysis on the key risk code corresponding to the taint transfer analysis prompt word.
[0060] S206: Construct target prompt words based on the key risk code prompt words and the taint transfer analysis prompt words.
[0061] After obtaining the key risk code prompt words and the taint transfer analysis prompt words, the key risk code prompt words and the taint transfer analysis prompt words can be spliced according to the preset splicing rules to obtain the target prompt words. The preset splicing rules can be determined based on the target large language model. Here, each group of key risk code sets corresponds to a target prompt word.
[0062] S208: Determine the taint transfer analysis result based on the target prompt word using the target large language model, and update the code risk detection result based on the taint transfer analysis result to obtain the target code risk detection result.
[0063] After the target prompt word is input into the target large language model, the target large language model extracts the semantic information of the corresponding part of the taint transfer analysis prompt word in the target prompt word, determines the taint transfer analysis task of the target large language model based on the extracted semantic information, and then performs taint transfer analysis on the key risk code corresponding to the key risk code prompt word in the target prompt word based on the obtained taint transfer analysis task, and obtains the function taint transfer result for the key risk code. Here, the target large language model is a language model composed of a neural network with many parameters, which is obtained by training a large amount of unlabeled text based on self-supervised learning or semi-supervised learning.
[0064] Afterwards, the target large language model performs taint transfer analysis on the key risk codes in the source code based on the target prompt words in turn to obtain the taint transfer analysis results, thereby determining whether the tainted variable is successfully transferred in the key risk code corresponding to the source code.
[0065] When the tainted variable is successfully passed in the key risk code corresponding to the source code, it indicates that there is no false alarm in the code risk detection result for the source code; when the tainted variable is not successfully passed in the key risk code corresponding to the source code, it indicates that there is a false alarm in the code risk detection result for the source code, and the code risk detection result is corrected and updated to eliminate the false alarm.
[0066] In this specification, by obtaining the code risk detection results corresponding to the source code, and then determining the key risk codes corresponding to the code risk detection results, thereby eliminating redundant useless codes compared to the code risk detection results, and then constructing key risk code prompt words based on the key risk codes, thereby avoiding the interference of other redundant useless codes on the target large language model when constructing the target prompt words subsequently, and reducing the input of the subsequent target large language model.
[0067] At the same time, the taint transfer analysis prompt words for key risk codes are determined, and the target prompt words of the target large language model are constructed through the key code prompt words and the taint transfer analysis prompt words, thereby effectively improving the target large language model's understanding accuracy of the target prompt words and the processing efficiency of the taint transfer analysis. Finally, the risk detection results are updated based on the obtained taint transfer results, and the risk detection results are screened for false positives, thereby solving the problem that in the process of security risk detection of the code, in order to avoid the omission of risks, a large number of risk false positives are often generated, which requires security engineers to spend a lot of time on risk investigation.
[0068] See also Figure 3 , Figure 3 This is a flow chart of determining a key risk code proposed in an embodiment of this specification. Specifically: Determining the key risk code corresponding to the code risk detection result in S202 includes:
[0069] S302: Obtain a risk function call link from the code risk detection result, and determine a target function and function variables of the target function in the risk function call link.
[0070] A risky function call link can be a function call link that has security risks. A function call link refers to a series of function call processes, that is, when a function is called, it triggers the call of another function. This process will continue to form a call chain, namely, a function call link. The function call link includes the function call process and the functions related to the function call process. Of course, the function call link can also include the number of lines of code at the function call point.
[0071] Therefore, the risk function call link can be understood as a function call link in which the tainted variable has the possibility of being directly propagated to the taint aggregation point. The taint aggregation point represents the function site that directly generates security-sensitive operations or leaks private data to the outside world. Security-sensitive operations usually refer to violations of data integrity, that is, information loss, errors or changes occur during data transmission, storage and processing, resulting in the authenticity and accuracy of the data being affected.
[0072] After obtaining the risk function call link from the code risk detection results, obtain the function call relationship of the risk function call link, and determine the starting function in the risk function call link. The starting function refers to the first function called in the risk function call link, and the starting function is the starting point of the entire risk function call link. The starting function in the risk function call link is used as the target function, and the function variables of the target function are determined. Function variables refer to variables used inside the function. During the function call, function variables can be passed to other functions as input parameters of the function. It should be understood that since the risk function call link is obtained from the code risk detection results, the function variables corresponding to the starting function in the risk function call link are generally tainted variables.
[0073] S304: Determine the key risk code of each risk function associated with the function variable from the risk function call link.
[0074] After obtaining the function variables of the objective function, the risk function associated with the function variables of the objective function is determined from the risk function call link, and the key risk code associated with the function variables of the objective function in each risk function is determined. Here, the key risk code can be understood as the function statement code of the function related to the function variables of the objective function.
[0075] For example, the risk function is function B, which includes multiple lines of function code, such as the first line of function code a, the second line of function code b, and the third line of function code c, and the second line of function code b is associated with the function variable of the target function, that is, the second line of function code b directly or indirectly calls the function variable of the target function, then the second line of function code b is the key risk code of function B for the function variable in the target function.
[0076] In this specification, the target function and function variables of the risk function call link in the code risk detection result are determined, so that the key risk codes of each risk function associated with the function variables are determined from the risk function call link through the function variables, thereby eliminating the redundant codes in a single function compared to the function variables, and then constructing the key risk code prompt words based on the key risk codes, so as to prevent other redundant codes from interfering with the target large language model, and also reduce the input of the subsequent target large language model.
[0077] In the embodiment provided in this specification, in S208, the code risk detection result is updated based on the taint transfer analysis result to obtain the target code risk detection result, including:
[0078] The type of the taint transfer analysis result is determined. If the type of the taint transfer analysis result is a link taint transfer failure type, the target risk function call link corresponding to the taint transfer failure is removed from the code risk detection result.
[0079] By determining the type of the taint transfer analysis result of each risk function call link in the code risk detection result, it is judged whether each risk function call link is a false alarm information in the code risk detection result. When the type of the taint transfer analysis result is a link taint transfer failure type, the target risk function call link corresponding to the taint transfer failure is removed from the code risk detection result; when the type of the taint transfer analysis result is a link taint transfer success type, the target risk function call link corresponding to the taint transfer success is retained from the code risk detection result.
[0080] See also Figure 4 , Figure 4 Another flow chart of determining key risk codes proposed in the embodiment of this specification. Specifically: In S304, determining the key risk codes of each risk function associated with the function variable from the risk function call link includes:
[0081] S402: Determine at least one risk function associated with a function variable in a risk function call link.
[0082] The risk function call link is split into functions to obtain at least two call functions corresponding to the risk function call link, and then one or more risk functions associated with the function variables are determined from the call functions. Here, the number of risk functions is determined based on the number of call functions associated with the function variables in the risk function call link.
[0083] Specifically, one or more risk functions associated with the function variable may be determined from at least two calling functions corresponding to the risk function calling link through the data flow direction information of the function variable.
[0084] S404: Searching for code statements associated with function variables from function code statements of risk functions to obtain key risk codes corresponding to each risk function.
[0085] Among them, after determining the risk function in the risk function call link, the function code statement of the risk function is obtained, and then the code statement associated with the function variable is extracted from the function code statement of the risk function, so as to obtain the key code corresponding to each risk function.
[0086] In a specific embodiment, when the function variables corresponding to the target function are filename and content, after searching the code statements associated with the function variables in the function code statements of a risk function, it is determined that the key codes corresponding to the risk function are "filepath = "pre_path" + filename" and "file_write (filepath, content)".
[0087] In this specification, at least one risk function associated with the function variable in the risk function call link is determined by the function variable corresponding to the objective function, and then the key code associated with the function variable in the function code statement of the risk function is determined, thereby obtaining the key code of each risk function in the risk function call link. In this embodiment, by determining the risk function associated with the function variable, the function that is not related to the function variable of the objective function is filtered out, which can effectively reduce the model input of the subsequent target large language model. At the same time, by extracting the key code associated with the function variable in each risk function, the useless code in each risk function is further filtered out, thereby further reducing the model input of the subsequent target large language model, and effectively eliminating the interference of other useless codes on the target large language model.
[0088] See also Figure 5 , Figure 5 This is a flow chart of determining a key risk code prompt word proposed in an embodiment of this specification. Specifically: S204 generates a key risk code prompt word based on the key risk code, including:
[0089] S502: Determine a taint variable corresponding to the risk function based on the code risk detection result.
[0090] Each risk function has its corresponding taint variable. It should be understood that the taint variable corresponding to each risk function can be from the previous risk function corresponding to the risk function in the taint transfer data stream, or from external input. Therefore, the taint transfer information can be determined based on the code risk detection result, thereby determining the taint variable corresponding to each risk function.
[0091] During the taint transfer process, the taint variable may change. Assuming that the initial taint variable in the risk function call link is W, when the taint variable is transferred to the next risk function, the taint variable may become N, where N=W+1. Therefore, the taint variables of the key codes of each risk function can be determined based on the taint transfer information in the code risk detection result. The taint transfer information can refer to the transfer information of the taint variable in the function call link.
[0092] In the risk function call chain, since the function taint transfer result of the current risk function may affect the function taint transfer result of the next risk function, and because the function taint transfer result of the current risk function will affect the tainted variable in the next risk function, it is necessary to determine the function taint transfer result of each risk function in the risk function call chain in turn based on the target large language model.
[0093] S504: Searching for the target sub-function corresponding to the endpoint code statement from the key risk code corresponding to the risk function.
[0094] After determining the key code corresponding to each risk function, determine the end code statement in the key code corresponding to each risk function. The end code statement may refer to the target code statement that needs to be executed when the key code corresponding to the risk function is run. After that, the target code statement may be used as the target sub-function. The target sub-function is used to transfer tainted variables between risk functions.
[0095] S506: Generate taint transfer analysis prompt words for key risk codes based on the taint variable and the target sub-function.
[0096] The taint transfer analysis prompt word may be: determine whether the taint variable can be successfully transferred to the target sub-function of the key risk code through the key risk code. Since the taint variables, target sub-functions and key risk codes of different risk functions may be different, different risk functions may correspond to different taint transfer analysis prompt words.
[0097] In some embodiments, the key risk code corresponding to the risk function func(filename, content) is { / / filepath="pre_path"+filename; / / file_write(filepath, content); / / sink}, the taint variables of the risk function are filename and content, and the target subfunction is the file_write function. The taint transfer analysis prompt for the key risk code can be "The parameters of the current func function are filename and content, and filename and content are controllable. Please analyze from the key risk code to see whether the final taint of the parameters filename and content will reach the file_write function."
[0098] In this specification, the taint variables corresponding to each risk function are determined through the code risk detection results, and the target sub-function for transferring taint variables between each risk function is determined based on the key risk code corresponding to each risk function. Finally, based on the taint variables corresponding to each risk function and the target sub-function corresponding to each risk function, taint transfer analysis prompt words are generated for the key risk code corresponding to each risk function. By splitting the entire taint transfer process of the source code into the taint transfer process of a single risk function, the target large language model can be better understood and the input of a single target large language model can be reduced.
[0099] See also Figure 6 , Figure 6 This is a flow chart of constructing a target prompt word according to an embodiment of this specification. Figure 6 As shown, S206 constructs a target prompt word based on the key risk code prompt word and the taint transfer analysis prompt word, including:
[0100] S602: Construct code prior knowledge prompt words for the risk function call link, and construct output specification prompt words.
[0101] The code prior knowledge prompt words are used to instruct the target large language model to learn and understand the prior knowledge, where the prior knowledge includes a series of vulnerability codes and purification functions. The purification function is usually used to clear or clean data or variables. It may involve deleting duplicates, handling errors, standardizing data formats, or performing other tasks related to data cleaning and preparation.
[0102] By providing vulnerable code and purification functions, the target large language model can learn the vulnerable code and which purification functions will eliminate the tainted variables after the vulnerable code passes through, thereby improving the accuracy of the target large language model in eliminating false positive information in the code risk detection results.
[0103] The output standard prompt word is used to standardize the output of the target large language model, so that the output format of the target large language model is stable, so as to facilitate the subsequent generation of new prompt words based on the output of the target large language model. The output standard prompt word can be: "Please output the result in json format".
[0104] At this time, the taint transfer analysis results can be expressed in JSON format and can be divided into two parts. The first part is used to answer whether the tainted variable can reach the target function. The second part is used to clearly describe the source of the taint on the target function when the tainted variable can reach the target function, that is, to perform taint analysis, so as to determine the position of the tainted variable corresponding to the function corresponding to the taint convergence point and the starting source function of the tainted variable.
[0105] S604: Construct target prompt words based on code prior knowledge prompt words, key risk code prompt words, taint transfer analysis prompt words, and output specification prompt words.
[0106] After determining the code prior knowledge prompt words and the output specification prompt words, the code prior knowledge prompt words, the key risk code prompt words, the taint transfer analysis prompt words and the output specification prompt words are spliced to obtain the target prompt words.
[0107] Among them, the code prior knowledge prompt words are used to instruct the target large language model to learn and understand the prior knowledge model, so that the target large language model can learn the code with vulnerabilities and which purification functions will eliminate the tainted variables after the code with vulnerabilities passes through, thereby improving the accuracy of the target large language model in eliminating false positive information in the code risk detection results; the key risk code prompt words are used to provide the key risk code to the target large language model for taint transfer risk, so as to avoid redundant code interfering with the model understanding of the target large language model; the taint transfer analysis prompt words are used to instruct the target large language model to perform taint transfer analysis on the key risk codes in the key risk code prompt words; the output specification prompt words are used to standardize the output of the target large language model, so as to facilitate the generation of new prompt words based on the output of the target large language model.
[0108] See also Figure 7 , Figure 7 This is a flow chart of constructing a code prior knowledge prompt word according to an embodiment of this specification. Figure 7 As shown, in S602, the code prior knowledge prompt words for the risk function call link are constructed, including:
[0109] S702: Determine the risk type of the risk function in the risk function call link, and determine the code prior knowledge database information matching the risk type.
[0110] The risk types of the risk function may be divided based on specific scenarios, such as the risk types may include a first risk type, a second risk type, and a third risk type.
[0111] Each risk type has its own corresponding code prior knowledge database. The code prior knowledge database may include a series of vulnerability codes and purification functions corresponding to the risk type. The code prior knowledge database information may be location information of the code prior knowledge database.
[0112] S704: Generate a priori code knowledge prompt word for the risk function call link based on the priori code knowledge database information.
[0113] After determining the code prior knowledge database information, the code prior knowledge database information is used to generate a code prior knowledge prompt word that instructs the target large language model to learn the code prior knowledge based on the code prior knowledge database information.
[0114] Specifically, when the code prior knowledge database information is the location information of the code prior knowledge database, the code prior knowledge prompt word may be: please perform model learning on the code prior knowledge in the code prior knowledge database based on the location information of the code prior knowledge database.
[0115] In this specification, by determining the risk type of the risk function in the risk function call link and then determining the corresponding code prior knowledge database information, the generated code prior knowledge prompt words are made more targeted, and the code prior knowledge for model learning of the target large language model is made more targeted, thereby improving the targeted code prior knowledge learning and model learning efficiency of the target large language model.
[0116] See also Figure 8 , Figure 8 This is a flow chart of determining the result of a stain transfer analysis proposed in the embodiment of this specification. Figure 8 As shown, in S208, the target large language model is used based on the target prompt word to determine the taint transfer analysis result, including:
[0117] S802: Input the target prompt word into the target large language model.
[0118] The target prompt words include at least key risk code prompt words and taint transfer analysis prompt words; of course, the target prompt words may also include code prior knowledge prompt words, key risk code prompt words, taint transfer analysis prompt words and output specification prompt words; or, the target prompt words may also include code prior knowledge prompt words, key risk code prompt words and taint transfer analysis prompt words; or, the target prompt words may also include key risk code prompt words, taint transfer analysis prompt words and output specification prompt words.
[0119] Among them, the specific descriptions of the code prior knowledge prompt words, key risk code prompt words, taint transfer analysis prompt words and output specification prompt words can be found in the relevant description of S604, which will not be repeated here.
[0120] S804: Obtain the risk function corresponding to the target prompt word and the risk function call link corresponding to the risk function through the target large language model, determine the taint variable corresponding to the risk function based on the target prompt word, and perform taint transfer analysis on the key risk code corresponding to the risk function based on the taint variable to obtain the function taint transfer analysis result for the risk function.
[0121] The target prompt word can be determined based on the key risk code corresponding to a single risk function, so the risk function corresponding to the target prompt word can be obtained based on the target large language model. The code risk detection result includes one or more risk function call links, and the risk function is included in the corresponding risk function call link, so the corresponding risk function call link can be obtained from the code risk detection result based on the risk function.
[0122] The taint variable corresponding to the risk function can be determined through the code risk detection result. It should be understood that the representation of the taint variable may change during the taint transmission process. Therefore, each risk function has its corresponding taint variable.
[0123] Through the instruction of the target prompt word, the target large language model first determines the taint variable corresponding to the risk function, and then performs taint transfer analysis on the key risk code corresponding to the risk function based on the taint variable, so as to determine whether the taint variable is successfully transferred in the key risk code corresponding to the risk function, thereby obtaining the function taint transfer analysis result.
[0124] S806: Determine whether there is a next reference function of the risk function based on the risk function call link.
[0125] The risk function call link includes the call relationship between each risk function. Therefore, it can be determined through the risk function call link whether the risk function has a next reference function for its tainted variable transfer.
[0126] S808: If it does not exist, generate a taint transfer analysis result based on the function taint transfer analysis result.
[0127] When it is determined based on the risk function call link that there is no next reference function of the risk function, it indicates that the risk function is the function to which the tainted variable is finally transferred, and the taint transfer analysis result can be determined based on the function taint transfer analysis result of the risk function.
[0128] That is, when the function taint transfer analysis result of the risk function is a taint transfer success type, the taint transfer analysis result corresponds to a link taint transfer success; when the function taint transfer analysis result of the risk function is a taint transfer failure type, the taint transfer analysis result corresponds to a link taint transfer failure.
[0129] S810: If it exists, obtain the reference prompt word corresponding to the reference function associated with the function taint transfer analysis result, use the reference prompt word as the target prompt word and the reference function as the risk function, and execute the step of inputting the target prompt word into the target large language model.
[0130] In the risk function call chain, the function taint transfer result of the current risk function may affect the function taint transfer result of the next reference function, because the function taint transfer result of the current risk function will affect the taint variable of the next reference function. Therefore, it is necessary to determine the function taint transfer result of each risk function in the risk function call chain in turn based on the target large language model.
[0131] Therefore, when it is determined based on the risk function call link that there is the next reference function of the risk function, it indicates that the risk function is not the function to which the taint variable is ultimately transferred, and the next reference function of the risk function is determined. At this time, the reference prompt word corresponding to the reference function associated with the function taint transfer analysis result is obtained. Similarly, the reference prompt word may include the key risk code prompt word and the taint transfer analysis prompt word corresponding to the reference function; of course, the reference prompt word may also include the code prior knowledge prompt word, key risk code prompt word, taint transfer analysis prompt word and output specification prompt word corresponding to the reference function; or, the reference prompt word may also include the code prior knowledge prompt word, key risk code prompt word and taint transfer analysis prompt word corresponding to the reference function; or, the reference prompt word may also include the key risk code prompt word, taint transfer analysis prompt word and output specification prompt word corresponding to the reference function.
[0132] After obtaining the reference prompt word corresponding to the reference function, the reference prompt word corresponding to the reference function is used as the target prompt word and the reference function is used as the risk function, and step S802 is executed until there is no next reference function of the risk function in the risk function call link, indicating that the target large language model has completed the taint transfer analysis of the risk function call link.
[0133] In this specification, the target large language model is used to perform taint transfer analysis on the risk functions in the risk function call link one by one, thereby reducing the input of the single target large language model and improving the model understanding accuracy and model processing efficiency of the target large language model for the target prompt word, so that the final taint transfer analysis result can be determined accurately and efficiently.
[0134] See also Fig. 9 , Fig. 9 This is a flow chart of determining a reference prompt word corresponding to a reference function proposed in an embodiment of this specification. Fig. 9 As shown, in S810, obtaining a reference prompt word corresponding to a reference function associated with the function taint transfer analysis result includes:
[0135] S902: Determine the reference taint variable corresponding to the reference function based on the function taint transfer analysis result, and search for the reference sub-function corresponding to the endpoint code statement from the reference key risk code corresponding to the reference function.
[0136] The function taint transfer analysis result corresponding to the risk function can characterize whether the taint variable is successfully transferred in the risk function. When the taint variable is successfully transferred in the risk function, when the taint variable corresponding to the risk function is passed to the reference function, due to the possible operation of the taint variable, its form may change when it is passed to the reference function. Therefore, it is necessary to determine the reference taint variable corresponding to the reference function based on the function taint transfer analysis result.
[0137] Afterwards, the key risk code corresponding to the reference function, that is, the reference key risk code, is searched, the endpoint code statement is searched from the reference key risk code, and the endpoint code statement is used as the reference sub-function.
[0138] Optionally, determining a reference tainted variable corresponding to the reference function based on the function taint transfer analysis result in S902 includes:
[0139] Obtain the key risk code of the risk function corresponding to the function taint transfer analysis result, and determine the target sub-function corresponding to the endpoint code statement in the key risk code;
[0140] If the function taint transfer analysis result is a taint transfer success type, the function output variable of the target sub-function is obtained, and the function output variable is used as the reference taint variable corresponding to the reference function.
[0141] Among them, the taint variable of the risk function is generally transferred to the next reference function through the target sub-function corresponding to the endpoint code statement in the key risk code. When the function taint transfer analysis result of the risk function is the taint transfer success type, it indicates that the function output variable of the target sub-function is the reference taint variable of the next reference function.
[0142] When the function taint transfer analysis result of the risk function is a taint transfer failure type, it indicates that the function output variable of the target sub-function is not the reference taint variable of the next reference function. At this time, it can be determined whether the next reference function has additional reference taint variables based on the code risk detection result. If the next reference function does not have additional reference taint variables, the reference taint variable of the next reference function is empty. At this time, the function taint transfer analysis result of the next reference function is a taint transfer failure type.
[0143] S904: Generate reference taint transfer analysis prompt words for the reference key risk code based on the reference taint variable, the reference key risk code and the reference sub-function.
[0144] Among them, the relevant description of step S904 is similar to that of step S506, and you can refer to step S506, and no further description is given here.
[0145] S906: Determine a reference prompt word corresponding to the reference function based on the reference taint transfer analysis prompt word.
[0146] At least based on the reference taint transfer analysis prompt words, the reference prompt words corresponding to the reference function are generated. The reference prompt words may include key risk code prompt words and reference taint transfer analysis prompt words corresponding to the reference function; of course, the reference prompt words may also include code prior knowledge prompt words, key risk code prompt words, reference taint transfer analysis prompt words and output specification prompt words corresponding to the reference function; or, the reference prompt words may also include code prior knowledge prompt words, key risk code prompt words and reference taint transfer analysis prompt words corresponding to the reference function; or, the reference prompt words may also include key risk code prompt words, reference taint transfer analysis prompt words and output specification prompt words corresponding to the reference function.
[0147] In this specification, the reference taint variable corresponding to the reference function is determined based on the function taint transfer analysis result corresponding to the risk function, and the reference taint transfer analysis prompt words for the reference key risk code are obtained, thereby generating reference prompt words for the reference function, thereby improving the accuracy of the reference prompt words corresponding to the reference function.
[0148] The following will be combined Fig.10 , Fig.10 This is a code risk detection device proposed in the embodiment of this specification, and the code risk detection device provided in this specification is introduced in detail. It should be noted that: Fig.10 The code risk detection device shown is used to execute this instruction Figures 1 to 9 For the convenience of explanation, only the parts related to this specification are shown. For specific technical details not disclosed, please refer to this specification. Figures 1 to 9 The embodiment shown.
[0149] See also Fig.10 , which shows a schematic diagram of the structure of the code risk detection device of the present specification. The code risk detection device 1 can be implemented as all or part of the user terminal through software, hardware or a combination of both. According to some embodiments, the code risk detection device 1 includes an acquisition module 11, a generation module 12, a construction module 13 and an update module 14, which are specifically used to:
[0150] An acquisition module 11 is adapted to acquire a code risk detection result for a source code and determine a key risk code corresponding to the code risk detection result;
[0151] A generating module 12, adapted to generate a taint transfer analysis prompt word based on a key risk code, and generate a key risk code prompt word based on the key risk code;
[0152] A construction module 13, adapted to construct a target prompt word based on a key risk code prompt word and a taint transfer analysis prompt word;
[0153] The updating module 14 is adapted to determine the taint transfer analysis result based on the target prompt word using the target large language model, and update the code risk detection result based on the taint transfer analysis result to obtain the target code risk detection result.
[0154] Optionally, the acquisition module 11 includes:
[0155] An acquisition unit, adapted to acquire a risk function call link from the code risk detection result, and determine a target function and a function variable of the target function in the risk function call link;
[0156] The determination unit is adapted to determine the key risk code of each risk function associated with the function variable from the risk function call link.
[0157] Optionally, the determining unit includes:
[0158] a determination subunit adapted to determine at least one risk function associated with a function variable in a risk function call link;
[0159] The search subunit is adapted to search for code statements associated with function variables from function code statements of risk functions to obtain key risk codes corresponding to each risk function.
[0160] Optionally, the generating module 12 includes:
[0161] A taint variable determination unit, adapted to determine a taint variable corresponding to a risk function based on a code risk detection result;
[0162] A target sub-function search unit, adapted to search for a target sub-function corresponding to an endpoint code statement from a key risk code corresponding to a risk function;
[0163] The generation unit is adapted to generate taint transfer analysis prompt words for key risk codes based on taint variables and target sub-functions.
[0164] Optionally, building block 13 includes:
[0165] The first construction unit is adapted to construct code prior knowledge prompt words for the risk function call link and construct output specification prompt words;
[0166] The second construction unit is suitable for constructing target prompt words based on code prior knowledge prompt words, key risk code prompt words, taint transfer analysis prompt words and output specification prompt words.
[0167] Optionally, the first building block comprises:
[0168] A code prior knowledge database information determination subunit, adapted to determine the risk type of the risk function in the risk function call link, and determine the code prior knowledge database information matching the risk type;
[0169] The code prior knowledge prompt word generation unit is adapted to generate code prior knowledge prompt words for risk function call links based on code prior knowledge database information.
[0170] Optionally, the updating module 14 includes:
[0171] An input unit, adapted to input a target prompt word into a target large language model;
[0172] A function taint transfer analysis result determination unit is adapted to obtain the risk function corresponding to the target prompt word and the risk function call link corresponding to the risk function through the target large language model, determine the taint variable corresponding to the risk function based on the target prompt word, and perform taint transfer analysis on the key risk code corresponding to the risk function based on the taint variable to obtain the function taint transfer analysis result for the risk function;
[0173] A judgment unit, adapted to determine whether there is a next reference function of the risk function based on the risk function call link;
[0174] a taint transfer analysis result generating unit, adapted to generate a taint transfer analysis result based on the function taint transfer analysis result if it does not exist;
[0175] An execution unit is adapted to obtain, if any, a reference prompt word corresponding to a reference function associated with a function taint transfer analysis result, use the reference prompt word as a target prompt word and the reference function as a risk function, and execute the step of inputting the target prompt word into a target large language model.
[0176] Optionally, the execution unit includes:
[0177] A reference sub-function search sub-unit is adapted to determine a reference taint variable corresponding to a reference function based on a function taint transfer analysis result, and to search for a reference sub-function corresponding to an endpoint code statement from a reference key risk code corresponding to the reference function;
[0178] A reference taint transfer analysis prompt word generation subunit, adapted to generate reference taint transfer analysis prompt words for reference key risk codes based on reference taint variables and reference subfunctions;
[0179] The reference prompt word determination subunit is adapted to determine the reference prompt word corresponding to the reference function based on the reference taint transfer analysis prompt word.
[0180] Optionally, the reference sub-function search sub-unit is adapted to obtain a key risk code of a risk function corresponding to a function taint transfer analysis result, and determine a target sub-function corresponding to an endpoint code statement in the key risk code;
[0181] If the function taint transfer analysis result is a taint transfer success type, the function output variable of the target sub-function is obtained, and the function output variable is used as the reference taint variable corresponding to the reference function.
[0182] Optionally, the updating module 14 is adapted to determine the type of the taint transfer analysis result, and if the type of the taint transfer analysis result is a link taint transfer failure type, the target risk function call link corresponding to the taint transfer failure is removed from the code risk detection result.
[0183] It should be noted that the code risk detection device provided in the above embodiment only uses the division of the above functional modules as an example when executing the code risk detection method. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the code risk detection device provided in the above embodiment and the code risk detection method embodiment belong to the same concept, and the implementation process thereof is detailed in the method embodiment, which will not be repeated here.
[0184] The present specification also provides a computer storage medium, which can store multiple instructions, which are suitable for being loaded and executed by a processor as described above. Figures 1 to 9 The code risk detection method of the embodiment shown in the figure can be specifically executed by referring to Figures 1 to 9 The specific description of the illustrated embodiment will not be repeated here.
[0185] The present specification also provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by the processor as described above. Figures 1 to 9The code risk detection method of the embodiment shown in the figure can be specifically executed by referring to Figures 1 to 9 The specific description of the illustrated embodiment will not be repeated here.
[0186] Please refer to Fig.11 , Fig.11 The electronic device in this specification may include one or more of the following components: a processor 110, a memory 120, an input device 130, an output device 140, and a bus 150. The processor 110, the memory 120, the input device 130, and the output device 140 may be connected via the bus 150.
[0187] The processor 110 may include one or more processing cores. The processor 110 uses various interfaces and lines to connect various parts of the entire electronic device, and executes various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets or instruction sets stored in the memory 120, and calling data stored in the memory 120. Optionally, the processor 110 can be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), and programmable logic array (PLA). The processor 110 can integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU mainly processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 110, but may be implemented separately through a communication chip.
[0188] The memory 120 may include a random access memory (RAM) or a read-only memory (ROM). Optionally, the memory 120 includes a non-transitory computer-readable storage medium. The memory 120 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The operating system may be an Android system, including a system deeply developed based on the Android system, an IOS system developed by Apple, including a system deeply developed based on the IOS system or other systems. The data storage area may also store data created by the electronic device during use, such as a phone book, audio and video data, chat record data, etc.
[0189] See also Fig.12 As shown, Fig.12 The structural diagram of the operating system and user space provided in this specification shows that the memory 120 can be divided into the operating system space and the user space. The operating system runs in the operating system space, and the native and third-party applications run in the user space. In order to ensure that different third-party applications can achieve good operating results, the operating system allocates corresponding system resources to different third-party applications. However, the requirements for system resources in different application scenarios in the same third-party application are also different. For example, in the local resource loading scenario, the third-party application has higher requirements for disk reading speed; in the animation rendering scenario, the third-party application has higher requirements for GPU performance. The operating system and the third-party application are independent of each other, and the operating system often cannot perceive the current application scenario of the third-party application in time, resulting in the operating system being unable to perform targeted system resource adaptation according to the specific application scenario of the third-party application.
[0190] In order for the operating system to distinguish the specific application scenarios of third-party applications, it is necessary to open up data communication between third-party applications and the operating system so that the operating system can obtain the current scenario information of third-party applications at any time, and then perform targeted system resource adaptation based on the current scenario.
[0191] Fig.13 for Fig.12 The architecture diagram of the Android operating system in FIG. 1 is a diagram showing an operating system as the Android system. The programs and data stored in the memory 120 are as follows: Fig.13 As shown, the memory 120 may store a Linux kernel layer 320, a system runtime library layer 340, an application framework layer 360 and an application layer 380, wherein the Linux kernel layer 320, the system runtime library layer 340 and the application framework layer 360 belong to the operating system space, and the application layer 380 belongs to the user space. The Linux kernel layer 320 provides underlying drivers for various hardware of electronic devices, such as display drivers, audio drivers, camera drivers, Bluetooth drivers, Wi-Fi drivers, power management, etc. The system runtime library layer 340 provides the main feature support for the Android system through some C / C++ libraries. For example, the SQLite library provides database support, the OpenGL / ES library provides 3D drawing support, and the Webkit library provides browser kernel support, etc. The Android runtime library (Android runtime) is also provided in the system runtime library layer 340, which mainly provides some core libraries that allow developers to use the Java language to write Android applications. The application framework layer 360 provides various APIs that may be used when building applications. Developers can also use these APIs to build their own applications, such as activity management, window management, view management, notification management, content provider, package management, call management, resource management, and location management. At least one application runs in the application layer 380. These applications can be native applications that come with the operating system, such as contact applications, text messaging applications, clock applications, camera applications, etc.; they can also be third-party applications developed by third-party developers, such as game applications, instant messaging applications, photo beautification applications, etc.
[0192] Fig.14 for Fig.12 FIG. 1 is an architecture diagram of the IOS operating system, taking the operating system as the IOS system as an example, the programs and data stored in the memory 120 are as follows: Fig. 9As shown, the IOS system includes: a core operating system layer 420 (Core OS layer), a core service layer 440 (Core Services layer), a media layer 460 (Media layer), and a touchable layer 480 (Cocoa TouchLayer). The core operating system layer 420 includes the operating system kernel, drivers, and underlying program frameworks, which provide functions closer to the hardware for use by the program framework located in the core service layer 440. The core service layer 440 provides system services and / or program frameworks required by the application, such as the foundation framework, account framework, advertising framework, data storage framework, network connection framework, geographic location framework, motion framework, etc. The media layer 460 provides audio-visual interfaces for the application, such as graphics and image related interfaces, audio technology related interfaces, video technology related interfaces, and wireless playback (AirPlay) interfaces for audio and video transmission technologies. The touchable layer 480 provides various commonly used interface-related frameworks for application development, and the touchable layer 480 is responsible for the user's touch interaction operations on the electronic device. For example, local notification service, remote push service, advertising framework, game tool framework, message user interface (UI) framework, user interface UIKit framework, map framework, etc.
[0193] exist Fig.14 Among the frameworks shown, the frameworks related to most applications include but are not limited to: the basic framework in the core service layer 440 and the UIKit framework in the touchable layer 480. The basic framework provides many basic object classes and data types, provides the most basic system services for all applications, and has nothing to do with UI. The classes provided by the UIKit framework are basic UI class libraries for creating touch-based user interfaces. iOS applications can provide UIs based on the UIKit framework, so it provides the basic architecture of applications for building user interfaces, drawing, processing and user interaction events, responding to gestures, etc.
[0194] Among them, the method and principle of implementing data communication between third-party applications and the operating system in the IOS system can be referred to the Android system, and this manual will not go into details here.
[0195] Among them, the input device 130 is used to receive input instructions or data, and the input device 130 includes but is not limited to a keyboard, a mouse, a camera, a microphone or a touch device. The output device 140 is used to output instructions or data, and the output device 140 includes but is not limited to a display device and a speaker. In one example, the input device 130 and the output device 140 can be combined, and the input device 130 and the output device 140 are touch screens, which are used to receive touch operations on or near them by users using any suitable objects such as fingers and touch pens, and to display the user interfaces of various applications. The touch screen is usually set on the front panel of the electronic device. The touch screen can be designed as a full screen, a curved screen or a special-shaped screen. The touch screen can also be designed as a combination of a full screen and a curved screen, or a combination of a special-shaped screen and a curved screen, which is not limited in this specification.
[0196] In addition, those skilled in the art will appreciate that the structure of the electronic device shown in the above drawings does not constitute a limitation on the electronic device, and the electronic device may include more or fewer components than shown, or combine certain components, or arrange the components differently. For example, the electronic device also includes a radio frequency circuit, an input unit, a sensor, an audio circuit, a wireless fidelity (WiFi) module, a power supply, a Bluetooth module and other components, which will not be described in detail here.
[0197] In this specification, the execution subject of each step may be the electronic device described above. Optionally, the execution subject of each step is the operating system of the electronic device. The operating system may be an Android system, an IOS system, or other operating systems, which is not limited in this specification.
[0198] The electronic device of this specification may also be equipped with a display device, which may be any device capable of realizing a display function, such as a cathode ray tube display (CR), a light-emitting diode display (LED), an electronic ink screen, a liquid crystal display (LCD), a plasma display panel (PDP), etc. The user may use the display device on the electronic device 101 to view displayed text, images, videos and other information. The electronic device may be a smart phone, a tablet computer, a gaming device, an AR (Augmented Reality) device, a car, a data storage device, an audio playback device, a video playback device, a notebook, a desktop computing device, a wearable device such as an electronic watch, an electronic glasses, an electronic helmet, an electronic bracelet, an electronic necklace, electronic clothing and other devices.
[0199] exist Fig.11 In the electronic device shown, where the electronic device may be a terminal, the processor 110 may be used to call the code risk detection program stored in the memory 120, and specifically perform the following operations:
[0200] Obtain code risk detection results for source code and determine key risk codes corresponding to the code risk detection results;
[0201] Generate taint transfer analysis prompt words based on key risk codes, and generate key risk code prompt words based on key risk codes;
[0202] Construct target prompt words based on key risk code prompt words and taint transfer analysis prompt words;
[0203] Based on the target prompt word, a target large language model is used to determine the taint transfer analysis result, and based on the taint transfer analysis result, the code risk detection result is updated to obtain the target code risk detection result.
[0204] Optionally, when the processor 110 determines the key risk code corresponding to the code risk detection result, it specifically performs:
[0205] Obtain a risk function call link from the code risk detection result, and determine the target function and function variables of the target function in the risk function call link;
[0206] The key risk code of each risk function associated with the function variable is determined from the risk function call link.
[0207] Optionally, when the processor 110 determines the key risk code of each risk function associated with the function variable from the risk function call link, it specifically executes:
[0208] Determining at least one risk function associated with a function variable in a risk function call link;
[0209] Find the code statements associated with the function variables from the function code statements of the risk function to obtain the key risk codes corresponding to each risk function.
[0210] Optionally, when the processor 110 generates a key risk code prompt word based on the key risk code, specifically:
[0211] Determine the taint variable corresponding to the risk function based on the code risk detection result;
[0212] Find the target sub-function corresponding to the endpoint code statement from the key risk code corresponding to the risk function;
[0213] Generate taint transfer analysis hint words for key risk codes based on taint variables and target sub-functions.
[0214] Optionally, when the processor 110 constructs a target prompt word based on the key risk code prompt word and the taint transfer analysis prompt word, the processor 110 specifically executes:
[0215] Construct code prior knowledge prompt words for risk function call links and construct output specification prompt words;
[0216] Target prompt words are constructed based on code prior knowledge prompt words, key risk code prompt words, taint transfer analysis prompt words and output specification prompt words.
[0217] Optionally, when the processor 110 executes the construction of a code priori knowledge prompt word for the risk function call link, specifically:
[0218] Determine the risk type of the risk function in the risk function call link, and determine the code prior knowledge database information matching the risk type;
[0219] Generate code prior knowledge prompt words for risk function call links based on code prior knowledge database information.
[0220] Optionally, when the processor 110 determines the taint transfer analysis result based on the target prompt word using the target large language model, specifically:
[0221] Input the target cue word into the target large language model;
[0222] The risk function corresponding to the target prompt word and the risk function call link corresponding to the risk function are obtained through the target large language model. Based on the target prompt word, the taint variable corresponding to the risk function is determined, and the taint transfer analysis is performed on the key risk code corresponding to the risk function based on the taint variable to obtain the function taint transfer analysis result for the risk function.
[0223] Determining whether there is a next reference function of the risk function based on the risk function call link;
[0224] If it does not exist, generate the taint transfer analysis result based on the function taint transfer analysis result;
[0225] If so, obtain the reference prompt word corresponding to the reference function associated with the function taint transfer analysis result, use the reference prompt word as the target prompt word and the reference function as the risk function, and execute the step of inputting the target prompt word into the target large language model.
[0226] Optionally, when the processor 110 executes the acquisition of a reference prompt word corresponding to a reference function associated with the function taint transfer analysis result, the processor 110 specifically executes:
[0227] Determine the reference taint variable corresponding to the reference function based on the function taint transfer analysis result, and search for the reference sub-function corresponding to the endpoint code statement from the reference key risk code corresponding to the reference function;
[0228] Generate reference taint transfer analysis prompt words for reference key risk codes based on reference taint variables and reference sub-functions;
[0229] The reference prompt word corresponding to the reference function is determined based on the reference taint transfer analysis prompt word.
[0230] Optionally, when the processor 110 determines the reference tainted variable corresponding to the reference function based on the function taint transfer analysis result, the processor 110 specifically performs:
[0231] Obtain the key risk code of the risk function corresponding to the function taint transfer analysis result, and determine the target sub-function corresponding to the endpoint code statement in the key risk code;
[0232] If the function taint transfer analysis result is a taint transfer success type, the function output variable of the target sub-function is obtained, and the function output variable is used as the reference taint variable corresponding to the reference function.
[0233] Optionally, when the processor 110 updates the code risk detection result based on the taint transfer analysis result to obtain the target code risk detection result, the processor 110 specifically executes:
[0234] The type of the taint transfer analysis result is determined. If the type of the taint transfer analysis result is a link taint transfer failure type, the target risk function call link corresponding to the taint transfer failure is removed from the code risk detection result.
[0235] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0236] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in the embodiments of this specification are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions. For example, the object features, interactive behavior features and user information involved in this specification are all obtained with full authorization.
[0237] The above disclosure is only the preferred embodiment of this specification, which certainly cannot be used to limit the scope of rights of this specification. Therefore, equivalent changes made according to the claims of this specification are still within the scope covered by this specification.
Claims
1. A code risk detection method, the method comprising: Obtaining a code risk detection result for the source code, and determining a key risk code corresponding to the code risk detection result; Generate a taint transfer analysis prompt word based on the key risk code, and generate a key risk code prompt word based on the key risk code; Constructing a target prompt word based on the key risk code prompt word and the taint transfer analysis prompt word; A target large language model is used to determine a taint transfer analysis result based on the target prompt word, and the code risk detection result is updated based on the taint transfer analysis result to obtain a target code risk detection result.
2. According to the method of claim 1, determining the key risk code corresponding to the code risk detection result comprises: Obtaining a risk function call link from the code risk detection result, and determining a target function in the risk function call link and a function variable of the target function; A key risk code of each risk function associated with the function variable is determined from the risk function call link.
3. The method according to claim 2, wherein determining the key risk code of each risk function associated with the function variable from the risk function call link comprises: Determining at least one risk function associated with the function variable in the risk function call link; The code statements associated with the function variables are searched from the function code statements of the risk function to obtain the key risk codes corresponding to each risk function.
4. The method according to claim 2, wherein generating a key risk code prompt word based on the key risk code comprises: Determine a taint variable corresponding to the risk function based on the code risk detection result; Find the target sub-function corresponding to the endpoint code statement from the key risk code corresponding to the risk function; A taint transfer analysis prompt word for the key risk code is generated based on the taint variable and the target sub-function.
5. The method according to claim 2, wherein the step of constructing a target prompt word based on the key risk code prompt word and the taint transfer analysis prompt word comprises: Construct code prior knowledge prompt words for the risk function call link, and construct output specification prompt words; A target prompt word is constructed based on the code prior knowledge prompt word, the key risk code prompt word, the taint transfer analysis prompt word and the output specification prompt word.
6. According to the method of claim 5, the step of constructing a priori knowledge hint words for the risk function call link comprises: Determine the risk type of the risk function in the risk function call link, and determine the code prior knowledge database information matching the risk type; A code prior knowledge prompt word for the risk function call link is generated based on the code prior knowledge database information.
7. The method according to any one of claims 2 to 6, wherein determining the taint transfer analysis result based on the target prompt word using a target large language model comprises: Inputting the target prompt word into a target large language model; The risk function corresponding to the target prompt word and the risk function call link corresponding to the risk function are obtained through the target large language model, the taint variable corresponding to the risk function is determined based on the target prompt word, and the taint transfer analysis is performed on the key risk code corresponding to the risk function based on the taint variable to obtain a function taint transfer analysis result for the risk function; Determining whether there is a next reference function of the risk function based on the risk function call link; If not, generating a taint transfer analysis result based on the function taint transfer analysis result; If so, obtain the reference prompt word corresponding to the reference function associated with the function taint transfer analysis result, use the reference prompt word as the target prompt word and the reference function as the risk function, and execute the step of inputting the target prompt word into the target large language model.
8. According to the method of claim 7, the step of obtaining a reference prompt word corresponding to the reference function associated with the function taint transfer analysis result comprises: Determine the reference taint variable corresponding to the reference function based on the function taint transfer analysis result, and search for the reference sub-function corresponding to the endpoint code statement from the reference key risk code corresponding to the reference function; Generate a reference taint transfer analysis prompt word for the reference key risk code based on the reference taint variable and the reference sub-function; A reference prompt word corresponding to the reference function is determined based on the reference taint transfer analysis prompt word.
9. The method according to claim 8, wherein determining the reference taint variable corresponding to the reference function based on the function taint transfer analysis result comprises: Obtaining a key risk code of a risk function corresponding to the function taint transfer analysis result, and determining a target sub-function corresponding to an endpoint code statement in the key risk code; If the function taint transfer analysis result is a taint transfer success type, the function output variable of the target sub-function is obtained, and the function output variable is used as a reference taint variable corresponding to the reference function.
10. The method according to claim 2, wherein the updating of the code risk detection result based on the taint transfer analysis result to obtain a target code risk detection result comprises: The type of the taint transfer analysis result is determined. If the type of the taint transfer analysis result is a link taint transfer failure type, the target risk function call link corresponding to the taint transfer failure is removed from the code risk detection result.
11. A code risk detection device, the device comprising: An acquisition module, adapted to acquire a code risk detection result for a source code, and determine a key risk code corresponding to the code risk detection result; A generating module, adapted to generate a taint transfer analysis prompt word based on the key risk code, and generate a key risk code prompt word based on the key risk code; A construction module, adapted to construct a target prompt word based on the key risk code prompt word and the taint transfer analysis prompt word; The updating module is adapted to determine the taint transfer analysis result based on the target prompt word by using a target large language model, and to update the code risk detection result based on the taint transfer analysis result to obtain a target code risk detection result.
12. A computer storage medium storing a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the method steps according to any one of claims 1 to 10.
13. A computer program product, the computer program product storing at least one instruction, wherein the at least one instruction is loaded by a processor and executes the method steps according to any one of claims 1 to 10.
14. An electronic device comprising: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the method steps as claimed in any one of claims 1 to 10.
Citation Information
Patent Citations
Honeypot protection method and device, storage medium and electronic equipment
CN116800525A
Code repairing method and device, equipment and medium
CN117555720A
Code processing method and code processing model training method
CN117806967A
Sensitive information leakage monitoring and linkage large model analysis method
CN117874754A
Code risk detection method, and deep learning model training method and device
CN117909235A
Cited By
Security detection method, device, equipment, medium and product
CN119538266A
A language model-based reverse shell detection method, device, equipment, medium and product for cloud security protection and business risk identification
CN119538266B
Firmware logic vulnerability detection method and system based on large language model thinking chain, electronic equipment and computer readable storage medium
CN119691757A
Firmware Logic Vulnerability Detection Method, System, Electronic Device and Computer Readable Storage Medium Based on the Chain of Thought of Large Language Model
CN119691757B
Code analysis method and device based on interactive model, and electronic equipment
CN119829030A
