Penetration testing method and device and storage medium
By obtaining the traffic data of the National Secretariat Agreement, calculating the local private key using the elliptic curve parameters and decrypting it, and combining with the stratified reinforcement learning model to generate attack payloads, the problems of low efficiency and high false alarm rate of traditional penetration testing tools under the National Secretariat TLCP protocol are solved, and efficient penetration testing is achieved.
Patent Information
- Application Number
- CN202510667792.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-22
- Publication Date
- 2025-07-18
AI Technical Summary
Traditional penetration testing tools do not support the National Secret TLCP protocol, resulting in low testing efficiency and high false alarm rate, which cannot be effectively applied in key areas such as government and finance.
By obtaining the traffic data of the National Secretariat Agreement, using the elliptic curve parameters to calculate the local private key, generate a shared secret and derive a target key, decrypt the encrypted data of the National Secretariat algorithm, and generate an attack payload after reorganization and analysis, realizing attack testing of the system under test, combining the hierarchical reinforcement learning model to detect vulnerabilities and generate an attack strategy.
No third-party tools are required to support traffic analysis of the National Secretariat Agreement, improve testing efficiency, reduce false alarm rates, and achieve efficient penetration testing in the National Secretariat environment.
Smart Images

Figure CN120342753A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network security, and in particular, to penetration testing methods, devices, and storage media. Background Art
[0002] As an active means of network security assessment, penetration testing plays a crucial role in the network security protection system. It deeply detects the security of the target system by simulating the behavior of malicious attackers, aims to discover potential security vulnerabilities, and then provides key basis for subsequent repair and protection strategy formulation. In today's digital age, network security threats are becoming increasingly complex and diverse, and the importance of penetration testing is becoming more prominent. It has become a key link to ensure the secure and stable operation of various information systems. Currently, national cryptographic transport layer cryptographic protocols (Transport Layer Cryptography Protocol, TLCP for short), such as "GM / T 0024 - 2014 SSL VPN Technical Specification", have been widely used in key fields such as government and finance. The data security and stability in these fields are of utmost importance, involving national secrets, economic lifelines, and the vital interests of the general public.
[0003] However, in the related art, traditional penetration testing tools do not support the national cryptographic TLCP protocol and need to indirectly support it through third-party tools, resulting in problems of low testing efficiency and high false alarm rate. According to the actual measurement data of a certain financial institution, in the national cryptographic environment, manual testing takes 60% more time and the missed alarm rate reaches 25%.
[0004] Currently, there is no effective solution to the problem that traditional penetration testing tools in the related art do not support the national cryptographic TLCP protocol, resulting in low efficiency and high false alarm rate. Summary of the Invention
[0005] Embodiments of this application provide a penetration testing method, device, system, electronic device, and storage medium to at least solve the problem in the related art that traditional penetration testing tools do not support the national cryptographic TLCP protocol and need to indirectly support it through third-party tools, resulting in low testing efficiency and high false alarm rate.
[0006] In a first aspect, embodiments of this application provide a penetration testing method, and the method includes:
[0007] Obtain the encrypted data of the national cryptographic algorithm obtained by encrypting the national cryptographic protocol traffic data, and obtain the public key of the peer end, where the peer end is the system to be tested;
[0008] Calculate the local private key according to the preset elliptic curve parameters, obtain the shared secret based on the local private key and the public key of the peer; perform key derivation processing on the shared secret to generate the target key, and decrypt the data encrypted by the national cryptographic algorithm based on the target key to obtain the decrypted data;
[0009] Perform recombination and parsing processing on the decrypted data to obtain the application layer parsing data;
[0010] Generate an attack payload according to the application layer parsing data, and use the attack payload to perform an attack test on the system under test to obtain a test result.
[0011] In some embodiments, the generating an attack payload according to the application layer parsing data includes:
[0012] Input the application layer parsing data into the trained hierarchical reinforcement learning model, use the hierarchical reinforcement learning model to detect the vulnerability type of the application layer parsing data to obtain the vulnerability type, and perform local policy planning processing according to the vulnerability type to generate the attack payload.
[0013] In some embodiments, the detecting the vulnerability type of the application layer parsing data to obtain the vulnerability type includes:
[0014] Establish a vulnerability knowledge base; the vulnerability knowledge base stores known vulnerability data;
[0015] Detect the vulnerability type of the application layer parsing data to obtain a vulnerability feature vector;
[0016] Traverse the known vulnerability data stored in the vulnerability knowledge base, and retrieve the target vulnerability data that matches the vulnerability feature vector from the vulnerability knowledge base;
[0017] Determine the vulnerability type based on the target vulnerability data.
[0018] In some embodiments, after traversing the known vulnerability data stored in the vulnerability knowledge base, the method further includes:
[0019] If the retrieval of the target vulnerability data that matches the vulnerability feature vector from the vulnerability knowledge base fails, input the vulnerability feature vector into the trained vulnerability classification model, and output the vulnerability type of the vulnerability feature vector;
[0020] Update the vulnerability feature vector and the vulnerability type to the vulnerability knowledge base to obtain a new vulnerability knowledge base.
[0021] In some embodiments, the training process of the hierarchical reinforcement learning model includes:
[0022] Input the obtained training data set into the initial reinforcement learning model. Through the initial global policy network in the initial reinforcement learning model, generate an attack phase based on the training data set. Through the initial local policy network in the hierarchical reinforcement learning model, determine an attack path based on the training data set and the attack phase;
[0023] Use a preset attack path evaluation model to calculate the contribution value of the attack path; calculate the reward value of each attack test based on the contribution value; based on the reward value, optimize the initial global policy network and the initial local policy network, and generate the hierarchical reinforcement learning model.
[0024] In some embodiments, the generating an attack payload according to the application layer parsing data includes:
[0025] Based on the application layer parsing data and the obtained preset system configuration, perform compliance verification on the system under test to obtain a compliance verification result;
[0026] Generate an attack payload according to the application layer parsing data and the compliance verification result.
[0027] In some embodiments, the performing compliance verification on the system under test based on the application layer parsing data and the obtained preset system configuration to obtain a compliance verification result includes:
[0028] Based on the application layer parsing data, calculate a key update period, and compare the key update period with a preset period threshold to obtain a compliance verification result of the key update period;
[0029] Calculate a certificate hash value based on the application layer parsing data, map the certificate hash value to a bit array based on multiple hash functions, and determine the index positions in the bit array corresponding to the multiple hash functions; based on the detection results of the index positions, judge the certificate revocation status to obtain a compliance verification result of the certificate.
[0030] In some embodiments, the performing key derivation processing on the shared secret to generate a target key includes:
[0031] Based on the shared secret, calculate a hash value using a hash algorithm; according to the hash value, perform key derivation processing on the shared secret and generate the target key.
[0032] In a second aspect, an embodiment of the present application provides a penetration testing device, and the device includes:
[0033] A traffic capture module acquires the encrypted data of the national cryptography algorithm obtained by encrypting the traffic data of the national cryptography protocol, and acquires the public key of the peer end, where the peer end is the system under test;
[0034] A decryption module calculates the local private key according to the preset elliptic curve parameters, and obtains a shared secret based on the local private key and the public key of the peer end; performs key derivation processing on the shared secret to generate a target key, and decrypts the encrypted data of the national cryptography algorithm based on the target key to obtain decrypted data;
[0035] A recombination and parsing module performs recombination and parsing processing on the decrypted data to obtain application layer parsing data;
[0036] An intelligent attack module generates an attack payload according to the application layer parsing data, and uses the attack payload to perform an attack test on the system under test to obtain a test result.
[0037] In a third aspect, an embodiment of the present application provides a storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the penetration testing method as described in the first aspect above.
[0038] Compared with the related art, the penetration testing method, device and storage medium provided by the embodiments of the present application obtain the encrypted data of the national cryptography algorithm obtained by encrypting the traffic data of the national cryptography protocol, and acquire the public key of the peer end, where the peer end is the system under test; calculate the local private key according to the preset elliptic curve parameters, and obtain a shared secret based on the local private key and the public key of the peer end; perform key derivation processing on the shared secret to generate a target key, and decrypt the encrypted data of the national cryptography algorithm based on the target key to obtain decrypted data; perform recombination and parsing processing on the decrypted data to obtain application layer parsing data; generate an attack payload according to the application layer parsing data, and use the attack payload to perform an attack test on the system under test to obtain a test result. Based on this, it is possible to support the parsing of the traffic of the national cryptography protocol without a third-party tool, and an attack payload can be generated through the application layer parsing data to attack the system under test, effectively solving the problems of low test efficiency and high false alarm rate.
[0039] Details of one or more embodiments of the present application are set forth in the following drawings and description, so that other features, objects, and advantages of the present application will become more clearly understood. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The drawings described herein are used to provide a further understanding of the present application, and constitute a part of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application, and do not constitute an improper limitation of the present application. In the drawings:
[0041] Figure 1It is a hardware structure block diagram of a terminal for a penetration testing method according to an embodiment of the present application;
[0042] Figure 2 It is a flowchart of a penetration testing method according to an embodiment of the present application;
[0043] Figure 3 It is an architecture diagram of a hierarchical reinforcement learning model according to an embodiment of the present application;
[0044] Figure 4 It is a structure block diagram of a penetration testing device according to an embodiment of the present application;
[0045] Figure 5 It is a flowchart for executing a penetration test according to an embodiment of the present application;
[0046] Figure 6 It is an architecture diagram of a penetration testing system according to an embodiment of the present application. Detailed implementation manners
[0047] In order to make the objectives, technical solutions and advantages of the present application clearer and more understandable, the present application will be described and explained below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments provided in the present application without making creative efforts belong to the scope of protection of the present application. In addition, it can also be understood that although the efforts made in this development process may be complex and lengthy, for those of ordinary skill in the art related to the content disclosed in the present application, some design, manufacturing or production changes made on the basis of the technical content disclosed in the present application are only conventional technical means and should not be understood as insufficient disclosure of the content of the present application.
[0048] Referring to "embodiment" in the present application means that specific features, structures or characteristics described in connection with the embodiment can be included in at least one embodiment of the present application. The phrase appears at various positions in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those of ordinary skill in the art explicitly and implicitly understand that the embodiments described in the present application can be combined with other embodiments without conflict.
[0049] Unless otherwise defined, technical terms or scientific terms involved in this application shall have the ordinary meanings understood by those with ordinary skills in the technical field to which this application belongs. The words such as "a", "an", "one", "the" and the like involved in this application do not indicate a limitation in quantity and may represent a singular or plural number. The terms "comprising", "including", "having" and any variations thereof involved in this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or units, but may further include unlisted steps or units, or may further include other steps or units inherent to these processes, methods, products or devices. The words such as "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "plurality" involved in this application means greater than or equal to two. "And / or" describes the association relationship of associated objects and indicates that three relationships may exist. For example, "A and / or B" may represent three situations: A exists alone, A and B exist simultaneously, and B exists alone. The terms "first", "second", "third" and the like involved in this application are only used to distinguish similar objects and do not represent a specific order of the objects.
[0050] The method embodiment provided in this embodiment can be executed on a terminal, a computer or a similar computing device. Taking running on a terminal as an example, Figure 1 is a hardware structure block diagram of a terminal of a penetration testing method according to an embodiment of this application. As Figure 1 shown, the terminal may include one or more ( Figure 1 only one is shown in the figure) processors 102 (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a field programmable gate array FPGA) and a memory 104 for storing data. Optionally, the above terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those of ordinary skill in the art can understand that Figure 1 the structure shown is only schematic and does not limit the structure of the above terminal. For example, the terminal may further include more or fewer components than those shown in Figure 1 the figure, or have a different configuration from that shown in Figure 1 the figure.
[0051] The memory 104 can be used to store computer programs, such as software programs and modules of application software, for example, the computer program corresponding to the penetration testing method in the embodiments of the present application. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, that is, implements the above-mentioned method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some instances, the memory 104 may further include a memory remotely disposed relative to the processor 102, and these remote memories can be connected to the terminal through a network. Examples of the above network include but are not limited to the Internet, intranet, local area network, mobile communication network, and combinations thereof.
[0052] The transmission device 106 is used to receive or send data via a network. Specific examples of the above network may include a wireless network provided by a communication provider of the terminal. In one instance, the transmission device 106 includes a network adapter (abbreviated as NIC), which can be connected to other network devices through a base station and thus communicate with the Internet. In one instance, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0053] This embodiment provides a penetration testing method. Figure 2 It is a flowchart of a penetration testing method according to an embodiment of the present application, as Figure 2 shown, and the process includes the following steps:
[0054] Step S201: Obtain the data encrypted by the national secret algorithm for the national secret protocol traffic data, and obtain the public key of the peer end, where the peer end is the system to be tested;
[0055] Among them, the obtained national secret traffic data refers to the TLCP protocol data encrypted based on the national secret algorithm SM4 block encryption algorithm. The SM4 algorithm is a commercial cipher algorithm standard issued by the State Cryptography Administration of China. It is a block symmetric encryption algorithm with high security and efficiency, and is widely used in the field of information security. The SM4 block encryption algorithm is encrypted based on a round function. Each round of iteration of the round function includes a round key addition operation and an S-box lookup operation, and encrypts the data through exclusive OR and non-linear transformation. The plaintext data is first XORed with the initial vector, and then enters the round function for 32 rounds of iteration, and finally the ciphertext is output. These ciphertext data will be encapsulated in the data packets of the TLCP protocol for transmission. The specific calculation formula of the round function is as follows:
[0056]
[0057] In the above formula, T is a complex non-linear transformation function, including S-box substitution and permutation operations. Xi represents the input data block in the i-th round of the encryption process, and X i+1 represents the output result after the i-th round of operation, that is, the data block obtained after being processed by the round function F, which will be used as the input for the encryption operation in the next round (the (i + 1)-th round). As the number of encryption rounds increases, the data is continuously transformed, and finally the ciphertext is obtained. X i-1 , X i-2 and X i-3 respectively represent the input data blocks in the (i - 1)-th, (i - 2)-th, and (i - 3)-th rounds before the i-th round. In the operation of the round function, the input data of several rounds before the current round will be XORed. The purpose is to make the encryption process fully utilize the operation results of the previous rounds, increase the confusion degree of the data, and thus improve the security of the encryption. rki represents the round key in the i-th round. In the SM4 algorithm, a series of round keys are generated from the initial key through the key expansion algorithm, and each round of encryption operation uses a different round key. The role of the round key is to participate in each round of encryption operation and mix with the data block, so that the same plaintext will generate different ciphertexts after being affected by different round keys in different rounds, further enhancing the complexity and security of the encryption. It can be seen that the round function enhances the security of the data through multi-round iterative confusion and diffusion transformations, ensuring that the key information is fully mixed with the data to resist various cryptographic analysis attacks.
[0058] Among them, the peer public key is generated by the peer system under test.
[0059] Step S202, calculate the local private key according to the preset elliptic curve parameters, obtain the shared secret based on the local private key and the peer public key; perform key derivation processing on the shared secret to generate the target key, and decrypt the data encrypted by the national cryptography algorithm based on the target key to obtain the decrypted data;
[0060] First, calculate the local private key according to the preset elliptic curve parameters. The formula of the elliptic curve equation is as follows:
[0061] In the above formula, a and b are the coefficients of the curve equation, p is a prime number representing the modulus of the finite field, and mod p means that all calculations are carried out modulo p. The above parameters are defined in the cryptographic standard.
[0062] In the key generation process, from this set elliptic curve equation, the curve order n is calculated using relevant mathematical methods, and then an integer value is randomly sampled in the interval [1, n - 1] as the private key d.
[0063] After that, the public key P = d·G is calculated based on the private key d and a predefined base point G on the elliptic curve. This process ensures that even if the public key P is public, it is very difficult to derive d from P without the private key d, which is the basis for the security of elliptic curve cryptography. Both this paragraph and the peer will generate their respective private key / public key pairs (d 本段 , P 本端 and d 对段 , P 对端 ) based on the elliptic curve defined by the above elliptic curve equation.
[0064] The shared secret is obtained based on the private key of this paragraph and the public key of the peer, Z = d 本段 ·P 对端 . Mathematically, it is necessary to ensure that:
[0065] d 本段 ·P 对端 = d 对段 ·P 本端
[0066] After obtaining the shared secret, the target key K is derived from the shared secret Z through KDF. The specific formula is as follows:
[0067] K = KDF(Z, klen) = HMAC_SM3(Z||salt||counter, 0x01, klen)
[0068] Where Z is the shared secret; klen is the length of the required derived key; salt is the salt value used to increase randomness and prevent the same input from producing the same output; counter is the counter used to change during the iteration to generate multiple keys; 0x01: a constant used as the initialization vector for HMAC. First, the shared secret Z, the salt value salt, and the counter counter are concatenated to form an input string; then, the concatenated string is hashed using the HMAC-SM3 algorithm; finally, the first klen bits are intercepted from the output of HMAC-SM3 as the derived key K, that is, the target key K.
[0069] After that, the round key rki' is derived from the target key K, and the national cipher algorithm encrypted data obtained in step S201 is decrypted using the decryption round function to obtain the decrypted data. The decryption process of the round function is similar to the encryption process, but the order of the round keys used is reversed. The specific formula is as follows:
[0070]
[0071] The specific Python code implementation framework is as follows:
[0072] def sm2_key_exchange_decrypt(packet):
[0073] # Parse elliptic curve parameters
[0074] curve = get_sm2_curve(packet)
[0075] # Extract encrypted data
[0076] shared_data = parse_shared_data(packet)
[0077] # Generate shared secret
[0078] shared_secret=sm2_derive_shared_secret(local_private_key, peer_public_key)
[0079] # Generate SM4 key
[0080] sm4_key = kdf(shared_secret, curve_n_bit_length())
[0081] # Call C function for decryption
[0082] lib = ctypes.CDLL("sm4.so")
[0083] lib.sm4_decrypt.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
[0084] lib.sm4_decrypt.restype = ctypes.c_char_p
[0085] decrypted_data = lib.sm4_decrypt(sm4_key, shared_data)
[0086] return decrypted_data
[0087] # Example call
[0088] packet = "example_packet"
[0089] decrypted_data = sm2_key_exchange_decrypt(packet)
[0090] print(decrypted_data)
[0091] The specific C language code implementation framework is as follows:
[0092] #include <stdio.h>
[0093] #include <string.h>
[0094] / / Assume the implementation of the SM4 decryption function is here
[0095] void sm4_decrypt(const unsigned char *key, const unsigned char *data,unsigned char *output)
[0096] / / Implement the SM4 decryption logic
[0097] }
[0098] extern "C" {
[0099] / / Define an interface function for Python to call
[0100] char* sm4_decrypt(char* key, char* data) {
[0101] unsigned char output
[16] ; / / Assume the output length is 16 bytes
[0102] sm4_decrypt((const unsigned char*)key, (const unsigned char*)data, output);
[0103] return strdup((char*)output); / / Return a string
[0104] }
[0105] }
[0106] Step S203, perform recombination and parsing processing on the decrypted data to obtain the application layer parsing data;
[0107] The decrypted TLCP traffic can be recombined and parsed into various application layer protocol data. For example:
[0108] (1) HTTP protocol: Parse the URL, request method (GET / POST), header fields (such as Cookie, User-Agent), and request body (such as JSON / form data).
[0109] (2) Cryptography certificate data of the country: Parse the public key, certificate validity period, and issuer information in the SM2 certificate (compliant with the GM / T0034-2014 standard).
[0110] (3) Key negotiation log: Extract the elliptic curve parameters (such as curve equation coefficients (a, b), base point G), random number in the negotiation data, and session key fragment during the SM2 key exchange process.
[0111] (4) Business instructions: Such as payment instructions in financial transactions, file transfer instructions in government affairs systems, etc. Identify potential vulnerabilities (such as insufficient instruction permissions, parameter tampering) by parsing the plaintext content.
[0112] Step S204, generate an attack payload based on the application layer parsed data, and use the attack payload to perform an attack test on the system under test to obtain a test result.
[0113] Through the above steps, this application constructs a complete national cryptography protocol parsing system based on the mathematical characteristics of national cryptography algorithms. This system enables this solution to be independent of third-party tools. Compared with the traditional testing method that requires the use of third-party tools for encryption and decryption of national cryptography data, this application realizes the full-process automated parsing of SM2 key negotiation and SM4 traffic decryption, breaks through the parsing limitations of traditional tools for national cryptography protocols, and realizes the real-time decryption and recombination of encrypted traffic (with a speed of 200 Mbps), improving the efficiency and accuracy of testing.
[0114] In some of these embodiments, the above-mentioned generating an attack payload based on the application layer parsed data further includes the following steps:
[0115] Input the application layer parsed data into the trained hierarchical reinforcement learning model, use the hierarchical reinforcement learning model to detect the vulnerability type of the application layer parsed data to obtain the vulnerability type, and perform local policy planning processing according to the vulnerability type to generate an attack payload.
[0116] Specifically, after obtaining the application layer parsing data, these data are input into a well-trained hierarchical reinforcement learning model. The model continuously learns and optimizes the attack strategy by simulating the behavior of attackers. The model first analyzes the application layer parsing data to detect potential security vulnerability types. These vulnerabilities cover common network security threats such as SQL injection, cross-site scripting (XSS), command injection, buffer overflow, etc. The model uses deep learning techniques to carefully identify abnormal patterns and structures in the data, and then accurately determines the existence and type of vulnerabilities. Once the vulnerability type is determined, the hierarchical reinforcement learning model will carry out local policy planning. This step will formulate detailed attack steps and strategies based on the specific detected vulnerability type. Based on the results of the local policy planning, the model will generate specific attack payloads. The attack payload is the specific code or command used to implement the attack, and its design purpose is to make full use of the detected vulnerabilities. In the process of generating the attack payload, the model will consider various factors to maximize the success rate of the attack.
[0117] The model can accurately identify abnormal patterns and structures in the application layer data through deep learning techniques, quickly and accurately detect potential vulnerability types; the local policy planning based on the vulnerability type can formulate highly adaptable attack steps and strategies according to the characteristics of different vulnerabilities; when generating the attack payload, various factors such as the target system protection mechanism and network environment are comprehensively considered to maximize the success rate of the attack, and the model can continuously optimize the strategy by continuously simulating the behavior of attackers, providing comprehensive, efficient and accurate detection and attack simulation capabilities for network security assessment, and helping to discover and repair system security hidden dangers in advance.
[0118] In some of these embodiments, the above-mentioned detection of the vulnerability type from the application layer parsing data to obtain the vulnerability type further includes the following steps:
[0119] Establish a vulnerability knowledge base; the vulnerability knowledge base stores known vulnerability data; detect the vulnerability type of the application layer parsing data to obtain a vulnerability feature vector; traverse the known vulnerability data stored in the vulnerability knowledge base, and retrieve target vulnerability data that matches the vulnerability feature vector from the vulnerability knowledge base; based on the target vulnerability data, determine the vulnerability type.
[0120] Specifically, a vulnerability knowledge base is established, which is specifically used to store rich and detailed known vulnerability data. These data cover various potential security vulnerability information in the national cryptography environment, such as SM2 key reuse vulnerability, SM4-CBC mode IV prediction, etc. Detect the vulnerability type of the application layer parsed data, and then obtain the vulnerability feature vector, and extract the key features related to security vulnerabilities among them. These features are processed and quantified by specific algorithms, and finally converted into a vulnerability feature vector. This vector precisely describes the possible vulnerability features in the application layer parsed data in a mathematical form. After obtaining the vulnerability feature vector, the system will automatically start the retrieval program and compare each piece of known vulnerability data in the knowledge base in turn. The similarity between the vulnerability feature vector and the known vulnerability data is evaluated through precise calculations. When the similarity reaches the preset threshold, it is determined that the target vulnerability data that matches it has been found. For example, when comparing the SM2 key reuse vulnerability, elements related to the key in the vulnerability feature vector will be focused on, such as the usage frequency of the key, whether there are duplicate key values, etc., and a detailed comparison will be made with the standard features of the SM2 key reuse vulnerability in the knowledge base. Once the target vulnerability data is retrieved, the system will accurately judge the vulnerability type according to the pre-set rules and classification system.
[0121] In summary, through a series of steps such as establishing a vulnerability knowledge base, obtaining a vulnerability feature vector, retrieving and matching target vulnerability data, and determining the vulnerability type, an efficient and accurate vulnerability detection system can be constructed, greatly improving the ability to discover and handle network application security vulnerabilities, and providing a solid guarantee for the safe and stable operation of network applications.
[0122] In some of these embodiments, after traversing the known vulnerability data stored in the vulnerability knowledge base, the following steps are further included:
[0123] In the case where the retrieval of the target vulnerability data that matches the vulnerability feature vector fails from the vulnerability knowledge base, input the vulnerability feature vector into the trained vulnerability classification model, and output the vulnerability type of the vulnerability feature vector; update the vulnerability feature vector and the vulnerability type to the vulnerability knowledge base to obtain a new vulnerability knowledge base.
[0124] Specifically, when retrieving target vulnerability data that matches the vulnerability feature vector from the vulnerability knowledge base, retrieval failures may occur. This may be because there are new security vulnerabilities in the application layer parsed data that have not been included in the existing vulnerability knowledge base, or the combination of features represented by the vulnerability feature vector is extremely special and no matching items can be found in the existing known vulnerability data. When encountering such a retrieval failure situation, in order to accurately determine the vulnerability type, further measures will be taken, that is, inputting the vulnerability feature vector into a vulnerability classification model trained with a large amount of data. This trained vulnerability classification model is constructed by means of technologies such as deep learning and machine learning. It has learned the feature patterns of many different types of vulnerabilities and has the ability to classify unknown vulnerabilities. By analyzing and processing the vulnerability feature vector, the model will output the corresponding vulnerability type. Once the vulnerability type of the vulnerability feature vector is determined, the vulnerability knowledge base needs to be updated in a timely manner to improve its integrity and practicality. Add the vulnerability feature vector and the determined vulnerability type to the original vulnerability knowledge base, expand and update the knowledge base, so as to obtain a new vulnerability knowledge base. The new vulnerability knowledge base not only contains the previous known vulnerability data, but also incorporates this newly discovered vulnerability information, enabling more comprehensive identification of various potential security threats during subsequent vulnerability detection.
[0125] Such an update mechanism helps the system continuously learn and adapt to newly emerging security vulnerabilities, and continuously enhance the detection and prevention capabilities of network application security vulnerabilities.
[0126] In some of the embodiments, the training process of the hierarchical reinforcement learning model further includes the following steps:
[0127] Input the obtained training data set into the initial reinforcement learning model. Via the initial global policy network in the initial reinforcement learning model, generate an attack phase based on the training data set. Via the initial local policy network in the hierarchical reinforcement learning model, determine an attack path based on the training data set and the attack phase; use a preset attack path evaluation model to calculate the contribution value of the attack path; calculate the reward value of each attack test based on the contribution value; based on the reward value, optimize the initial global policy network and the initial local policy network, and generate the hierarchical reinforcement learning model.
[0128] Specifically, in the initial training stage of the reinforcement learning model, the obtained training data set needs to be input into the initial reinforcement learning model. These training data sets cover rich information, including network traffic data, system configuration information, vulnerability characteristics, and attack history records under various national cryptography protocol environments, which can truly reflect the complexity and diversity of the national cryptography TLCP protocol environment. After input, the initial global policy network in the initial reinforcement learning model will play a key role. Based on the training data set, it uses its own algorithms and logic to comprehensively analyze the target environment and then generate the attack phase. In this process, the initial global policy network will comprehensively consider the open port information, service type, national cryptography certificate-related data, and existing vulnerability information in the training data set. For example, if the training data shows that a specific port is open on the target system and a service with a known vulnerability is running, the initial global policy network may determine the attack phase as giving priority to vulnerability exploitation in order to quickly discover and utilize system vulnerabilities. Then, the initial local policy network in the hierarchical reinforcement learning model will determine the specific attack path based on the training data set and the attack phase generated by the global policy network. It will deeply explore the detailed information related to specific vulnerabilities in the training data set and, combined with the requirements of the attack phase, generate targeted attack strategies for each vulnerability. For example, for the SM2 key reuse vulnerability, the initial local policy network will determine specific attack parameters, such as the validity period of the forged certificate and the key usage, based on the exploitation methods, successful cases, and relevant environmental factors of this vulnerability in the training data set, thus forming a specific attack path. At this time, using the preset attack path evaluation model, the contribution degree value of the attack path can be calculated. This model adopts a calculation method based on the Shapley value and will comprehensively consider factors such as all possible combinations of attack phases and the threat values of historical attack paths. Taking a certain attack path as an example, the attack path evaluation model will analyze the contribution degree of this path to the overall attack success at different stages. If a certain attack path successfully exploits the SM2 key reuse vulnerability and elevates the system privilege, the attack path evaluation model will calculate the contribution degree value of this path according to the importance of this achievement in the entire attack process. Based on the contribution degree value, the reward value of each attack test can be calculated. This system adopts a hierarchical reward mechanism, and the reward value consists of a global reward and a local reward. The global reward is determined based on the completion degree of the attack phase of the global policy network. For example, successfully advancing from the reconnaissance phase to the vulnerability exploitation phase can obtain a certain global reward; the local reward is calculated according to the attack effect of the local policy network. For example, successfully exploiting a vulnerability to obtain sensitive data or elevate the system privilege can get the corresponding local reward. By adding the global reward and the local reward according to a certain weight, the total reward value of each attack test is obtained. Finally, based on the reward value, the system will optimize the parameters of the global policy network and the local policy network. The system will judge the performance of the current policy network according to the feedback of the reward value.If the reward value is high, it indicates that the parameter settings of the current policy network are relatively reasonable, and the system will appropriately strengthen these parameters; if the reward value is low, the system will adjust the parameters of the policy network, try different combinations to improve the attack effect. After multiple iterations of optimization, a hierarchical reinforcement learning model with better performance is finally generated.
[0129] Through the above embodiments, the hierarchical reinforcement learning model uses the global policy network to scientifically plan the attack stage, uses the local policy network to accurately generate attack parameters for specific vulnerabilities, combines the national cryptographic vulnerability knowledge base, improves the threat recognition accuracy, and effectively responds to new attack surfaces such as key generation vulnerabilities. Through the collaborative work of the attack path evaluation model and the reward function, the attack strategy is optimized, and the penetration testing cycle is significantly shortened. In addition, the model has a high degree of automation, reduces manual intervention, reduces the false alarm rate, and can continuously evolve in continuous learning, effectively ensuring the security of the network system in the national cryptographic environment.
[0130] The following will be described in detail with specific embodiments. Figure 3 is the architecture diagram of the hierarchical reinforcement learning model, as Figure 3 shown, this model includes the following modules:
[0131] The global policy network module 31 selects the attack stage (reconnaissance → vulnerability exploitation → privilege maintenance) according to the target environment information (such as open ports, service types).
[0132] The input of the global policy module is the state information of the target environment, including: open ports and service types (such as HTTP, SSH, database services, etc.); decrypted traffic characteristics output by the protocol parsing layer (such as SM2 key negotiation parameters, application layer data after SM4 decryption); system configuration information (such as national cryptographic certificate type, key update period).
[0133] The output of the global policy module includes: the selection of the macro attack stage, for example: the attack stage sequence (such as "reconnaissance → vulnerability exploitation → privilege maintenance"); priority sorting (such as choosing to exploit the SM2 key reuse vulnerability or the SM4-CBC IV prediction vulnerability first).
[0134] The stage decision module 32 generates specific action instructions and resource allocation strategies based on multiple aspects of information such as the output of the global policy network, the real-time environment state, and the compliance verification result.
[0135] The input of the stage decision module includes: the output of the global policy network (such as the selection of the current attack stage); the real-time environment state (such as the response of the target host, the vulnerability exploitation success rate); the compliance verification result (such as whether the key update period conforms to GM / T 0024-2014).
[0136] The output of the phase decision module includes: specific action instructions, such as: the next attack step (e.g., "Execute MITM attack" or "Generate forged certificate"); resource allocation strategy (e.g., execute multiple vulnerability exploitation tasks in parallel).
[0137] The vulnerability type selection module 33 generates a vulnerability feature vector according to the application layer parsing data and the national cryptography vulnerability knowledge base.
[0138] The input of the vulnerability type selection module includes: decrypted application layer data (from the SM4 traffic decryption module); national cryptography protocol features extracted by the protocol parsing layer (such as abnormal SM2 key negotiation parameters, repeated SM4 IV values); national cryptography vulnerability knowledge base (such as predefined SM2 key reuse patterns, SM4-CBC IV prediction attack features).
[0139] The output of the vulnerability type selection module includes: a vulnerability feature vector representing the potential vulnerability type and its probability.
[0140] Input the above vulnerability feature vector into the Transformer encoder structure formula to generate an enhanced feature vector to judge the potential vulnerability type and its probability. The Transformer encoder structure formula is as follows:
[0141]
[0142] In the above formula, V is the vulnerability feature vector, which comes from the decrypted traffic features of the vulnerability type selection module (such as SM2 public key parameters, SM4 ciphertext blocks), and We is the embedding matrix obtained through the pre-trained national cryptography vulnerability feature library. The step of V·We multiplies the vulnerability feature vector V by the embedding matrix We to achieve the embedding transformation of the features, and then performs the PositionalEncoding (positional encoding) operation. The result obtained after this step is X, which is the feature representation after positional encoding processing. MultiHeadAttention(X,X,X): The multi-head attention mechanism is one of the core components of the Transformer. Here, three Xs are input, corresponding to the query (Query), key (Key), and value (Value) respectively. The multi-head attention mechanism calculates the attention in parallel through multiple different "heads" (linear transformation matrices), and then splices and linearly transforms the results, enabling the model to learn different information in different representation subspaces and capture richer relationships in the input features. For example, when analyzing national cryptography vulnerability features, it can focus on the associations between features from different perspectives. X+MultiHeadAttention(X,X,X): This is the residual connection operation. It adds the original input X to the result after being processed by the multi-head attention mechanism. The residual connection helps to solve problems such as gradient disappearance in the training of deep neural networks, making it easier for the model to learn and optimize, and making the flow of information smoother. LayerNorm(X+MultiHeadAttention(X,X,X)): The layer normalization operation normalizes the result after the residual connection. Layer normalization is performed on the hidden layer dimension of a single sample, which can accelerate the model convergence speed and help improve the model stability. The result obtained after this step is Encoder, that is, the enhanced feature vector after being processed by the Transformer encoder structure, and the potential vulnerability types and their probabilities can be judged based on this subsequently.
[0143] The local policy network module 34 generates specific attack parameters for a specific vulnerability according to the feature vector output by the vulnerability type selection module.
[0144] The input of the local policy network module includes: the feature vector output by the vulnerability type selection (such as the features of the SM2 key reuse vulnerability).
[0145] The output of the local policy network module is the specific attack parameters, including: the validity period of the forged certificate, the key usage field; the predicted value of the SM4-CBC mode IV; the construction parameters of the attack payload (such as SQL injection statements, malformed request packets).
[0146] The payload generation module 35 generates an executable attack payload according to the attack parameters generated by the local policy network.
[0147] The input of the payload generation module includes: the attack parameters generated by the local policy network.
[0148] The output of the payload generation module includes: executable attack payloads.
[0149] The payload generation module combines attack primitives and converts the received attack parameters into actual executable attack payloads. Common forms include Python scripts, PowerShell commands, etc. These attack payloads can directly act on the system under test, attempt to exploit the discovered vulnerabilities, and achieve penetration testing purposes such as obtaining sensitive information and escalating privileges.
[0150] After the attack is completed, according to the attack results, the contribution degree is calculated based on the preset attack path evaluation model to quantify the contribution of each stage to the overall attack success and optimize the selection of local policies. The formula for calculating the contribution degree of each stage (denoted by i) in the attack path to the overall attack success in the attack path evaluation model is as follows:
[0151]
[0152] In the above formula, v(S) is the threat value based on the historical attack path (such as the success probability of a certain path, the level of privilege escalation caused). N is all possible combinations of attack stages (such as reconnaissance, vulnerability exploitation, privilege maintenance, etc.).
[0153] After that, the parameters of the reinforcement learning reward function are adjusted using the contribution degree value. The formula for the reinforcement learning reward function is as follows:
[0154] R = αR g + βR l
[0155] Where R g is the global reward, that is, the completion degree of the attack stage of the global policy network (such as reconnaissance → vulnerability exploitation: +50). R l is the local reward, that is, the specific attack effect of the local policy network (such as successfully obtaining privileges: +100). α is the weight of the global reward, and β is the weight of the local reward.
[0156] The global reward is adjusted using the contribution degree value to calculate the contribution degree of each attack stage (such as reconnaissance, vulnerability scanning, vulnerability exploitation, etc.) to the overall attack success. For example, if it is calculated that the contribution degree value of the reconnaissance stage is relatively high, it means that it makes a great contribution to the attack success. Then when calculating R gWhen the reconnaissance phase is successfully completed, a higher reward weight is given, so that the rewards obtained when this phase is completed account for a larger proportion in the global rewards. At the same time, according to the contribution degrees of each attack phase, the parameters of the global policy network are dynamically adjusted. For the phase with a high contribution degree, a greater influence is given in the calculation of the global rewards, prompting the global policy network to preferentially select and optimize the key attack phases, plan a more reasonable attack phase sequence, and improve the overall attack efficiency.
[0157] Adjust the local rewards using the contribution degree value. The local reward R l Based on the attack effect of the local policy network. The contribution degree value can calculate the contributions of different vulnerability exploitation methods (such as vulnerability exploitation for SM2 key reuse, SM4-CBC mode IV prediction attack, etc.) to the attack success. If the contribution degree value for the vulnerability exploitation of SM2 key reuse is high, when this vulnerability is successfully exploited, when calculating R l A higher reward coefficient is given to make the local rewards more generous, guiding the model to adopt such efficient vulnerability exploitation methods more. At the same time, according to the contribution degree reflected by the contribution degree value, the parameters of the local policy network are optimized. The local policy corresponding to the vulnerability exploitation method with a large contribution receives more attention and resources during training, and the network parameters are adjusted to better generate attack parameters for such vulnerabilities, enhancing the local attack accuracy and success rate.
[0158] In some of the embodiments, the above-mentioned generating an attack payload according to the application layer parsing data further includes the following steps:
[0159] Based on the application layer parsing data and the obtained preset system configuration, perform compliance verification on the system under test to obtain a compliance verification result;
[0160] Generate an attack payload according to the application layer parsing data and the compliance verification result.
[0161] Specifically, the system will also determine the next attack step based on the results of compliance verification. If the key update period is too long, it means that the same key is used for a long time, and there is a risk of the key being cracked. The system may generate an attack payload specifically targeting key cracking, attempting to exploit the vulnerability of the long-unupdated key to obtain encrypted data or elevate system privileges. The system will combine relevant information such as encryption algorithms and key usage frequencies in the application layer parsed data to optimize the design of the attack payload, making it more targeted and effective. If problems are found with the certificate, such as an abnormal certificate revocation status or a certificate format not conforming to the GM / T 0034 - 2014 standard, the system will generate corresponding attack payloads based on these problems. For example, in the case of an abnormal certificate revocation status, an attack payload may be generated to simulate a legitimate user accessing with a revoked certificate to test the system's ability to identify and prevent abnormal certificates; for the problem of a certificate format not conforming to the standard, an attack payload containing an incorrect certificate format will be constructed to check whether there are vulnerabilities in the system when processing such abnormal certificates and whether security problems will occur due to incorrect certificate parsing.
[0162] In this way, when generating the attack payload, the system fully combines the application layer parsed data and the results of compliance verification, not only improving the targeting of the attack payload, but also being able to more comprehensively detect the security of the system under test, discover potential security vulnerabilities, and provide strong support for subsequent security protection and repair work.
[0163] In some of these embodiments, the above-mentioned compliance verification of the system under test based on the application layer parsed data and the obtained preset system configuration to obtain the compliance verification results further includes the following steps:
[0164] Based on the application layer parsed data, calculate the key update period, and compare the key update period with a preset period threshold to obtain the compliance verification result of the key update period;
[0165] Calculate the certificate hash value based on the application layer parsed data, map the certificate hash value to a bit array based on multiple hash functions, and determine the index positions in the bit array corresponding to the multiple hash functions; based on the detection results of the index positions, judge the certificate revocation status to obtain the compliance verification result of the certificate.
[0166] Specifically, based on the application layer parsed data, first calculate the key update period. This also involves analyzing relevant data sources such as system logs and key management records. The preset period threshold is a dynamic threshold based on time series analysis and is used to judge whether the key update period is compliant. This threshold is not static but is dynamically calculated based on historical data. The specific formula is as follows:
[0167] Threshold = μ + 3σ
[0168] In the above formula, μ represents the historical average update period, which is the average of the key update periods of all past records; σ represents the standard deviation, which measures the volatility or dispersion of the update period; Threshold represents the preset period threshold. Once the key update period and the period threshold are calculated, the system will compare the two. Through this comparison, the system can evaluate the compliance of the key update period and generate corresponding verification results. These results can be used to adjust the key management strategy to ensure that the key update period meets both security requirements and operational feasibility.
[0169] By this method, security risks are reduced and the efficiency of key management is improved. The advantage of this method is that it is based on actual data and dynamic analysis, rather than relying on static rules or empirical values, thus providing a more accurate and adaptable compliance verification.
[0170] After that, based on the data parsed at the application layer, the certificate hash value is calculated, and the certificate revocation status is judged using the following formula.
[0171] h i =SM3(cert_hash⊕salt i )mod m(i = 1..k)
[0172] In the above formula, h i represents the result calculated by the i-th hash function; cert_hash is the hash value of the certificate, which is obtained by performing a hash operation on the certificate content; salt i is the i-th salt value, which is used for exclusive OR operation with the certificate hash value to increase the randomness of the hash function; m is the size of the Bloom filter, that is, the length of the bit array; k is the number of hash functions, which determines the false positive rate and the storage space occupancy of the Bloom filter.
[0173] Specifically, for each hash function i (from 1 to k), calculate h i , and take the modulus of the result by m to obtain an index value. This index value points to the position in the Bloom filter bit array. For each calculated hash value h i , check the position in the Bloom filter bit array with the index h i . If all these positions are 1, then the certificate may be revoked. If any one position is 0, then the certificate is not revoked.
[0174] Using the Bloom filter can quickly judge whether a certificate may be revoked, improving the judgment efficiency. Moreover, using a bit array to store the hash results also saves storage space.
[0175] In some embodiments, the key derivation process for the shared secret to generate the target key further includes the following steps:
[0176] Based on the shared secret, a hash value is calculated using a hash algorithm; according to the hash value, a key derivation process is performed on the shared secret to generate a target key.
[0177] Specifically, the following formula is used to implement the process of deriving the target key K from the shared secret Z:
[0178] K=KDF(Z,klen)=HMAC_SM3(Z||salt||counter,0x01,klen)
[0179] In the above formula, Z is the shared secret; klen is the length of the required derived key; salt is the salt value, which is used to increase randomness and prevent the same input from producing the same output; counter is a counter, which is used to change during the iteration process to generate multiple keys; 0x01: a constant used for the initialization vector of HMAC. First, the shared secret Z, the salt value salt and the counter counter are concatenated to form an input string; then, the concatenated string is hashed using the HMAC-SM3 algorithm to obtain a hash value; finally, the first klen bits are intercepted from the hash value as the derived key K, that is, the target key K.
[0180] This process not only enhances the security and randomness of the key, but also ensures that each derived key is unique, thereby improving the security and anti-attack capabilities of the entire system. In addition, the flexibility of this method allows the generation of keys of different lengths and types according to different security requirements and environmental conditions to adapt to diverse security scenarios.
[0181] This embodiment also provides a penetration testing device, which is used to implement the above embodiments and preferred implementations, and will not be repeated here. As used below, the terms "module", "unit", "subunit", etc. can implement a combination of software and / or hardware for a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0182] Figure 4 is a structural block diagram of a penetration testing device according to an embodiment of the present application, such as Figure 4As shown in the figure, the device includes: a traffic capture module 41, which is used to obtain the encrypted data of the national secret algorithm obtained by encrypting the traffic data of the national secret protocol, and obtain the public key of the peer end, where the peer end is the system under test; a decryption module 42, which is used to calculate the local private key according to the preset elliptic curve parameters, obtain the shared secret based on the local private key and the public key of the peer end; perform key derivation processing on the shared secret to generate a target key, and decrypt the encrypted data of the national secret algorithm based on the target key to obtain decrypted data; a recombination and parsing module 43, which is used to perform recombination and parsing processing on the decrypted data to obtain application layer parsing data; an intelligent attack module 44, which is used to generate an attack payload according to the application layer parsing data, and use the attack payload to perform an attack test on the system under test to obtain a test result.
[0183] It should be noted that the above-mentioned various modules can be functional modules or program modules, and can be implemented either by software or by hardware. For the modules implemented by hardware, the above-mentioned various modules can be located in the same processor; or the above-mentioned various modules can also be located in different processors in any combined form. Specific examples in this embodiment can refer to the examples described in the above-mentioned embodiment and optional implementation manners, and will not be elaborated in this embodiment.
[0184] The present application will be described below in conjunction with specific embodiments. Figure 5 It is a flowchart of a penetration test execution according to an embodiment of the present application. The process includes the following steps:
[0185] Step S501, target configuration: The user inputs the test target IP, SM2 certificate, and password card key through the visual interface.
[0186] Step S502, environment initialization: The system loads the SM2 private key from the password card and initializes the national secret protocol stack.
[0187] Step S503, traffic capture: Real-time capture the TLCP traffic of the target host through the DPDK driver.
[0188] Step S504, protocol parsing: Reverse analyze the SM2 key negotiation process, derive the SM4 session key, and decrypt the data stream.
[0189] Step S505, vulnerability detection: Use the Transformer model to analyze the decrypted traffic and detect vulnerability features (such as key reuse).
[0190] Step S506, policy generation: Generate an optimal attack sequence based on reinforcement learning (such as forging a certificate first and then implementing a MITM attack).
[0191] Step S507, Attack Execution: Automatically send attack payloads and monitor the target responses in real time.
[0192] Step S508, Effect Analysis: Verify whether the attack is successful (such as obtaining sensitive data, elevating system privileges).
[0193] Step S509, Report Generation: Summarize the test results and generate a test report containing compliance scores.
[0194] Figure 6 It is an architecture diagram of a penetration testing system according to an embodiment of the present application. The architecture mainly includes:
[0195] The terminal layer 601 is used to support the capture of national cryptography encrypted traffic (high-speed packet capture based on DPDK), integrate a national cryptography password card (such as the SSX35 series) to achieve secure key storage, and provide a visual test configuration interface (supporting SM2 certificate import and target IP configuration).
[0196] The protocol parsing layer 602 is used for SM2 key exchange parsing: Reverse the protocol stack based on dynamic symbolic execution technology to achieve automatic decryption of the elliptic curve parameter negotiation process, and SM4 traffic decryption: Implement a high-performance SM4 traffic decryption module that supports 200Mbps real-time decryption. Optimize the SM4 decryption algorithm using GPU acceleration (such as CUDA or OpenCL) to significantly improve throughput.
[0197] The intelligent decision-making layer 603 is used to generate reinforcement learning attack strategies: Based on the hierarchical PPO algorithm, achieve macro attack phase selection (such as reconnaissance → vulnerability exploitation → privilege maintenance) and micro payload generation, load the vulnerability knowledge base: Include vulnerability patterns specific to the national cryptography environment (such as SM2 key reuse vulnerability, SM4-CBC mode IV prediction), and attack effect evaluation: Analyze the contribution degree of the attack path using an attack path evaluation model.
[0198] The execution control layer 604 is used to generate attack payloads: Dynamically combine attack primitives (such as certificate forgery, MITM interception, replay attack), automate test execution: Support distributed task scheduling (parallel testing based on Celery), and real-time monitoring system: Monitor the attack process through Prometheus + Grafana.
[0199] The management layer 605 is used to run a compliance verification engine: Built-in GM / T 0024-2014 detection rules (including 32 core indicators), equipped with a report generation system: Automatically generate a penetration test report that meets the requirements of Equal Protection 2.0, and also has a knowledge base update function to continuously update the vulnerability feature library through online learning.
[0200] In addition, in combination with the penetration testing method in the above embodiments, an embodiment of the present application can be implemented by providing a storage medium. A computer program is stored on the storage medium; when the computer program is executed by a processor, any one of the penetration testing methods in the above embodiments is implemented.
[0201] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data that have been authorized by the user or fully authorized by all parties.
[0202] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, a database, or other media used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memories can include read-only memory (ROM), magnetic tapes, floppy disks, flash memories, optical memories, high-density embedded non-volatile memories, resistive random access memories (ReRAM), magnetoresistive random access memories (MRAM), ferroelectric random access memories (FRAM), phase change memories (PCM), graphene memories, etc. Volatile memories can include random access memory (RAM) or external cache memories, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in the present application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., without limitation. The processors involved in the embodiments provided in the present application can be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, data processing logics based on quantum computing, etc., without limitation.
[0203] Those skilled in the art should understand that the technical features of the above-described embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered to be within the scope described in this specification.
[0204] The above-described embodiments only express several implementation manners of the present application, and the description thereof is relatively specific and detailed, but it should not be construed as a limitation on the scope of the invention patent. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application should be subject to the appended claims.
Claims
1. A penetration testing method, characterized in that, The method includes: Obtaining the encrypted data encrypted by the national cryptography algorithm for the traffic data of the national cryptography protocol, and obtaining the public key of the peer end, where the peer end is the system under test; Calculating the private key of the local end according to the preset elliptic curve parameters, obtaining the shared secret based on the private key of the local end and the public key of the peer end; performing key derivation processing on the shared secret to generate the target key, and decrypting the encrypted data of the national cryptography algorithm based on the target key to obtain the decrypted data; Performing recombination and parsing processing on the decrypted data to obtain the application layer parsing data; Generating an attack payload according to the application layer parsing data, and using the attack payload to perform an attack test on the system under test to obtain a test result.
2. The penetration testing method according to claim 1, wherein The generating an attack payload according to the application layer parsing data includes: Inputting the application layer parsing data into the trained hierarchical reinforcement learning model, using the hierarchical reinforcement learning model to detect the vulnerability type of the application layer parsing data to obtain the vulnerability type, and performing local policy planning processing according to the vulnerability type to generate the attack payload.
3. The penetration testing method according to claim 2, wherein The detecting the vulnerability type of the application layer parsing data to obtain the vulnerability type includes: Establishing a vulnerability knowledge base; the vulnerability knowledge base stores known vulnerability data; Detecting the vulnerability type of the application layer parsing data to obtain a vulnerability feature vector; Traversing the known vulnerability data stored in the vulnerability knowledge base, and retrieving the target vulnerability data that matches the vulnerability feature vector from the vulnerability knowledge base; Determining the vulnerability type based on the target vulnerability data.
4. The penetration testing method according to claim 3, wherein After traversing the known vulnerability data stored in the vulnerability knowledge base, the method further includes: In the case of failing to retrieve the target vulnerability data that matches the vulnerability feature vector from the vulnerability knowledge base, inputting the vulnerability feature vector into the trained vulnerability classification model, and outputting the vulnerability type of the vulnerability feature vector; Updating the vulnerability feature vector and the vulnerability type to the vulnerability knowledge base to obtain a new vulnerability knowledge base.
5. The penetration testing method according to claim 2, characterized in that The training process of the hierarchical reinforcement learning model includes: Inputting the obtained training data set into the initial reinforcement learning model, generating an attack phase based on the training data set through the initial global policy network in the initial reinforcement learning model, and determining an attack path based on the training data set and the attack phase through the initial local policy network in the hierarchical reinforcement learning model; Calculating the contribution value of the attack path by using a preset attack path evaluation model; calculating the reward value of each attack test based on the contribution value; optimizing the initial global policy network and the initial local policy network based on the reward value, and generating the hierarchical reinforcement learning model.
6. The penetration testing method according to claim 1, wherein The generating an attack payload according to the application layer parsing data includes: Performing compliance verification on the system under test based on the application layer parsing data and the obtained preset system configuration to obtain a compliance verification result; Generating an attack payload according to the application layer parsing data and the compliance verification result.
7. The penetration testing method according to claim 6, wherein Performing compliance verification on the system under test based on the application layer parsed data and the obtained preset system configuration, and obtaining a compliance verification result, including: Calculating a key update period based on the application layer parsed data, and comparing the key update period with a preset period threshold to obtain the key update period compliance verification result; Calculating a certificate hash value based on the application layer parsed data, mapping the certificate hash value into a bit array based on multiple hash functions, and determining index positions in the bit array corresponding to the multiple hash functions; judging the certificate revocation status based on the detection results of the index positions to obtain the certificate compliance verification result.
8. The penetration testing method according to any one of claims 1 to 7, characterized in that, Performing key derivation processing on the shared secret to generate a target key, including: Calculating a hash value based on the shared secret using a hash algorithm; performing key derivation processing on the shared secret according to the hash value, and generating the target key.
9. A penetration testing device, characterized in that, The device includes: A traffic capture module, configured to obtain encrypted data of the national cryptography algorithm obtained by encrypting the national cryptography protocol traffic data, and obtain the public key of the peer end, where the peer end is the system under test; A decryption module, configured to calculate the local private key according to preset elliptic curve parameters, obtain a shared secret based on the local private key and the public key of the peer end; perform key derivation processing on the shared secret to generate a target key, and decrypt the encrypted data of the national cryptography algorithm based on the target key to obtain decrypted data; A recombination and parsing module, configured to perform recombination and parsing processing on the decrypted data to obtain application layer parsed data; An intelligent attack module, configured to generate an attack payload according to the application layer parsed data, and use the attack payload to perform an attack test on the system under test to obtain a test result.
10. A storage medium, characterized in that, A computer program is stored in the storage medium, wherein the computer program is set to execute the penetration testing method according to any one of claims 1 to 8 when running.
