API penetration test method and device based on LLM, medium and product

Through the API penetration testing method based on LLM, the test case framework is automatically identified and constructed, vulnerabilities are monitored in real time and test cases are updated, which solves the low efficiency and error-prone problems of existing API penetration testing and achieves a more efficient and accurate API security assessment. .

CN118535448AActive Publication Date: 2024-08-23北京安胜华信科技有限公司

Patent Information

Application Number
CN202410307740.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-18
Publication Date
2024-08-23
Estimated Expiration
2044-03-18

AI Technical Summary

Technical Problem

Existing API penetration testing is inefficient and error-prone. Manual testing is time-consuming and difficult to fully cover all interfaces and functions.

Method used

Adopt an LLM-based API penetration testing method to build a target test case framework by identifying test identifiers, automatically identify and obtain test cases, monitor vulnerabilities in real time, and update test cases to improve efficiency and accuracy.

Benefits of technology

Significantly improves the efficiency and accuracy of API penetration testing, reduces the probability of human error, reduces testing time, and enhances the reflection of API security status.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118535448A
    Figure CN118535448A
Patent Text Reader

Abstract

The invention relates to the technical field of penetration testing, in particular to an LLM-based API penetration testing method and device, a medium and a product, the method comprises the steps that a test identifier contained in a to-be-tested API is recognized, a corresponding target test case frame is determined based on the test identifier, and the target test case frame is formed based on a test requirement of the to-be-tested API and an LLM model. The target test case framework comprises a plurality of function nodes and target test cases corresponding to the function nodes; performing penetration testing on the to-be-tested API by utilizing the target test case framework; after penetration tests corresponding to all function nodes are completed, vulnerability penetration results corresponding to all vulnerability function nodes are counted, the statistical results are fed back, and the vulnerability function nodes are function nodes with penetration results having vulnerabilities. According to the method and the device, the efficiency of performing penetration testing on the API can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of penetration testing, and in particular to an API penetration testing method, equipment, medium and product based on LLM. Background Art

[0002] API (Application Programming Interface) is an application programming interface that can serve as a communication bridge between different systems or services. Through API, different systems or services can collaborate with each other and transmit data and instructions. Therefore, the security of API directly affects the security of the entire application system or service. If there are security risks in API, hackers or related malicious websites will attack API based on the security risks, thereby stealing sensitive data in the system or service, which may cause significant losses to the system or service.

[0003] In the related technology, manual testing is generally used to perform penetration testing on APIs to promptly discover hidden security risks in APIs. However, since APIs contain a large number of interfaces and functions of different levels, if all interfaces and functions need to be fully covered, the penetration testing process may be time-consuming. In addition, the error rate of the test results obtained through manual testing is also high, and the penetration testing efficiency is low. Summary of the invention

[0004] In order to improve the efficiency of penetration testing of API, the present application provides an API penetration testing method, equipment, medium and product based on LLM.

[0005] In the first aspect, the present application provides an API penetration testing method based on LLM, which adopts the following technical solution: An API penetration testing method based on LLM, including: Identify the test identifier contained in the API to be tested, and determine the corresponding target test case framework based on the test identifier, wherein the target test case framework is based on the test requirements and LLM model of the API to be tested, and the target test case framework includes multiple function nodes and a target test case corresponding to each function node; Performing penetration testing on the API to be tested using the target test case framework; After the penetration tests corresponding to all functional nodes are completed, the vulnerability penetration results corresponding to all vulnerable functional nodes are counted, and the statistical results are fed back. The vulnerable functional nodes are functional nodes with vulnerabilities in the penetration results.

[0006] By adopting the above technical solution, the target test case framework corresponding to each API to be tested is constructed through LLM, which can cover various functions and boundary conditions in the API to be tested to a large extent, and this automatic identification of test identifiers and framework acquisition method is convenient for avoiding the tedious process of manual search and screening, thereby improving the efficiency of the penetration test preparation process. In addition, during the penetration test process, the vulnerability situation corresponding to each functional node is monitored and analyzed in real time, and whether there are vulnerable functional nodes is monitored. This automated statistical method can not only improve the efficiency of the penetration test process, but also reduce the error probability that may be caused by manual statistics. By automatically identifying test identifiers, obtaining test case frameworks, conducting penetration tests, and statistically and feedbacking results, it is easy to solve the problems of high time consumption and high error rate in the penetration test process of the API to be tested, thereby improving the efficiency of the penetration test process.

[0007] In a possible implementation, the penetration test of the API to be tested using the target test case framework includes: Obtaining a vulnerability penetration result corresponding to the vulnerability function node and an associated test case corresponding to an associated function node, wherein the vulnerability function node is a function node where a vulnerability exists in the penetration result; Identify vulnerability features contained in the vulnerability penetration result, and identify associated preconditions of the associated test cases corresponding to the associated function nodes, and determine target preconditions based on the vulnerability features and the associated preconditions; Based on the target precondition, an update test case is determined from a preset test case library, and a penetration test is performed on the API to be tested based on the update test case and the target test case framework.

[0008] By adopting the above technical solution, since there may be an association relationship between the various functional nodes in the API to be tested, once an abnormality occurs in the current functional node, it may affect the pre-input of the associated functional node, etc., and determine the new test case by real-time monitoring and analyzing the vulnerability situation corresponding to each functional node, and timely adjusting the pre-input of the associated functional node, instead of using the original test case after the vulnerability occurs. Since the updated test case is closer to the actual security requirements, the security status of the API to be tested can be more accurately reflected by timely updating the test case of the associated functional node, thereby facilitating the reduction of the error rate of the penetration test results. In addition, when a vulnerability occurs, it is corrected in time and the updated test case is used to continue the penetration test, without the need for manual supervision and manual generation of test cases, which is facilitating the reduction of the time used for the entire penetration test process, thereby facilitating the improvement of the efficiency of penetration testing of the API to be tested.

[0009] In one possible implementation, the process of determining whether the penetration tests corresponding to all functional nodes are completed includes: Identify the location node of the current function node in the target test case framework, and record the number of penetrations of the API to be tested in the target test case framework; If the location node is a leaf node, and the number of penetrations is consistent with the number of functional nodes included in the target test case framework, it is determined that the API to be tested has completed the penetration test.

[0010] By adopting the above technical solution, by identifying the location node corresponding to the current function node and the number of penetrations experienced by the API to be tested, it is possible to jointly determine whether the API to be tested has completed the penetration test, thereby improving the accuracy of the judgment result. In addition, by using automated identification to determine whether the API to be tested has completed the penetration test, it is possible to improve the judgment efficiency, reduce the possibility of manual intervention and misjudgment, and thus improve the reliability of the judgment result.

[0011] In one possible implementation, the process of forming the target test case framework includes: Acquire the test requirements of the API to be tested, identify the requirement identifier corresponding to each test requirement, and functionally divide the test requirements according to each requirement identifier to obtain at least one functional requirement group; Import each functional requirement group into the trained LLM model to obtain the test cases corresponding to each functional requirement group; Determine each functional requirement group as a functional node, and determine the association relationship between each functional node based on the test requirements included in each functional requirement group; The target test case framework is obtained according to the association relationship between each functional node and the test case corresponding to each functional node.

[0012] By adopting the above technical solution, by identifying the requirement identifier corresponding to each test requirement and dividing the test requirements into functions, scattered test requirements can be organized into structured functional requirement groups. This helps to more clearly understand the various aspects of the API to be tested, so as to ensure that the penetration test work is more systematic and organized. Since the test case framework is automatically generated according to the functional requirement group and takes into account the association relationship between functional nodes, the use of the test case framework for penetration testing of the API to be tested can reduce test omissions, thereby improving the accuracy of the penetration test results.

[0013] In a possible implementation, determining the target precondition based on the vulnerability feature and the associated precondition includes: Identify the combination position corresponding to the vulnerability feature from the associated preconditions, and clear the combination position; Determine, according to the vulnerability feature and a preset mapping relationship, a replacement character corresponding to the vulnerability feature, wherein the preset mapping relationship is a correspondence relationship between the vulnerability feature and the replacement character; The replacement character is written into the cleared combination position to obtain the target precondition.

[0014] By adopting the above technical solution, the combination position is identified and the precondition is updated by updating the characters at the combination position instead of regenerating a new precondition, so that the rate of determining the target precondition is improved. In addition, the corresponding replacement characters are determined by the vulnerability characteristics, so that the correlation between the target precondition and the associated precondition is improved.

[0015] In a possible implementation, after performing a penetration test on the API to be tested based on the updated test case and the target test case framework, the method further includes: The updated test case and the original test case are stored in parallel in the target test case framework, and the usage frequency of the updated test case and the original test case within a preset time period is recorded; If the usage frequency of the updated test case within the preset time period is higher than the usage frequency of the original test case within the preset time period, the target test case framework is updated according to the updated test case.

[0016] By adopting the above technical solution, by storing the updated test cases and the original test cases in parallel, it is convenient to deal with different penetration testing situations. After analyzing and observing the usage frequency of the two test cases over a period of time, the target test case framework is deduplicated according to the analysis and observation results, so as to improve the processing rate when using the target test case framework.

[0017] In one possible implementation, the method further includes: When an access request is detected, a progress display frame is fed back, wherein the formation process of the progress display frame includes: Identify a functional node that is currently in a penetration test phase, and mark it in the target test case framework according to a first mark, so as to indicate that a penetration test is being performed based on the functional node; When it is detected that the penetration test of the functional node is completed, the first mark is replaced with a second mark, indicating that the penetration test based on the functional node has been completed; When it is detected that the functional node is a vulnerable functional node, the simulated repair time of the vulnerable functional node is determined based on the simulated test data, and the first mark is replaced with the third mark to indicate that there is a vulnerability based on the penetration test of the functional node, and the simulated repair time is superimposed on the third mark.

[0018] By adopting the above technical solution and the recording and identification functions of the progress display framework, each step of the penetration test process is clearly recorded, making the penetration test process more transparent and traceable, which is helpful for subsequent troubleshooting and auditing. In addition, by superimposing the simulated repair time, it helps relevant staff to better evaluate the impact and priority of the vulnerability, thereby formulating a more effective repair strategy.

[0019] In a second aspect, the present application provides an electronic device, which adopts the following technical solution: An electronic device, comprising: at least one processor; Memory; At least one application, wherein the at least one application is stored in a memory and configured to be executed by at least one processor, and the at least one application is configured to: execute the above-mentioned LLM-based API penetration testing method.

[0020] In a third aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution: A computer-readable storage medium includes: a computer program that can be loaded by a processor and execute the above-mentioned LLM-based API penetration testing method.

[0021] In a fourth aspect, the present application provides a computer program product, which adopts the following technical solution: A computer program product includes a computer program, and when the computer program is executed by a processor, the LLM-based API penetration testing method is implemented.

[0022] In summary, the present application includes at least one of the following beneficial technical effects: By building a target test case framework corresponding to each API to be tested through LLM, various functions and boundary conditions in the API to be tested can be covered to a large extent. This automated identification of test identifiers and framework acquisition method makes it easy to avoid the tedious process of manual search and screening, thereby improving the efficiency of the penetration test preparation process. In addition, during the penetration test process, the vulnerability situation corresponding to each functional node is monitored and analyzed in real time, and whether there are vulnerable functional nodes is monitored. This automated statistical method can not only improve the efficiency of the penetration test process, but also reduce the error probability that may be caused by manual statistics. By automatically identifying test identifiers, obtaining test case frameworks, conducting penetration tests, and statistically and feedbacking results, it is easy to solve the problems of high time consumption and high error rate in the penetration test process of the API to be tested, thereby improving the efficiency of the penetration test process.

[0023] Since there may be associations between the various functional nodes in the API to be tested, once an abnormality occurs in the current functional node, it may affect the pre-input of the associated functional node, etc. By real-time monitoring and analyzing the vulnerability situation corresponding to each functional node, and timely adjusting the pre-input of the associated functional node, a new test case is determined instead of using the original test case after the vulnerability occurs. Since the updated test case is closer to the actual security requirements, the security status of the API to be tested can be more accurately reflected by timely updating the test case of the associated functional node, thereby facilitating the reduction of the error rate of the penetration test results. In addition, when a vulnerability occurs, it is corrected in time and the updated test case is used to continue the penetration test without manual supervision and manual generation of test cases, which is facilitating the reduction of the time used for the entire penetration test process, thereby facilitating the improvement of the efficiency of penetration testing of the API to be tested. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 It is a flow chart of an API penetration testing method based on LLM in an embodiment of the present application; Figure 2 It is a flowchart of a test case updating method in an embodiment of the present application; Figure 3 It is a structural schematic diagram of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION

[0025] The following is combined with Figure 1-3 This application is described in further detail.

[0026] After reading this specification, those skilled in the art may make non-creative modifications to this embodiment as needed, but such modifications are protected by patent law as long as they are within the scope of the claims of this application.

[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0028] Specifically, the embodiment of the present application provides an API penetration testing method based on LLM, which is performed by an electronic device, which can be a server or a terminal device, wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited thereto. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiment of the present application.

[0029] refer to Figure 1 , Figure 1 : is a flow chart of an API penetration testing method based on LLM in an embodiment of the present application, the method includes steps S110 to S130, wherein: Step S110: Identify the test identifier contained in the API to be tested, and determine the corresponding target test case framework based on the test identifier. The target test case framework is based on the test requirements and LLM model of the API to be tested. The target test case framework contains multiple functional nodes and target test cases corresponding to each functional node.

[0030] Specifically, the test identifier can be a character or a code. The specific identifier is not specifically limited in the embodiments of this application and can be set by relevant technical personnel. Since different APIs to be tested may have different contents and functions to be tested, a corresponding target test case framework is set for each API to be tested in the embodiments of this application to cope with the penetration test conditions that different APIs to be tested may encounter. The test case framework contains multiple functional nodes, and each functional node corresponds to a test case, which is used to perform penetration testing on the corresponding functional node of the API to be tested. The test case is a set of test inputs, execution conditions, expected results and other elements to complete the data for a specific requirement or target test.

[0031] The LLM (Large Language Model) model, also known as a large language model or large model, is a language model built using an artificial neural network. It can train the requirement text through self-supervised learning or semi-supervised learning to obtain test cases corresponding to the requirement text, which can greatly reduce the time for manually writing test cases, thereby facilitating the improvement of the efficiency of penetration test preparation.

[0032] Furthermore, the process of forming the target test case framework may specifically include: Obtain the test requirements of the API to be tested, identify the requirement identifier corresponding to each test requirement, and divide the test requirements into functions according to each requirement identifier to obtain at least one functional requirement group, each functional requirement group containing at least two test requirements; import each functional requirement group into the trained LLM model to obtain the test cases corresponding to each functional requirement group; determine each functional requirement group as a functional node, and determine the association relationship between each functional node based on the test requirements contained in each functional requirement group; obtain the target test case framework according to the association relationship between each functional node and the test case corresponding to each functional node.

[0033] Specifically, the test requirements of the API to be tested are the directions in which the API to be tested needs to be penetrated and tested. The test requirements may include: functional testing, that is, verifying the API request and response to be tested, ensuring that the returned data format and structure are consistent with expectations, and verifying whether the business logic of the API to be tested is correct; performance testing, that is, testing the response time, throughput, concurrency, etc. of the API to be tested under different loads and conditions to ensure that the API to be tested can meet the performance requirements of the actual application scenario; security testing, that is, testing the potential security risks of the API to be tested, such as input validation, authorization, access control, etc., to ensure that the API to be tested can resist common security attacks, such as SQL injection, cross-site scripting (XSS), etc.; boundary value testing, that is, testing the boundary value of the parameters accepted by the API to be tested, such as whether the interface can be processed normally when the passed parameters are large enough or negative. The test requirements corresponding to different APIs to be tested may be different. For example, the test requirements may also include stability testing, compatibility testing, document consistency testing, etc. The specific content of the test requirements is not specifically limited in the embodiments of this application. Different test requirements correspond to a requirement identifier. The corresponding test requirement can be located according to the requirement identifier corresponding to the API to be tested. The same API to be tested may contain multiple requirement identifiers. The specific number of requirement identifiers is not specifically limited in the embodiments of this application.

[0034] Different requirement identifiers may belong to the same type of functions. For example, fault-tolerant processing tests and compatibility tests can be divided into the same type of functions, such as quality assurance functions. The requirement identifiers belonging to the same type of functions have the same identification characters. By identifying the identification characters in different requirement identifiers, multiple test requirements can be functionally divided to obtain at least one functional requirement group. The functional requirement group may contain one test requirement or multiple test requirements. The number of test requirements contained in the functional requirement group is not specifically limited in the embodiments of this application. All test requirements contained in the functional requirement group are imported into the trained LLM model as a whole requirement to obtain the corresponding test case. The test case is a group of data composed of test input, execution conditions, expected results and other elements to complete the test of a specific requirement or target. The test case can describe the penetration test steps of the API to be tested based on the functional requirement group in the form of a document, so as to perform a penetration test on a certain function in the API to be tested to determine whether a certain function of the API to be tested meets a specific requirement. The LLM model is obtained after training with a large amount of sample data, and a large amount of sample data contains a large number of test requirements and artificially generated test cases.

[0035] Each functional requirement group corresponds to the same or similar functions. There may be associations between the functions corresponding to different functional requirement groups. For example, functional requirement group a needs to conduct a penetration test on the security of the login process, and functional requirement group b needs to conduct a penetration test on the security of the data area accessible to the login user. Since the premise for the login user to access the data is a successful login, and there is a correspondence between the login identity and the access rights, it can be determined that there is an association between functional requirement group a and functional requirement group b. It is possible to determine whether the functional requirement group has an association relationship with other functional requirement groups by identifying whether the test requirements contained in each functional requirement group contain an association identifier. If an association identifier is contained, other functional requirement groups with which it has an association relationship can be determined based on the association mapping relationship. There may be 0, 1, or more functional requirement groups with which the same requirement functional group has an association relationship. Each functional requirement group is determined as a functional node, and the functional nodes with an association relationship are connected, and finally the target test case framework corresponding to the API to be tested can be obtained.

[0036] By identifying the requirement identifier corresponding to each test requirement and dividing the test requirements into functions, scattered test requirements can be organized into structured functional requirement groups. This helps to more clearly understand the various aspects of the API to be tested, ensuring that the penetration testing work is more systematic and organized.

[0037] Step S120: Perform penetration testing on the API to be tested using the target test case framework.

[0038] Specifically, locate the starting function node from the target test case framework, obtain the starting test case corresponding to the starting function node, and perform a penetration test based on the starting function node on the API to be tested based on the starting test case. When the penetration test based on the starting function node is completed, it can automatically flow to the next function node according to the association relationship between the function nodes to perform a penetration test based on the next function node. For example, the current function node is a login process penetration test, and the corresponding test case may be an attack method that imitates a hacker or malicious website, bypassing the defense measures of the API to be tested for the login process, directly bypassing the identity authentication of the API to be tested, and forcibly accessing the API to be tested. If the response result given by the API to be tested is the same as the expected result corresponding to the test case, it indicates that the current function node has completed the penetration test.

[0039] Step S130: After the penetration tests corresponding to all functional nodes are completed, the vulnerability penetration results corresponding to all vulnerable functional nodes are counted, and the statistical results are fed back. The vulnerable functional node is the functional node with a vulnerability in the penetration result.

[0040] Specifically, if the response result given by the API to be tested is different from the expected result corresponding to the test case, it indicates that the current function node has a vulnerability, and the current function node is determined to be a vulnerable function node. Since there is an association between function nodes, and the preconditions contained in the test case corresponding to the next function node may be related to the penetration result of the current function node, if there is a vulnerable function node, it may affect the penetration test effect of the next function node. In order to reduce the error rate of the penetration result, when a vulnerable function node is detected, steps S1 to S3 are also included, such as Figure 2 As shown, where: Step S1: Obtain vulnerability penetration results corresponding to the vulnerability function node and associated test cases corresponding to the associated function node, where the vulnerability function node is a function node where a vulnerability exists in the penetration result.

[0041] Specifically, the penetration result corresponding to the vulnerability function node includes the specific vulnerability situation. For example, when the vulnerability function node is a login process penetration test, the specific vulnerability situation may be an authentication defense vulnerability, that is, a hacker or a malicious website may bypass the authentication defense operation of the API to be tested and forcibly access the API to be tested. At this time, the API to be tested may face the situation where sensitive data is stolen or tampered with.

[0042] Step S2: Identify vulnerability features contained in the vulnerability penetration results, identify associated preconditions of associated test cases corresponding to associated function nodes, and determine target preconditions based on the vulnerability features and associated preconditions.

[0043] Step S3: Determine an updated test case from a preset test case library based on the target preconditions, and perform a penetration test on the API to be tested based on the updated test case and the target test case framework.

[0044] Specifically, the vulnerability characteristics corresponding to the specific vulnerability situation can be identified from the vulnerability penetration results. The associated preconditions corresponding to the associated function nodes can be updated according to the vulnerability characteristics. The updated associated preconditions are more adapted to the actual penetration test situation. After the associated preconditions are updated, the associated test cases are updated.

[0045] When vulnerabilities appear, they are corrected in a timely manner and the updated test cases are used to continue penetration testing without the need for human supervision and manual generation of test cases. This helps to reduce the time used in the entire penetration testing process, thereby improving the efficiency of penetration testing of the API to be tested.

[0046] If during the penetration test of the current functional node, the response result given by the API to be tested is the same as the expected result corresponding to the test case, it indicates that the current functional node has completed the penetration test; if during the penetration test of the current functional node, the response result given by the API to be tested is different from the expected result corresponding to the test case, it also indicates that the current functional node has completed the penetration test, and at the same time, it is necessary to update the associated test cases of the associated functional nodes based on the vulnerability penetration results of the current functional node.

[0047] After the penetration tests corresponding to all functional nodes are completed, the vulnerability penetration results corresponding to all vulnerable functional nodes are integrated and fed back. The number of vulnerable functional nodes in the feedback content is not specifically limited in the embodiment of the present application.

[0048] By building a target test case framework corresponding to each API to be tested through LLM, various functions and boundary conditions in the API to be tested can be covered to a large extent. This automated identification of test identifiers and framework acquisition method makes it easy to avoid the tedious process of manual search and screening, thereby improving the efficiency of the penetration test preparation process. In addition, during the penetration test process, the vulnerability situation corresponding to each functional node is monitored and analyzed in real time, and whether there are vulnerable functional nodes is monitored. This automated statistical method can not only improve the efficiency of the penetration test process, but also reduce the error probability that may be caused by manual statistics. By automatically identifying test identifiers, obtaining test case frameworks, conducting penetration tests, and statistically and feedbacking results, it is easy to solve the problems of high time consumption and high error rate in the penetration test process of the API to be tested, thereby improving the efficiency of the penetration test process.

[0049] Furthermore, in order to improve the accuracy of the judgment result, the process of judging whether the penetration tests corresponding to all functional nodes are completed may specifically include: Identify the location node of the current function node in the target test case framework, and record the number of penetrations of the API to be tested in the target test case framework; if the location node is a leaf node, and the number of penetrations is consistent with the number of function nodes contained in the target test case framework, it is determined that the API to be tested has completed the penetration test.

[0050] Specifically, the target test case framework includes a starting function node and a leaf function node. Penetration testing can be performed based on multiple function nodes in the target test case framework at the same time, or one by one. The specific penetration test sequence is not specifically limited in the embodiment of the present application. Therefore, only by judging whether the current function node is a leaf node, it cannot be determined whether the penetration test has been performed on the API to be tested based on all function nodes in the target test case framework.

[0051] In the embodiment of the present application, by identifying whether the current functional node of the room is a leaf node and recording the number of penetrations of the API to be tested based on the target test case framework, it is jointly determined whether the penetration test of the API to be tested has been completed based on the location node corresponding to the current functional node and the number of penetrations experienced by the API to be tested, thereby facilitating improving the accuracy of the judgment result.

[0052] Furthermore, in order to improve the speed of determining the target precondition, the target precondition is determined based on the vulnerability characteristics and the associated precondition, which may specifically include: Identify the combination position corresponding to the vulnerability feature from the associated precondition, and clear the combination position; determine the replacement character corresponding to the vulnerability feature based on the vulnerability feature and the preset mapping relationship, the preset mapping relationship is the correspondence between the vulnerability feature and the replacement character; write the replacement character into the cleared combination position to obtain the target precondition.

[0053] Specifically, the content of the precondition varies depending on the different penetration test scenarios in which the API to be tested is located, but it usually involves a description of the conditions that must be met before executing a certain penetration test content, or a combination of conditions that must be met. For example, before executing the penetration test corresponding to function node b, the combination of conditions that need to be met may be "xxx, condition 1 is met, condition 2 is met", where "xxx" may be the penetration result of the previous function node a. When the previous function node a is a vulnerable function node, function node b may be used as the associated function node of function node a, and the "precondition xxx, condition 1 is met, condition 2 is met" corresponding to function node b may be used as the associated precondition. At this time, the associated precondition needs to be adjusted. The vulnerability feature can be used to determine that the combination position that needs to be adjusted is the first position, that is, the position of "xxx" in the associated precondition. Different combination positions in the associated precondition have corresponding position identifiers. By matching the position identifier with the vulnerability feature, the combination position of the vulnerability feature in the associated precondition combination can be determined. The correspondence between vulnerability features and location identifiers can be determined by relevant staff based on historical penetration testing experience and uploaded to the electronic device in advance. The specific content of the correspondence is not specifically limited in the implementation of this application and can be adjusted and modified by relevant staff based on actual penetration testing experience.

[0054] The vulnerability feature also has a corresponding relationship with the replacement character. The corresponding replacement character can be uniquely identified according to the vulnerability feature. The specific content of the replacement character is not specifically limited in the application embodiment. As long as it can characterize that the precondition content of the combination position corresponding to the vulnerability feature has an abnormality or a vulnerability, the replacement character can be written into the combination position corresponding to the vulnerability feature to update the associated precondition. The combination position can be cleared and then the replacement character can be written, or the replacement character can be made to directly overwrite the corresponding content of the original combination position. The specific method is not specifically limited in the embodiment of this application. By identifying the combination position and updating the precondition by updating the character at the combination position, rather than regenerating a new precondition, it is convenient to improve the rate of determining the target precondition.

[0055] Further, in order to improve the processing rate when using the target test case framework, in the embodiment of the present application, after the penetration test of the API to be tested is performed based on the updated test case and the target test case framework, the following is further included: The updated test cases are stored in parallel with the original test cases in the target test case framework, and the usage frequency of the updated test cases and the original test cases within a preset time period is recorded; if the usage frequency of the updated test cases within the preset time period is higher than the usage frequency of the original test cases within the preset time period, the target test case framework is updated according to the updated test cases.

[0056] Specifically, the updated test case is a test case updated based on the vulnerability feature, and the original test case is a test case containing the vulnerability feature content. The data storage location of the original test case can be identified and confirmed in the target test case, and a parallel storage area is added based on the data storage location to write the updated test case into the parallel storage area. The test case is not cleared after the updated test case is used, or the updated test case is directly replaced with the original test case. Instead, the clearing items are determined by the usage of the updated test case and the original test case in the future.

[0057] Since the same API to be tested may need to be repeatedly penetrated tested, when the penetration requirement remains unchanged, the same target test case can be used for penetration testing. The preset time period is the early period of the corresponding time period when the API to be tested is repeatedly penetrated tested. For example, when the API to be tested needs to be repeatedly penetrated tested, the corresponding time period is 10:00-10:30, and the preset time period may be 10:00-10:08. The requirements and methods for penetration testing of different APIs to be tested may be different. Therefore, different preset time periods correspond to different APIs to be tested. The specific length of the preset time period is not specifically limited in the embodiments of the present application.

[0058] The usage frequency a of the updated test case and the usage frequency b of the original test case in the preset time period are counted. When the usage frequency a is higher than the usage frequency b, it indicates that the updated test case is more suitable for the penetration test in the future. At this time, the original test case can be directly removed from the target test case framework and the updated test case can be retained. After analyzing and observing the usage frequency of two test cases over a period of time, the target test case framework is deduplicated according to the analysis and observation results to improve the processing rate when using the target test case framework.

[0059] Furthermore, in order to make the penetration testing process more transparent and traceable, the method provided in the embodiment of the present application also includes: When an access request is detected, a progress display frame is fed back, wherein the formation process of the progress display frame includes: Identify the functional node that is currently in the penetration test stage, and mark it in the target test case framework according to the first mark, which is used to indicate that the penetration test is being performed based on the functional node; when it is detected that the penetration test on the functional node has been completed, replace the first mark with the second mark, indicating that the penetration test based on the functional node has been completed; when the functional node is detected to be a vulnerable functional node, determine the simulated repair time of the vulnerable functional node based on the simulated test data, and replace the first mark with the third mark, indicating that there is a vulnerability in the penetration test based on the functional node, and add the simulated repair time to the third mark.

[0060] Specifically, the specific first mark, second mark and third mark are not specifically limited in the embodiment of the present application. The first mark is used to indicate that a penetration test is being performed based on a certain functional node at the current moment. The yellow mark can be used to mark the position of the functional node in yellow in the target test case framework; the second mark is used to indicate that the penetration test based on a certain functional node at the current moment has been completed, and there are no loopholes in the penetration process. The green mark can be used to change the position of the functional node from yellow to green in the target test case framework; the third mark is used to indicate that the penetration test based on a certain functional node at the current moment has been completed, but there are loopholes in the penetration process. The red mark can be used to change the position of the functional node from yellow to red in the target test case framework, so as to obtain a progress display framework, which is a target test case framework including the first mark, the second mark and the third mark. By observing the different marks in the progress display framework, you can intuitively view the test stage of the API to be tested during the penetration test process, and you can intuitively view the penetration results when the penetration test is performed based on different functional nodes.

[0061] The simulation test data contains the time required to simulate the repair of vulnerabilities after vulnerabilities appear in different vulnerability function nodes. When a vulnerability function node appears, the simulated repair time for repairing the current vulnerability function node is determined based on the simulation test data, and the simulated repair time is superimposed on the current vulnerability function node based on AR technology, which helps relevant staff to better evaluate the impact and priority of the vulnerability, so as to formulate a more effective repair strategy. The display form of the simulated repair time can be "there is a vulnerability, and the repair time is xx seconds", and the specific display form is not specifically limited in the embodiment of this application. If the vulnerability is not repaired within the simulated repair time, maintenance prompt information will be generated according to the vulnerability function node, and the generated maintenance prompt information will be sent to the maintenance queue for maintenance queuing. The maintenance queue is a storage space for storing maintenance prompt information, and the maintenance queue is sorted according to the time between the end of the repair time and the current time. For example, the repair time of maintenance reminder information 1 ends at 10:00, and the repair time of maintenance reminder information 2 ends at 10:20. In the maintenance queue, maintenance reminder information 1 is located at maintenance reminder information 2. When the vulnerability function node corresponding to the maintenance reminder information is a key function node, queue interruption processing can be performed according to the importance level of the function node, that is, vulnerability function nodes with higher importance levels are repaired first.

[0062] Since penetration testing can be performed based on multiple functional nodes in the target test case framework at the same time, penetration testing in multiple functional directions can be performed on the API to be tested at the same time, so the target test case framework may contain multiple functional nodes marked with the first mark at the same time. When the target test case framework contains multiple vulnerable functional nodes marked with the third mark, the node position of each vulnerable functional node in the target test case framework can be identified, and the abnormal area can be determined based on each node position to determine whether the multiple vulnerable functional nodes are located at the same level. If they are located at the same level, an abnormal warning instruction is generated. The target test case framework can be regarded as a node tree, and the number of nodes is a hierarchical set consisting of n (n>0) finite function nodes. In this set, each function node has a specific level, which is determined according to the relative position between each function node and the starting function node. The starting function node is located in the first layer, and the child nodes of the starting function node are located in the second layer, and so on. When multiple vulnerable function nodes are located at the same level, the penetration results generated after penetration testing based on multiple vulnerable function nodes may have a concentrated and significant impact on the nodes of the next layer. This concentrated impact may cause the penetration testing process of the API to be tested to be severely restricted or test abnormalities. Therefore, when multiple vulnerable function nodes are detected at the same level, an abnormal warning signal needs to be generated immediately to remind relevant staff to adjust the penetration testing process in time.

[0063] An electronic device is provided in an embodiment of the present application, such as Figure 3 As shown, Figure 3 The electronic device 300 shown includes: a processor 301 and a memory 303. The processor 301 and the memory 303 are connected, such as through a bus 302. Optionally, the electronic device 300 may also include a transceiver 304. It should be noted that in actual applications, the transceiver 304 is not limited to one, and the structure of the electronic device 300 does not constitute a limitation on the embodiments of the present application.

[0064] The processor 301 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. The processor 301 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0065] The bus 302 may include a path to transmit information between the above components. The bus 302 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 302 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 The fact that only one line is used in the diagram does not mean that there is only one bus or only one type of bus.

[0066] The memory 303 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto.

[0067] The memory 303 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 301. The processor 301 is used to execute the application code stored in the memory 303 to implement the contents shown in the above method embodiment.

[0068] The electronic devices include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), and fixed terminals such as digital TVs, desktop computers, etc. It can also be a server, etc. Figure 3 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0069] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding content in the aforementioned method embodiment.

[0070] An embodiment of the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the method in any of the above embodiments is implemented.

[0071] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0072] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. An API penetration testing method based on LLM, characterized in that: include: Identify the test identifier contained in the API to be tested, and determine the corresponding target test case framework based on the test identifier, wherein the target test case framework is based on the test requirements and LLM model of the API to be tested, and the target test case framework includes multiple function nodes and a target test case corresponding to each function node; Performing penetration testing on the API to be tested using the target test case framework; After the penetration tests corresponding to all functional nodes are completed, the vulnerability penetration results corresponding to all vulnerable functional nodes are counted, and the statistical results are fed back. The vulnerable functional nodes are functional nodes with vulnerabilities in the penetration results.

2. According to claim 1, a method for API penetration testing based on LLM is characterized in that: The penetration test of the API to be tested using the target test case framework includes: Obtaining a vulnerability penetration result corresponding to the vulnerability function node and an associated test case corresponding to an associated function node, wherein the vulnerability function node is a function node where a vulnerability exists in the penetration result; Identify vulnerability features contained in the vulnerability penetration result, and identify associated preconditions of the associated test cases corresponding to the associated function nodes, and determine target preconditions based on the vulnerability features and the associated preconditions; Based on the target precondition, an update test case is determined from a preset test case library, and a penetration test is performed on the API to be tested based on the update test case and the target test case framework.

3. The API penetration testing method based on LLM according to claim 2 is characterized in that: The process of determining whether the penetration tests corresponding to all functional nodes have been completed includes: Identify the location node of the current function node in the target test case framework, and record the number of penetrations of the API to be tested in the target test case framework; If the location node is a leaf node, and the number of penetrations is consistent with the number of functional nodes included in the target test case framework, it is determined that the API to be tested has completed the penetration test.

4. The API penetration testing method based on LLM according to claim 1, characterized in that: The process of forming the target test case framework includes: Acquire the test requirements of the API to be tested, identify the requirement identifier corresponding to each test requirement, and functionally divide the test requirements according to each requirement identifier to obtain at least one functional requirement group; Import each functional requirement group into the trained LLM model to obtain the test cases corresponding to each functional requirement group; Determine each functional requirement group as a functional node, and determine the association relationship between each functional node based on the test requirements included in each functional requirement group; The target test case framework is obtained according to the association relationship between each functional node and the test case corresponding to each functional node.

5. The API penetration testing method based on LLM according to claim 2 is characterized in that: The determining of a target precondition based on the vulnerability feature and the associated precondition includes: Identify the combination position corresponding to the vulnerability feature from the associated preconditions, and clear the combination position; Determine, according to the vulnerability feature and a preset mapping relationship, a replacement character corresponding to the vulnerability feature, wherein the preset mapping relationship is a correspondence relationship between the vulnerability feature and the replacement character; The replacement character is written into the cleared combination position to obtain the target precondition.

6. The API penetration testing method based on LLM according to claim 3 is characterized in that: After the penetration test is performed on the API to be tested based on the updated test case and the target test case framework, the method further includes: The updated test case and the original test case are stored in parallel in the target test case framework, and the usage frequency of the updated test case and the original test case within a preset time period is recorded; If the usage frequency of the updated test case within the preset time period is higher than the usage frequency of the original test case within the preset time period, the target test case framework is updated according to the updated test case.

7. The API penetration testing method based on LLM according to claim 1, characterized in that: Also includes: When an access request is detected, a progress display frame is fed back, wherein the formation process of the progress display frame includes: Identify a functional node that is currently in a penetration test phase, and mark it in the target test case framework according to a first mark, so as to indicate that a penetration test is being performed based on the functional node; When it is detected that the penetration test of the functional node is completed, the first mark is replaced with a second mark, indicating that the penetration test based on the functional node has been completed; When it is detected that the functional node is a vulnerable functional node, the simulated repair time of the vulnerable functional node is determined based on the simulated test data, and the first mark is replaced with the third mark to indicate that there is a vulnerability based on the penetration test of the functional node, and the simulated repair time is superimposed on the third mark.

8. An electronic device, characterized in that: The electronic device includes: at least one processor; Memory; At least one application, wherein the at least one application is stored in a memory and configured to be executed by at least one processor, and the at least one application is configured to: execute an LLM-based API penetration testing method as described in any one of claims 1-7.

9. A computer-readable storage medium, characterized in that: include: A computer program is stored which can be loaded by a processor and execute an API penetration testing method based on LLM as described in any one of claims 1-7.

10. A computer program product, characterized in that It includes a computer program, which, when executed by a processor, implements the steps of an LLM-based API penetration testing method described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Test system management method, apparatus and device, and storage medium

    CN110502429A

  • Network interface security scanning method, device and system

    CN112019544A

  • Test case generation method and device as well as test method and device

    CN113641591A

  • Test case generation method and device, storage medium and computer equipment

    CN116974943A

  • Vehicle-mounted application test method and system, electronic equipment and storage medium

    CN117076316A

Cited By

  • Network penetration testing method and system based on state feedback

    CN119520075A