Application program interface attack detection method, device and readable storage medium
By performing feature comparison and abnormal behavior detection on the input parameters of API requests on the server side, the security issues of API interfaces in cases of user credential leakage and non-APIM platform integration are resolved, achieving more efficient API data protection and enhanced security.
Patent Information
- Application Number
- CN201910644347.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-07-17
- Publication Date
- 2024-11-19
- Estimated Expiration
- 2039-07-17
AI Technical Summary
Existing technologies cannot effectively protect API interfaces from the leakage of user credentials, and API interfaces not connected to the APIM platform in intranet environments are vulnerable to attacks and lack data security protection capabilities.
By performing feature comparison on the input parameters of the API requests sent by the client on the server side, abnormal behavior is detected by using black features and SQL syntax tree structure. Malicious requests are identified by combining request frequency and difference frequency, and security handling policies such as rate limiting, alarms or access denial are executed.
It improves the protection of API data security, reduces the cost of security verification, enhances the accuracy and convenience of verification, and strengthens the security of API interfaces.
Smart Images

Figure CN110378120B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and in particular to an application program interface-based attack detection method, device, and readable storage medium. Background Art
[0002] With the advent of the big data era, many companies are gradually deploying their businesses in the cloud, and application services have become a trend. In more and more scenarios, application architectures use application programming interfaces (APIs) as data transmission and control processes between applications. At the same time, the amount of data transmitted by APIs and their sensitivity are also increasing.
[0003] In order to prevent attackers from obtaining sensitive data (such as user identity information) through the API interface, the existing solution is to send the request originally sent to the API interface to the application programming interface manager (APIM) through middleware or proxy, and verify the identity and authority of the user credentials through the APIM platform, and then forward the request that meets the requirements to the original API interface address, and finally send the returned data back to the requester to complete an API interface call. This method is used to uniformly manage API interfaces and prevent API attacks. The existing solution cannot protect the security of the API interface when the user credentials are leaked, and in some intranet environments, due to the lack of security awareness of developers and the convenience of interface debugging, many API interfaces will not be connected to the APIM platform, and thus it is inevitable that they will be exploited by attackers. Therefore, how to improve the protection capability of API data security is a technical problem that needs to be solved urgently. Summary of the invention
[0004] The embodiments of the present invention provide an application program interface attack detection method, device and readable storage medium, which can enhance the protection capability for API data security and improve the security of API.
[0005] An embodiment of the present invention provides an application program interface (API) attack detection method, which is applied to a server and includes:
[0006] Get the first input parameter in the API request sent by the client;
[0007] Comparing the characteristics of the first input parameter with the characteristics of the input parameter in the legitimate API request to determine a security detection result of the first input parameter, where the security detection result is used to indicate whether the first input parameter has passed or failed detection;
[0008] If the security detection result indicates that the first input parameter detection fails, a security processing policy is executed on the client.
[0009] The comparing the feature of the first input parameter with the feature of the input parameter in the legitimate API request to determine the security detection result of the first input parameter includes:
[0010] Determining whether the first input parameter includes a preset black feature;
[0011] If the first input parameter includes the preset black feature, performing sentence structure splitting on the first input parameter;
[0012] Determine whether the number of branch structures after the statement structure of the first input parameter is split is not equal to a first threshold, where the first threshold is the number of branch structures of the input parameter of the legal API request;
[0013] If the number of branch structures after the statement structure of the first input parameter is split is not equal to the first threshold, the security detection result indicates that the first input parameter detection fails;
[0014] The security processing strategy includes at least one of current limiting, warning and access denial.
[0015] Wherein, after determining whether the number of branch structures after the sentence structure of the first input parameter is split is not equal to the first threshold, the method further includes:
[0016] If the number of branch structures after the statement structure of the first input parameter is split is not equal to the first threshold, determining whether the length of the first input parameter is greater than or equal to a second threshold;
[0017] If the length of the first input parameter is greater than or equal to the second threshold, the security detection result indicates that the first input parameter detection fails.
[0018] The first input parameter includes N input parameters, where N is an integer greater than or equal to 2; comparing the features of the first input parameter with the features of the input parameter in the legitimate API request to determine the security detection result of the first input parameter includes:
[0019] Determine a plurality of input parameters among the N input parameters whose request frequency is less than or equal to a third threshold, where the third threshold is the request frequency of the input parameters in the legitimate API request;
[0020] Sorting the multiple input parameters in order from large to small or from small to large;
[0021] Determine the difference between every two adjacent input parameters in the sorted plurality of input parameters;
[0022] Determining whether the frequency of the difference between two adjacent input parameters among the multiple input parameters is greater than or equal to a fourth threshold;
[0023] If the frequency of the difference between two adjacent input parameters among the multiple input parameters is greater than or equal to the fourth threshold, the security detection result indicates that the first input parameter detection fails;
[0024] The security processing strategy includes at least one of current limiting, warning and access denial.
[0025] Wherein, the method further comprises:
[0026] If the security detection result indicates that the first input parameter detection fails, an alarm message is sent to the security operation and maintenance platform or the administrator. The alarm message includes one or more of the alarm event identifier, the identification information of the client, the first input parameter, or the time information when the client sends the API request.
[0027] An embodiment of the present invention provides an application program interface (API) attack detection device, including:
[0028] An acquisition unit, used to acquire a first input parameter in an API request sent by a client;
[0029] a detection unit, configured to compare a feature of the first input parameter with a feature of an input parameter in a legitimate API request, and determine a security detection result of the first input parameter, wherein the security detection result is used to indicate whether the first input parameter has passed or failed detection;
[0030] A security processing unit is configured to execute a security processing policy on the client if the security detection result indicates that the first input parameter detection fails.
[0031] Wherein, the detection unit comprises:
[0032] A first judging unit, configured to judge whether the first input parameter includes a preset black feature;
[0033] a splitting unit, configured to perform sentence structure splitting on the first input parameter if the first input parameter includes the preset black feature;
[0034] A second judgment unit is used to judge whether the number of branch structures after the first input parameter is split into statement structures is not equal to a first threshold, where the first threshold is the number of branch structures of the input parameter of the legal API request;
[0035] If the number of branch structures after the statement structure of the first input parameter is split is not equal to the first threshold, the security detection result indicates that the first input parameter detection fails;
[0036] The security processing strategy includes at least one of current limiting, warning and access denial.
[0037] Wherein, the detection unit further includes:
[0038] A third judgment unit is used to judge whether the length of the first input parameter is greater than or equal to a second threshold if the number of branch structures after the sentence structure of the first input parameter is split is not equal to the first threshold;
[0039] If the length of the first input parameter is greater than or equal to the second threshold, the security detection result indicates that the first input parameter detection fails.
[0040] The first input parameter includes N input parameters, where N is an integer greater than or equal to 2; and the detection unit includes:
[0041] A first determining unit, configured to determine a plurality of input parameters whose request frequencies are less than or equal to a third threshold value among the N input parameters;
[0042] A sorting unit, used to sort the multiple input parameters in order from large to small or from small to large;
[0043] A second determining unit, configured to determine a difference between every two adjacent input parameters in the sorted plurality of input parameters;
[0044] a fourth determination unit, configured to determine whether a frequency of a difference between two adjacent input parameters among the plurality of input parameters is greater than or equal to a fourth threshold;
[0045] If the frequency of the difference between two adjacent input parameters among the multiple input parameters is greater than or equal to the fourth threshold, the security detection result indicates that the first input parameter detection fails;
[0046] The security processing strategy includes at least one of current limiting, warning and access denial.
[0047] Wherein, the device further comprises:
[0048] A sending unit is used to send an alarm message to a security operation and maintenance platform or an administrator if the security detection result indicates that the first input parameter detection fails. The alarm message includes one or more of an alarm event identifier, identification information of the client, the first input parameter, or time information when the client sends the API request.
[0049] An embodiment of the present invention provides an application program interface (API) attack detection device, including: a processor and a memory;
[0050] The processor is connected to a memory, wherein the memory is used to store a computer program, and the processor is used to call the computer program to execute a method as in one aspect of an embodiment of the present invention.
[0051] An embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. The computer program includes program instructions. When the program instructions are executed by a processor, the method in one aspect of the embodiment of the present invention is executed.
[0052] The embodiment of the present invention can obtain the first input parameter in the API request sent by the client, and then compare the characteristics of the first input parameter with the characteristics of the input parameter in the legal API request, perform a security check on the first input parameter to obtain a security check result, and the security check result is used to indicate whether the above-mentioned first input parameter has passed or failed the test. If the security check result indicates that the above-mentioned first input parameter has failed the test, the security processing strategy is executed on the above-mentioned client. It can be seen that after receiving the API request sent by the client, the server can extract the input parameters (or parameter variables) in the API request, and then use the characteristics of the input parameters to perform a security check on the input parameters to identify whether the API request (or client) is legal, instead of the third party performing the identity authentication of the client before receiving the API request as in the prior art, which saves the cost of security verification and improves the convenience of security verification. In addition, compared with the user credential verification method in the prior art, the security verification based on the input parameters has a higher verification accuracy, thereby improving the protection capability for API data security and improving the security of the API. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0054] Figure 1 is a schematic diagram of a network architecture provided by an embodiment of the present invention;
[0055] Figure 2 It is a scenario diagram of an API attack detection method provided by an embodiment of the present invention;
[0056] Figure 3It is a flowchart of an API attack detection method provided by an embodiment of the present invention;
[0057] Figure 4 It is a schematic diagram of a software architecture of a server provided by an embodiment of the present invention;
[0058] Figure 5 It is a flowchart of another API attack detection method provided by an embodiment of the present invention;
[0059] Fig. 6A It is a schematic diagram of an SQL syntax tree structure generated by using AST for a normal SQL statement provided by an embodiment of the present invention;
[0060] Figure 6B It is a schematic diagram of an SQL syntax tree structure generated by using AST for a normal SQL statement provided by an embodiment of the present invention;
[0061] Figure 6C It is a schematic diagram of an SQL syntax tree structure generated by using AST for an abnormal SQL statement provided by an embodiment of the present invention;
[0062] Figure 7 It is a flowchart of another API attack detection method provided by an embodiment of the present invention;
[0063] Figure 8 is a characteristic schematic diagram of a data enumeration request provided by an embodiment of the present invention;
[0064] Fig. 9 It is a structural diagram of an application program interface API attack detection device provided by an embodiment of the present invention;
[0065] Fig.10 It is a structural diagram of another application program interface API attack detection device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0066] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0067] See also Figure 1 , is a schematic diagram of a network architecture provided by an embodiment of the present invention. The network architecture may include one or more servers and one or more terminal devices (such as Figure 1As shown, it specifically includes terminal device 100a, terminal device 100b, terminal device 100c, and server 200. Server 200 can transmit data with each terminal device through the network. Each terminal device can install various application APPs (such as WeChat). Server 200 can be a background server corresponding to various applications. Therefore, each terminal device can transmit data with server 200 through the client corresponding to the various applications. For example, server 200 can send user information (such as user identity information) to each terminal device. Terminal devices may include mobile phones, tablet computers, laptops, PDAs, mobile internet devices (mobile internet devices, MIDs), and wearable devices (such as smart watches, smart bracelets, etc.). Each terminal device can display relevant application interfaces or information in the client corresponding to each type of application.
[0068] Please refer to Figure 2 , is a schematic diagram of a scenario of an API attack detection method provided by an embodiment of the present invention. Figure 2 As shown, the scene is Figure 1Taking the terminal device 100a in the corresponding embodiment as an example, after the terminal device 100a opens the company's website, the names of the company's employees can be displayed in the terminal display interface. In this page, when the user or company manager clicks on the name of a certain employee (for example, "Zhang San"), the terminal device 100a can respond to the user's or company manager's selection operation on the employee and send an API request to the server 200 (for example, the user's original command is "select*from Users where Id=1") to request to obtain the resume information of the employee. The server 200 can determine the user identification information corresponding to the terminal device 100a that issued the request and the index information corresponding to the resume information of the employee (for example, ID=1) according to the API request, and query the resume information of ID=1 from the database and return it to the terminal device 100a. After the terminal device 100a receives the resume information of ID=1 returned by the server, the page can jump to the resume page of the employee, and the detailed information of the employee can be displayed on the resume page. Among them, after the terminal device 100a sends an API request to the server 200, the server 200 can perform a security check on the input parameters in the API request sent by the client based on the input parameters in the API request (for example, "select*from Users where Id=1"), combined with the characteristics of the input parameters in the legitimate API request, to obtain a security check result. If the security check result indicates that the API request has passed the check, the server 200 will return the employee's resume information to the terminal device 100a. If the security check result indicates that the API request has not passed the check, the server 200 will not return the employee's resume information to the terminal device 100a, thereby improving the security of the API. In the embodiment of the present application, the input parameter check in the API request sent by the client passes, that is, the API request sent by the client passes, and the input parameter check in the API request sent by the client fails, that is, the API request sent by the client fails.
[0069] See also Figure 3 , is a flow chart of an API attack detection method provided by an embodiment of the present invention. The method may include the following steps:
[0070] Step S101: The server obtains the first input parameter in the API request sent by the client.
[0071] Specifically, the server (the server corresponds to Figure 2The server 200 in the corresponding embodiment can receive API requests sent by one or more clients. Each client can send multiple API requests to the server within a period of time. Each API request contains input parameters (or input variables). For example, the input parameters can be Structured Query Language (SQL) statements. In addition to the input parameters, the API request sent by the client can also include information such as request time, source IP, and WEB parameters. Some of the input parameters can be selected by the user, and some can be pre-set by the developer, for example Figure 2 In the employee name display page shown, the user can select the name of one of the employees, thereby triggering the terminal device 100a to send an API request to the server 200 to obtain the resume information of the employee. Assuming that Zhang San's resume index is 1 and Li Si's resume index is 2, the user clicks Zhang San's name, and the input parameter carried in the API request sent by the terminal device 100a to the server 200 is the SQL statement "select * from Users where Id = 1", where the index "1" is selected by the user and "select * from Users where Id = " is preset by the developer.
[0072] In step S102, the server compares the characteristics of the first input parameter with the characteristics of the input parameter in the legitimate API request to determine the security detection result of the first input parameter, where the security detection result is used to indicate whether the first input parameter has passed or failed the detection.
[0073] By analyzing historical API interface data leakage cases, the embodiment of the present invention summarizes the basic methods of attackers stealing API data, and finds that attackers mainly obtain sensitive data through database dragging (also known as exporting data from the database) operations and data enumeration (also known as traversing input parameters). Therefore, the embodiment of the present invention analyzes these means of stealing API data, extracts the behavioral characteristics of these means, establishes their respective behavioral detection models, and then uses the behavioral detection models to perform security detection on the input parameters.
[0074] The attacker's database dragging behavior is generally achieved by exploiting application layer vulnerabilities. For example, the attacker uses SQL injection vulnerabilities to operate the database. To address this abnormal behavior, the embodiment of the present invention uses malicious black features (or blacklists) combined with SQL syntax tree structures to perform security detection on input parameters. For the specific detection process, see Figure 5 The embodiment shown.
[0075] The attacker's data enumeration operation is usually achieved by exploiting logical vulnerabilities. Generally, after detecting the API interface, the attacker will try to traverse the interface parameters to obtain data. Figure 2 For example, if an attacker obtains the resume information of "Zhang San" by sending an API request with the input parameter "select*from Users where Id=1", and then traverses the parameter variable "1", for example, from 1 to 10000, the resume information of more employees can be obtained. The embodiment of the present invention needs to distinguish between normal user behavior and abnormal behavior, so the input parameter request frequency, difference, and frequency of difference occurrence can be combined to perform security detection on the input parameter. For the specific detection process, please refer to Figure 7 The embodiment shown.
[0076] In this application, the server can deploy security detection products, including but not limited to: Web Application Firewall (WAF), Runtime Application Self-Protection (RASP), Application Programming Interface Manager (APIM), etc. The embodiment of the present invention takes the server deployment of RASP as an example to illustrate the implementation of the present invention. However, the embodiment of the present invention is also applicable to servers that deploy WAF and APIM products.
[0077] RASP is a runtime application self-protection program that can be injected into the server's application program and integrated with the application program to monitor and block attacks in real time, allowing the program itself to have self-protection capabilities. And the application program does not need to make any modifications during coding, only a simple configuration is required. In an embodiment of the present invention, the server can use RASP to monitor key functions (such as database call functions) and obtain parameter information of key functions. For example: the server receives an API request sent by the client, and the API request carries input parameters. RASP will monitor and collect the API requests received by the server and store the input parameters in the API request to the data center, and detect the API request in the background through the characteristics of the input parameters to obtain the detection results. For details, please refer to Figure 4The software architecture diagram shown in the figure. The server includes a data acquisition module and a data analysis module. Among them, the data acquisition module is used to receive the API request sent by the client, and RASP is used to monitor the API request received by the server and save the relevant input parameters of the API request to the data center for subsequent detection process. The data analysis module uses two behavior detection models to analyze the input parameters, among which the application vulnerability analysis module mainly involves a black feature matching module and a syntax tree matching module. The black feature matching module is used to detect whether the input parameters include preset black features, and the syntax tree matching module is used to split the input parameters into syntax tree structures according to the sentence structure, and identify whether the number of branch structures of the syntax tree is the same as the number of legal branch structures, wherein the legal branch structure is the number of branch structures after the input parameters in the legal API request are split into sentence structures. The logic vulnerability analysis module mainly involves a normal behavior detection module and an abnormal behavior detection module, wherein the normal behavior detection module is used to identify normal input parameters with normal request frequency (the request frequency is higher than a certain threshold), and the abnormal behavior detection module is used to identify abnormal input parameters with abnormal request frequency (the request frequency is lower than a certain threshold), wherein the threshold is the request frequency of the input parameters in the legal API request. Legitimate API requests can be API requests that meet the requirements and are summarized through historical analysis and statistics.
[0078] Step S103: If the security detection result indicates that the first input parameter detection fails, the server executes the security processing policy on the client.
[0079] In an embodiment of the present invention, after detecting an abnormal API request, the server can summarize and organize the range of attacker data enumeration (for example, from 1-10000), the attacker's IP address, the attack period, and the API interface data attacked by the attacker, and then send the alarm information (also referred to as work order information) to the person in charge of the machine or the security operation and maintenance platform. Among them, the work order information includes but is not limited to: the first input parameter, the attack time, the business information (the region to which the attacked server belongs, the IP of the attacked server, the IP of the attacker), the alarm event identifier, the alarm reason and the specific explanation (for example, what behavior (drag library behavior, data enumeration behavior) triggered the alarm). The person in charge of the machine or the administrator of the security operation and maintenance platform can manually check the work order information reported by the server. If the work order is confirmed to be an attacker intrusion, the emergency response process is carried out, such as limiting the flow, alarming or denying access to the abnormal client. If the work order is confirmed to be a false alarm, the administrator can choose to add the corresponding command to the known typical business white feature library to improve the accuracy of subsequent detection.
[0080] In implementing the embodiment of the present invention, the first input parameter in the API request sent by the client can be obtained, and then the characteristics of the first input parameter can be compared with the characteristics of the input parameter in the legal API request, and the first input parameter can be subjected to a security check to obtain a security check result, and the security check result is used to indicate whether the above-mentioned first input parameter has passed the test or failed the test. If the security check result indicates that the above-mentioned first input parameter has failed the test, the security processing strategy is executed on the above-mentioned client. It can be seen that after receiving the API request sent by the client, the server can extract the input parameters (or parameter variables) in the API request, and then use the characteristics of the input parameters to perform a security check on the input parameters to identify whether the API request (or client) is legal, instead of the third party performing the identity authentication of the client before receiving the API request as in the prior art, which saves the cost of security verification and improves the convenience of security verification. In addition, compared with the user credential verification method in the prior art, the security verification based on the input parameters has a higher verification accuracy, thereby improving the protection capability for API data security and improving the security of the API.
[0081] See also Figure 5 , is a flow chart of another API attack detection method provided by an embodiment of the present invention. The method may include the following steps:
[0082] Step S201: The server obtains the first input parameter in the API request sent by the client.
[0083] In step S202, the server determines whether the first input parameter includes a preset black feature, and if so, executes step S203.
[0084] Here, black features refer to features that are different from normal SQL statements. Developers or managers can extract the features of SQL statements used by attackers to attack and summarize them as black features. Black features can also be called blacklists, which contain the features of SQL statements used by attackers to attack. The server can use black features to distinguish malicious SQL statements. Take the input parameter "select*from Users where Id=1" as an example, where integer 1 is the parameter variable. If the input parameter is "select*from Users where Id=1or 1=1", the parameter variable "1or 1=1" is a black feature. Using black features, the input parameters can be filtered at the first level to filter out normal API requests, and the remaining ones are suspicious API requests, which can reduce the complexity of subsequent calculations and improve the accuracy of detection.
[0085] If the input parameter does not include the preset black feature, it can be determined that the input parameter is a normal input parameter, the API request corresponding to the input parameter is a normal API request, and the security detection result of the API request is passed.
[0086] Step S203: the server splits the first input parameter into sentence structures.
[0087] Among them, statement splitting can be, for example, SQL syntax tree structure splitting. In computer science, the Abstract Syntax Tree (AST), or syntax tree, is a tree representation of the abstract syntax structure of the source code, specifically the source code of the programming language. Each node on the tree represents a structure in the source code. The reason why the syntax is "abstract" is that the syntax here does not represent every detail that appears in the real syntax. The embodiment of the present invention splits the input parameters (or SQL statements) into a SQL syntax tree, and the SQL syntax tree is used to split the multi-layer SQL statement structure and use a tree structure to represent the logical structure of the SQL statement.
[0088] See also Fig. 6A , is a schematic diagram of the SQL syntax tree structure generated by a normal SQL statement using AST. Fig. 6A As shown, the normal SQL statement is "select * from Users where name = 1". It can be seen that the generated SQL syntax tree structure has 8 branches, so the number of branch structures of this SQL statement is 8.
[0089] In step S204, the server determines whether the number of branch structures after the first input parameter is split into statement structures is not equal to a first threshold value, where the first threshold value is the number of branch structures of the input parameters of a legitimate API request. If the number of branch structures after the first input parameter is split into statement structures is not equal to the first threshold value, the security detection result indicates that the first input parameter detection fails.
[0090] The first threshold is the number of branch structures of normal / legal input parameters. The first threshold may be a threshold determined by developers or managers by counting the number of branch structures of SQL syntax trees of normal requests.
[0091] For example, see Figure 6B , is a schematic diagram of the SQL syntax tree structure generated by a normal SQL statement using AST. Figure 6BAs shown in the figure, since the single quotes are escaped in the SQL statement "select*from Users where name='abc\'or 1=1#", the original SQL statement structure has not changed, so the SQL injection has not succeeded. It can be seen that the tree diagram has 8 branches, so the number of branches in this SQL statement is still 8. Therefore, "select*from Users where name='abc\'or 1=1#" is a normal SQL statement, and the API request corresponding to this SQL statement has passed the detection. Figure 6C , is a schematic diagram of the SQL syntax tree structure generated by a malicious SQL statement using AST. Figure 6C As shown in the figure, since the SQL statement "select*from Users where name='abc'or 1=1#" introduces single quotation marks, the grammatical structure of the SQL statement has changed. The gray area is the abnormal node after SQL injection, and the number of branch structures becomes 13, which is different from the normal number of branch structures. Therefore, "select*from Users where name='abc'or 1=1#" is an abnormal SQL statement, and the API request detection corresponding to the SQL statement fails.
[0092] If the number of branch structures after the input parameter is split into statements is equal to the first threshold, it can be determined that the input parameter is a normal input parameter, the API request corresponding to the input parameter is a normal API request, and the security detection result of the API request is passed.
[0093] Step S205: If the security detection result indicates that the first input parameter detection fails, the server executes the security processing policy on the client.
[0094] In an optional implementation, the input parameter can also be more accurately detected in combination with the maximum input bit length. Exemplarily, after step S204 and before step S205, it also includes: if the number of branch structures after the first input parameter is split into a statement structure is not equal to the first threshold, the server further determines whether the length of the first input parameter is greater than or equal to the second threshold, and if the length of the first input parameter is greater than or equal to the second threshold, the security detection result indicates that the first input parameter detection fails.
[0095] The second threshold refers to the maximum input bit length of the input parameter, which can be set by the developer. Normal API request parameters will fluctuate within a reasonable length range, while malicious API requests often have problems such as too long input bit length due to the construction of a valid load (called payload). Therefore, the length of the input parameter can be combined to more accurately identify malicious / illegal API requests. For example, if the second threshold is 100 bits, if the length of the SQL statement in the API request is greater than 100 bits, it can be identified that the API request has failed the detection.
[0096] The relevant description of steps S201 and S205 in the embodiment of the present invention can refer to the aforementioned Figure 3 Steps S101 and S103 in the embodiment are not described in detail here.
[0097] use Figure 5 The method flow of the illustrated embodiment can detect the input parameters in each API request sent by each client, thereby identifying the legitimacy of each API request.
[0098] By implementing the embodiment of the present invention, the server can obtain the input parameters in the API request sent by the client, and then identify whether the input parameters contain preset black features. If so, it can further detect whether the branch structure number of the SQL syntax tree of the input parameter is equal to the normal branch structure number. If not, it can be identified that the input parameter is a malicious input parameter, and the API request corresponding to the input parameter is a malicious API request, and then the security processing strategy can be executed on the client that sent the API request. It can be seen that after receiving the API request sent by the client, the server can extract the input parameters (or parameter variables) in the API request, and then use the black features combined with the SQL syntax tree to perform security detection on the input parameters to identify whether the API request (or client) is legal, instead of the third party performing identity authentication of the client before receiving the API request as in the prior art, which saves the cost of security verification and improves the convenience of security verification. In addition, compared with the user credential verification method in the prior art, the security verification based on the input parameters has a higher verification accuracy, thereby improving the protection capability for API data security and improving the security of the API. In addition, the use of black feature recognition can filter out some legitimate API requests, reduce the complexity of subsequent detection, and use the SQL syntax tree to perform refined detection on the remaining suspicious API requests, which can improve the accuracy of detection. Furthermore, the input parameters can be further refined in combination with the length of the input parameters, which can improve the accuracy of detection.
[0099] See also Figure 7, is a flow chart of another API attack detection method provided by an embodiment of the present invention. The method may include the following steps:
[0100] Step S301: The server obtains N input parameters in the API request sent by the client, where N is an integer greater than or equal to 2.
[0101] Step S302: The server determines a plurality of input parameters among the N input parameters whose request frequencies are less than or equal to a third threshold, where the third threshold is the request frequency of the input parameters in the legitimate API request.
[0102] In an embodiment of the present invention, the requests for the same API can be counted according to a time period T. Assuming that T is 10 minutes, all request data for the same API interface within 10 minutes are sorted according to input parameters, and then the request frequency of each input parameter is counted. Among them, the input parameters with too low request frequency are suspicious, and the input parameters with high request frequency are normal. This is because the characteristics of normal API requests are more obvious, specifically, the parameter range of the request is relatively fixed and the probability of repeated occurrence is relatively high (that is, the frequency of requests is high), while the characteristics of abnormal API requests are low request frequency and the parameter range is mostly linearly related and the difference in the parameter range is fixed. Therefore, the request frequency is used to screen the input parameters. If it exceeds the preset frequency threshold, it is a normal input parameter. If it is lower than the preset frequency threshold, it is an abnormal input parameter for the next step of detection. Among them, the preset threshold can be set by the developer through the request frequency of the input parameters in the historical legal API requests. Please refer to Figure 8 The following are the characteristics of data enumeration requests. The parameter range of normal API requests is relatively fixed and has a high probability of repetition (i.e., the request frequency is high), while the characteristics of abnormal API requests are that the request frequency is low, the parameter range is mostly linear, and the difference in the parameter range is fixed.
[0103] Since the input parameter type may not be an integer, the embodiment of the present invention can count the parameters that conform to the distribution of digital types. For example, the server receives a total of 76 API requests sent by multiple clients to API interface 1 within 10 minutes, where the request frequency of the input parameters carried in each API request can be shown in Table 1 below.
[0104] Table 1
[0105] Input Parameters Request frequency select*from Users where name=1 10 select*from Users where name=2 20 select*from Users where name=3 25 select*from Users where name=4 15 select*from Users where name=100 1 select*from Users where name=200 1 select*from Users where name=201 1 select*from Users where name=300 1 select*from Users where name=400 1 select*from Users where name=500 1
[0106] As can be seen from Table 1, within 10 minutes, for AIP interface 1, the server received the input parameter "select*fromUsers where name=1" 10 times, and received the input parameter "select*from Users where name=100" 1 time. Assuming that the third threshold is 2, it can be determined that the input parameter "select*from Userswhere name=100" is a normal input parameter, and the input parameter "select*from Users where name=100" is a malicious input parameter. Similarly, "select*from Users where name=200", "select*from Userswhere name=201", "select*from Users where name=300", "select*from Users where name=400" and "select*from Users where name=500" are also malicious input parameters, and these input parameters need to be further detected in step S303.
[0107] If the request frequency of the input parameter is greater than the third threshold, it can be determined that the input parameter is a normal input parameter, the API request corresponding to the input parameter is a normal API request, and the security detection result of the API request is passed.
[0108] Step S303: the server sorts the multiple input parameters in order from large to small or from small to large.
[0109] After the server screens out abnormal input parameters, the input parameters may be sorted from large to small or from small to large. For example, after sorting the abnormal input parameters in Table 1 above from small to large, the following Table 2 is obtained.
[0110] Table 2
[0111] Input Parameters Request frequency select*from Users where name=100 1 select*from Users where name=200 1 select*from Users where name=201 1 select*from Users where name=300 1 select*from Users where name=400 1 select*from Users where name=500 1
[0112] Step S304: the server determines the difference between every two adjacent input parameters in the sorted plurality of input parameters.
[0113] After sorting, the difference between every two adjacent input parameters can be calculated. For example, in Table 2 above, it can be determined that the differences of the six input parameters are 100, 1, 99, 100, and 100 respectively.
[0114] Step S305, the server determines whether the frequency of the difference between two adjacent input parameters among multiple input parameters is greater than or equal to a fourth threshold. If the frequency of the difference between two adjacent input parameters among multiple input parameters is greater than or equal to the fourth threshold, the security detection result indicates that the first input parameter detection fails.
[0115] Based on the characteristics of abnormal API requests, first, there is generally a linear relationship between the two (traversing interface parameters), and second, the amplitude of parameter changes is single, that is, the difference is fixed. Therefore, after the filtered and sorted data is subjected to difference statistics, secondary frequency statistics are performed, and the input parameters exceeding the preset frequency threshold are determined as the final abnormal input parameters. For example, the difference values of the 6 input parameters in Table 2 above are 100, 1, 99, 100, and 100, respectively, where the frequency of the difference value 100 is 3 times. Assuming that the fourth threshold value is 1 time, the frequency of the difference value 100 is greater than the fourth threshold value. Therefore, the input parameters "select*from Userswhere name=100", "select*from Users where name=200", "select*from Users wherename=300", "select*from Users where name=400" and "select*from Users wherename=500" are all abnormal input parameters, and the API requests corresponding to these abnormal input parameters are abnormal API requests, and the result of the API request is that the detection fails.
[0116] If the frequency of the difference between two adjacent input parameters in the input parameters is less than the fourth threshold, it can be determined that the input parameter is a normal input parameter, the API request corresponding to the input parameter is a normal API request, and the security detection result of the API request is detection passed.
[0117] In addition to determining the input parameter whose difference frequency is greater than or equal to the fourth threshold as the abnormal input parameter, the input parameter whose difference frequency is the largest may also be determined as the abnormal input parameter.
[0118] Step S306: If the security detection result indicates that the first input parameter detection fails, the server executes the security processing policy on the client.
[0119] The relevant description of steps S301 and S306 in the embodiment of the present invention can refer to the aforementioned Figure 3 Steps S101 and S103 in the embodiment are not described in detail here.
[0120] use Figure 7The method flow of the illustrated embodiment can detect the input parameters in each API request sent by each client, thereby identifying the legitimacy of each API request.
[0121] By implementing the embodiment of the present invention, the server can obtain the input parameters in the API request sent by the client, and then identify whether the request frequency of the input parameters is too low. If so, it can further identify whether the difference of the request range of the input parameters is fixed. If so, it can be identified that the input parameter is a malicious input parameter, and the API request corresponding to the input parameter is a malicious API request, and then the security processing strategy can be executed on the client that sent the API request. It can be seen that after receiving the API request sent by the client, the server can extract the input parameters (or parameter variables) in the API request, and then use the request frequency combined with the request range to perform security detection on the input parameters to identify whether the API request (or client) is legal, instead of the third party performing client identity authentication before receiving the API request as in the prior art, which saves the cost of security verification and improves the convenience of security verification. In addition, compared with the user credential verification method in the prior art, the security verification based on input parameters has a higher verification accuracy, thereby improving the protection capability for API data security and improving the security of the API. In addition, request frequency identification can filter out some legitimate API requests, reduce the complexity of subsequent detection, and use the request range to perform refined detection on the remaining suspicious API requests to improve detection accuracy.
[0122] It should be noted that the above Figure 5 The application vulnerability detection method shown is similar to Figure 7 The logical vulnerability detection method shown can be executed in parallel or separately in actual applications. When the two methods are executed in parallel, the two behavior detection models can be combined to detect API requests, making the detection more accurate.
[0123] See also Fig. 9 , is a schematic diagram of the structure of an application program interface API attack detection device provided by an embodiment of the present invention. Fig. 9 As shown, the application interface attack detection device 1 can be applied to the above Figure 2 Corresponding to the server 200 in the embodiment, the application interface attack detection device 1 may include an acquisition unit 11, a detection unit 12 and a security processing unit 13;
[0124] An acquisition unit 11 is used to acquire a first input parameter in an API request sent by a client;
[0125] A detection unit 12, used to compare the characteristics of the first input parameter with the characteristics of the input parameter in the legitimate API request, and determine a security detection result of the first input parameter, wherein the security detection result is used to indicate whether the first input parameter has passed or failed the detection;
[0126] The security processing unit 13 is configured to execute a security processing policy on the client if the security detection result indicates that the first input parameter detection fails.
[0127] The specific functional implementation of the acquisition unit 11, the detection unit 12 and the security processing unit 13 can be found in the above Figure 3 The specific implementation of the steps S101 to S103 in the corresponding embodiment and the detection unit 12 can also refer to the above Figure 5 Steps S202 to S204 in the corresponding embodiment, or refer to the above Figure 7 Steps S302 to S305 in the corresponding embodiment will not be described in detail here.
[0128] Please also see Fig. 9 , the detection unit 12 may include:
[0129] A first judging unit 121, configured to judge whether the first input parameter includes a preset black feature;
[0130] A splitting unit 122, configured to perform sentence structure splitting on the first input parameter if the first input parameter includes the preset black feature;
[0131] The second judgment unit 123 is used to judge whether the number of branch structures after the statement structure of the first input parameter is split is not equal to a first threshold, and the first threshold is the number of branch structures of the input parameter of the legal API request; if the number of branch structures after the statement structure of the first input parameter is split is not equal to the first threshold, the security detection result indicates that the first input parameter detection fails;
[0132] The security processing strategy includes at least one of current limiting, warning and access denial.
[0133] The specific functional implementation of the first judgment unit 121, the splitting unit 122 and the second judgment unit 123 can be referred to above. Figure 5 The corresponding steps are steps S202 to S204 in the embodiment.
[0134] Please also see Fig. 9 , the detection unit 12 also includes:
[0135] A third judgment unit 124 is used to judge whether the length of the first input parameter is greater than or equal to a second threshold if the number of branch structures after the sentence structure of the first input parameter is split is not equal to the first threshold;
[0136] If the length of the first input parameter is greater than or equal to the second threshold, the security detection result indicates that the first input parameter detection fails.
[0137] The specific function implementation of the third judgment unit 124 can refer to the above Figure 5 Step S205 in the corresponding embodiment will not be described in detail here.
[0138] Please also see Fig. 9 , the first input parameter includes N input parameters, N is an integer greater than or equal to 2; the detection unit 12 may include:
[0139] A first determining unit 125, configured to determine a plurality of input parameters whose request frequencies are less than or equal to a third threshold value among the N input parameters;
[0140] A sorting unit 126, configured to sort the plurality of input parameters in order from large to small or from small to large;
[0141] A second determining unit 127, configured to determine a difference between every two adjacent input parameters in the sorted plurality of input parameters;
[0142] A fourth determination unit 128, configured to determine whether the frequency of the difference between two adjacent input parameters among the plurality of input parameters is greater than or equal to a fourth threshold;
[0143] If the frequency of the difference between two adjacent input parameters among the multiple input parameters is greater than or equal to the fourth threshold, the security detection result indicates that the first input parameter detection fails; wherein the security processing strategy includes at least one of current limiting, warning and access denial.
[0144] The specific functional implementation of the first determining unit 125, the sorting unit 126, the second determining unit 127 and the fourth judging unit 128 can be referred to above. Figure 7 The corresponding steps are steps S302 to S305 in the embodiment.
[0145] Please also see Fig. 9 , the application interface attack detection device 1 also includes:
[0146] The sending unit 14 is used to send an alarm message to the security operation and maintenance platform or the administrator if the security detection result indicates that the first input parameter detection fails. The alarm message includes one or more of the alarm event identifier, the identification information of the client, the first input parameter, or the time information when the client sends the API request.
[0147] The specific functional implementation of the sending unit 14 can be found in the above Figure 3 The corresponding step S303 in the embodiment.
[0148] The embodiment of the present invention can obtain the first input parameter in the API request sent by the client, and then compare the characteristics of the first input parameter with the characteristics of the input parameter in the legal API request, perform a security check on the first input parameter to obtain a security check result, and the security check result is used to indicate whether the above-mentioned first input parameter has passed or failed the test. If the security check result indicates that the above-mentioned first input parameter has failed the test, the security processing strategy is executed on the above-mentioned client. It can be seen that after receiving the API request sent by the client, the server can extract the input parameters (or parameter variables) in the API request, and then use the characteristics of the input parameters to perform a security check on the input parameters to identify whether the API request (or client) is legal, instead of the third party performing the identity authentication of the client before receiving the API request as in the prior art, which saves the cost of security verification and improves the convenience of security verification. In addition, compared with the user credential verification method in the prior art, the security verification based on the input parameters has a higher verification accuracy, thereby improving the protection capability for API data security and improving the security of the API.
[0149] See also Fig.10 , Fig.10 FIG. 1 is a schematic diagram of the structure of another application program interface API attack detection device provided by an embodiment of the present invention. Fig.10 As shown, the application interface API attack detection device 1000 may correspond to the above Figure 2In the corresponding embodiment, the server 200, the application interface API attack detection device 1000 may include: a processor 1001, a network interface 1004 and a memory 1005. In addition, the above-mentioned application interface API attack detection device 1000 may also include: a user interface 1003, and at least one communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. Among them, the user interface 1003 may include a display screen (Display), a keyboard (Keyboard), and the user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or it may be a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 1005 may optionally also be at least one storage device located away from the aforementioned processor 1001. As Fig.10 As shown, the memory 1005 as a computer-readable storage medium may include an operating system, a network communication module, a user interface module, and a device control application program.
[0150] In such Fig.10 In the application program interface API attack detection device 1000 shown in the figure, the network interface 1004 can provide a network communication function; the user interface 1003 is mainly used to provide an input interface for the user; and the processor 1001 can be used to call the device control application stored in the memory 1005 to implement the above Figure 3 , Figure 5 , Figure 7 The description of the API attack detection method in any corresponding embodiment will not be repeated here. In addition, the description of the beneficial effects of the same method will not be repeated here.
[0151] It should be understood that the application program interface API attack detection device 1000 described in the embodiment of the present invention can execute the above Figure 3 , Figure 5 , Figure 7 The description of the application program interface API attack detection method in any corresponding embodiment can also be performed as described above. Fig. 9 The description of the application program interface attack detection device 1 in the corresponding embodiment will not be repeated here. In addition, the description of the beneficial effects of adopting the same method will not be repeated here either.
[0152] In addition, it should be pointed out here that: the embodiment of the present invention further provides a computer-readable storage medium, and the computer-readable storage medium stores a computer program executed by the application program interface attack detection device 1 mentioned above, and the computer program includes program instructions. When the processor executes the program instructions, it can execute the above-mentioned Figure 3 , Figure 5 , Figure 7 The description of the application program interface API attack detection method in any corresponding embodiment will not be repeated here. In addition, the description of the beneficial effects of using the same method will not be repeated. For technical details not disclosed in the computer-readable storage medium embodiment involved in the present invention, please refer to the description of the method embodiment of the present invention.
[0153] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0154] The above disclosure is only the preferred embodiment of the present invention, which certainly cannot be used to limit the scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.
Claims
1. An application program interface API attack detection method, applied to a server, characterized in that: include: Get the first input parameter in the API request sent by the client; Comparing the characteristics of the first input parameter with the characteristics of the input parameter in the legitimate API request to determine a security detection result of the first input parameter, where the security detection result is used to indicate whether the first input parameter has passed or failed detection; If the security detection result indicates that the first input parameter detection fails, executing a security processing policy on the client; The first input parameter includes N input parameters, where N is an integer greater than or equal to 2; comparing the features of the first input parameter with the features of the input parameter in the legitimate API request to determine the security detection result of the first input parameter includes: Determine a plurality of input parameters among the N input parameters whose request frequency is less than or equal to a third threshold, where the third threshold is the request frequency of the input parameters in the legitimate API request; Sorting the multiple input parameters in order from large to small or from small to large; Determine the difference between every two adjacent input parameters in the sorted plurality of input parameters; Determining whether the frequency of the difference between two adjacent input parameters among the multiple input parameters is greater than or equal to a fourth threshold; If the frequency of the difference between two adjacent input parameters among the multiple input parameters is greater than or equal to the fourth threshold, the security detection result indicates that the first input parameter detection fails.
2. The method according to claim 1, characterized in that The comparing the feature of the first input parameter with the feature of the input parameter in the legitimate API request to determine the security detection result of the first input parameter includes: Determining whether the first input parameter includes a preset black feature; If the first input parameter includes the preset black feature, performing sentence structure splitting on the first input parameter; Determine whether the number of branch structures after the statement structure of the first input parameter is split is not equal to a first threshold, where the first threshold is the number of branch structures of the input parameter of the legal API request; If the number of branch structures after the statement structure of the first input parameter is split is not equal to the first threshold, the security detection result indicates that the first input parameter detection fails; The security processing strategy includes at least one of current limiting, warning and access denial.
3. The method according to claim 2, characterized in that After determining whether the number of branch structures after the sentence structure of the first input parameter is split is not equal to the first threshold, the method further includes: If the number of branch structures after the sentence structure of the first input parameter is split is not equal to the first threshold, determining whether the length of the first input parameter is greater than or equal to a second threshold; If the length of the first input parameter is greater than or equal to the second threshold, the security detection result indicates that the first input parameter detection fails.
4. The method according to any one of claims 1 to 3, characterized in that: in, The security processing strategy includes at least one of current limiting, warning and access denial.
5. The method according to claim 1, characterized in that Also includes: If the security detection result indicates that the first input parameter detection fails, an alarm message is sent to the security operation and maintenance platform or the administrator. The alarm message includes one or more of the alarm event identifier, the identification information of the client, the first input parameter, or the time information when the client sends the API request.
6. An application program interface API attack detection device, characterized in that: include: An acquisition unit, used to acquire a first input parameter in an API request sent by a client; a detection unit, configured to compare a feature of the first input parameter with a feature of an input parameter in a legitimate API request, and determine a security detection result of the first input parameter, wherein the security detection result is used to indicate whether the first input parameter has passed or failed detection; A security processing unit, configured to execute a security processing policy on the client if the security detection result indicates that the first input parameter detection fails; The first input parameter includes N input parameters, where N is an integer greater than or equal to 2; and the detection unit includes: A first determining unit, configured to determine a plurality of input parameters whose request frequencies are less than or equal to a third threshold value among the N input parameters; A sorting unit, used to sort the multiple input parameters in order from large to small or from small to large; A second determining unit, configured to determine a difference between every two adjacent input parameters in the sorted plurality of input parameters; a fourth determination unit, configured to determine whether a frequency of a difference between two adjacent input parameters among the plurality of input parameters is greater than or equal to a fourth threshold; If the frequency of the difference between two adjacent input parameters among the multiple input parameters is greater than or equal to the fourth threshold, the security detection result indicates that the first input parameter detection fails.
7. The device according to claim 6, characterized in that The detection unit comprises: A first judging unit, configured to judge whether the first input parameter includes a preset black feature; a splitting unit, configured to perform sentence structure splitting on the first input parameter if the first input parameter includes the preset black feature; A second judgment unit is used to judge whether the number of branch structures after the first input parameter is split into statement structures is not equal to a first threshold, where the first threshold is the number of branch structures of the input parameter of the legal API request; If the number of branch structures after the statement structure of the first input parameter is split is not equal to the first threshold, the security detection result indicates that the first input parameter detection fails; The security processing strategy includes at least one of current limiting, warning and access denial.
8. The device according to claim 7, characterized in that The detection unit also includes: A third judgment unit is used to judge whether the length of the first input parameter is greater than or equal to a second threshold if the number of branch structures after the sentence structure of the first input parameter is split is not equal to the first threshold; If the length of the first input parameter is greater than or equal to the second threshold, the security detection result indicates that the first input parameter detection fails.
9. The device according to any one of claims 6 to 8, characterized in that The first input parameter includes N input parameters, where N is an integer greater than or equal to 2; the detection unit includes: A first determining unit, configured to determine a plurality of input parameters whose request frequencies are less than or equal to a third threshold value among the N input parameters; A sorting unit, used to sort the multiple input parameters in order from large to small or from small to large; A second determining unit, configured to determine a difference between every two adjacent input parameters in the sorted plurality of input parameters; a fourth determination unit, configured to determine whether a frequency of a difference between two adjacent input parameters among the plurality of input parameters is greater than or equal to a fourth threshold; If the frequency of the difference between two adjacent input parameters among the multiple input parameters is greater than or equal to the fourth threshold, the security detection result indicates that the first input parameter detection fails; The security processing strategy includes at least one of current limiting, warning and access denial.
10. The device according to claim 6, characterized in that The device also includes: A sending unit is used to send an alarm message to a security operation and maintenance platform or an administrator if the security detection result indicates that the first input parameter detection fails. The alarm message includes one or more of an alarm event identifier, identification information of the client, the first input parameter, or time information when the client sends the API request.
11. An application program interface API attack detection device, characterized in that: include: Processor and memory; The processor is connected to a memory, wherein the memory is used to store a computer program, and the processor is used to call the computer program to execute the method according to any one of claims 1 to 5.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the method according to any one of claims 1 to 5 is executed.
13. A computer program product, characterized in that The method comprises a computer program / instruction, which, when executed by a processor, implements the method according to any one of claims 1 to 5.
