SQL injection detection method, device, equipment and computer storage medium
By detecting the response page and network stability, filtering and processing requests to find dynamic parameters, and using dynamic parameters for SQL injection detection, the problem of detection failure and high false positive rate under WAF is solved, and the accuracy of SQL injection detection is improved.
Patent Information
- Application Number
- CN202010429138.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-05-20
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2040-09-10
AI Technical Summary
Existing SQL injection detection methods cannot effectively detect when WAF is deployed, and have a high false negative rate and high false positive rate, resulting in low detection accuracy.
By sending preset abnormal requests to the website to be tested, the response page is detected to determine whether a WAF exists. If not, network stability is detected, the request is filtered to find dynamic parameters, and SQL injection detection is performed based on the dynamic parameters. By modifying Dynamic parameters and detection of return value similarity or delay time to determine the presence of injection.
It improves the accuracy of SQL injection detection, avoids the problems of detection failure and high false alarm rate when WAF exists, and enhances the effectiveness of detection.
Smart Images

Figure CN111581637B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of financial technology (Fintech), and in particular to a SQL injection detection method, device, equipment and computer storage medium. Background Art
[0002] With the development of computer technology, more and more technologies (big data, distributed, blockchain, artificial intelligence, etc.) are applied in the financial field. The traditional financial industry is gradually transforming to Fintech. However, due to the security and real-time requirements of the financial industry, higher requirements are also put forward for SQL (Structured Query Language) injection detection technology. At present, it is to modify the value of http (Hypertext Transfer Protocol) parameters, such as adding some statements that can cause database errors in the parameters, or replacing the parameters with some statements that can make the database conditional statements always true, and then detect whether there is SQL injection in the returned data packet. However, this method cannot effectively detect the battle points where WAF (Web Application Firewall, website application-level intrusion prevention system) is deployed, and the false alarm rate is high. In addition, it can only perform string matching on the returned http corresponding packets, with a high false alarm rate, which makes the accuracy of SQL injection detection low. Therefore, how to improve the accuracy of SQL injection detection has become a technical problem that needs to be solved urgently. Summary of the invention
[0003] The main purpose of the present invention is to provide a SQL injection detection method, device, equipment and computer storage medium, aiming to solve the technical problem of how to improve the accuracy of SQL injection detection.
[0004] To achieve the above object, the present invention provides a SQL injection detection method, which comprises the following steps:
[0005] Sending a preset abnormal request to the website to be tested to obtain a response page fed back by the website to be tested, and determining whether a WAF exists in the website to be tested based on the response page;
[0006] If there is no WAF, check whether the network of the website to be tested is stable;
[0007] If it is stable, filter the normal request corresponding to the abnormal request to detect whether there is a dynamic parameter in the filtered normal request;
[0008] If there are dynamic parameters, SQL injection detection is performed on the website to be tested according to the dynamic parameters.
[0009] Optionally, the step of performing SQL injection detection on the website to be tested according to the dynamic parameters includes:
[0010] Sending the dynamic parameter to the website to be tested to obtain a standard return value fed back by the website to be tested;
[0011] Modify the dynamic parameter and send the modified dynamic parameter to the website to be tested to obtain a modified return value fed back by the website to be tested, and detect whether the similarity between the standard return value and the modified return value is less than a preset value;
[0012] If the similarity is less than a preset value, it is determined that SQL injection exists in the website to be tested.
[0013] Optionally, the step of detecting whether the similarity between the standard return value and the modified return value is less than a preset value includes:
[0014] Detect whether the delay time of the modified return value fed back by the tested website is greater than a preset delay time;
[0015] If the delay time is greater than the preset delay time, it is determined that SQL injection exists in the website to be tested;
[0016] If the delay time is less than or equal to the preset delay time, it is detected whether the similarity between the standard return value and the modified return value is less than a preset value.
[0017] Optionally, the step of determining whether a WAF exists in the website to be tested based on the response page includes:
[0018] Detecting whether the response time corresponding to the response page is greater than a preset response time;
[0019] If the response time is less than or equal to the preset response time, a normal request corresponding to the abnormal request is determined, and the original page fed back by the tested website based on the normal request is obtained to detect whether the response page matches the original page;
[0020] If the response page does not match the original page, it is determined that no WAF exists in the website to be tested.
[0021] Optionally, after the step of detecting whether the response time corresponding to the response page is greater than a preset response time, the following steps are included:
[0022] If the response time is greater than the preset response time, it is determined that there is a WAF on the website to be tested, and the WAF is bypassed according to a preset bypass processing method. After the bypass processing is completed, SQL injection detection processing is performed on the website to be tested.
[0023] Optionally, the step of filtering the normal request corresponding to the abnormal request includes:
[0024] Determine a normal request corresponding to the abnormal request, obtain the original page fed back by the tested website based on the normal request, and detect whether the original page and the response page are the same;
[0025] If the original page and the response page are the same, replace the parameters in the normal request to obtain a replacement request, obtain a replacement page fed back by the tested website based on the replacement request, and detect whether the replacement page and the response page are the same, wherein the abnormal request and the replacement request are not the same;
[0026] If the replacement page and the response page are the same, it is determined to filter the normal request.
[0027] Optionally, the step of detecting whether there are dynamic parameters in the normal request after filtering includes:
[0028] Obtain all parameters in the normal request that has been filtered, and traverse each of the parameters in turn, modify the current parameter of the current traversal to obtain a modification request, and send the modification request to the website to be tested to obtain the first page fed back by the website to be tested, and detect whether the first page is the same as the original page;
[0029] If they are not the same, it is determined that there are dynamic parameters in the normal request, and the current parameters are used as dynamic parameters until the traversal of the parameters is completed.
[0030] Optionally, the step of detecting whether the network of the website to be tested is stable includes:
[0031] Send a request URL instruction to the website to be tested, and detect whether the response of the website to be tested has a return value;
[0032] If there is a return value, and the return value is not an http error, it is determined that the network of the website to be tested is stable.
[0033] In addition, to achieve the above object, the present invention also provides a SQL injection detection device, the SQL injection detection device comprising:
[0034] An acquisition module is used to send a preset abnormal request to the website to be tested to obtain a response page fed back by the website to be tested, and determine whether there is a WAF in the website to be tested based on the response page;
[0035] A detection module, used for detecting whether the network of the website to be tested is stable if WAF does not exist;
[0036] A filtering module, for filtering the normal requests corresponding to the abnormal requests if stable, and detecting whether there are dynamic parameters in the filtered normal requests;
[0037] The injection detection module is used to perform SQL injection detection on the website to be tested according to the dynamic parameters if there are dynamic parameters.
[0038] In addition, to achieve the above-mentioned purpose, the present invention also provides a SQL injection detection device, which includes: a memory, a processor, and a SQL injection detection program stored in the memory and executable on the processor, wherein the SQL injection detection program implements the steps of the above-mentioned SQL injection detection method when executed by the processor.
[0039] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer storage medium, on which a SQL injection detection program is stored, and when the SQL injection detection program is executed by a processor, the steps of the SQL injection detection method described above are implemented.
[0040] The present invention sends a preset abnormal request to a website to be tested to obtain a response page fed back by the website to be tested, and determines whether there is a WAF in the website to be tested based on the response page; if there is no WAF, detect whether the network of the website to be tested is stable; if it is stable, filter the normal request corresponding to the abnormal request, and detect whether there are dynamic parameters in the normal request after filtering; if there are dynamic parameters, perform SQL injection detection on the website to be tested according to the dynamic parameters. By sending an abnormal request to the website to be tested, and determining whether there is a WAF in the website to be tested according to the response page fed back by the website to be tested, the phenomenon of SQL injection detection failure due to the existence of WAF in the website to be tested is avoided, and when it is determined that there is no WAF and the website is stable, the normal request is filtered, and then the SQL injection detection is performed on the website to be tested according to the dynamic parameters in the normal request, thereby avoiding the phenomenon that only string matching is performed when performing SQL injection detection in the prior art, resulting in a high false alarm rate. The accuracy of SQL injection detection is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 It is a schematic diagram of the structure of a SQL injection detection device in a hardware operating environment involved in an embodiment of the present invention;
[0042] Figure 2This is a flow chart of the first embodiment of the SQL injection detection method of the present invention;
[0043] Figure 3 A schematic diagram of a device module of a SQL injection detection device of the present invention;
[0044] Figure 4 This is a schematic diagram of the process of detecting WAF in the SQL injection detection method of the present invention;
[0045] Figure 5 It is a schematic diagram of the flow of network stability detection in the SQL injection detection method of the present invention;
[0046] Figure 6 A schematic diagram of the process of parameter filtering in the SQL injection detection method of the present invention;
[0047] Figure 7 A schematic diagram of page similarity detection in the SQL injection detection method of the present invention;
[0048] Figure 8 The present invention is a flowchart of the SQL injection detection method of the present invention.
[0049] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0050] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0051] like Figure 1 As shown, Figure 1 It is a schematic diagram of the structure of a SQL injection detection device in a hardware operating environment involved in an embodiment of the present invention.
[0052] The SQL injection detection device in the embodiment of the present invention may be a PC or a server device, on which a Java virtual machine runs.
[0053] like Figure 1As shown, the SQL injection detection device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional 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 a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0054] Those skilled in the art will understand that Figure 1 The SQL injection detection device structure shown in the figure does not constitute a limitation on the device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0055] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and an SQL injection detection program.
[0056] exist Figure 1 In the SQL injection detection device shown, the network interface 1004 is mainly used to connect to the background server and communicate data with the background server; the user interface 1003 is mainly used to connect to the client (user end) and communicate data with the client; and the processor 1001 can be used to call the SQL injection detection program stored in the memory 1005 and perform the operations in the following SQL injection detection method.
[0057] Based on the above hardware structure, an embodiment of the SQL injection detection method of the present invention is proposed.
[0058] Reference Figure 2 , Figure 2 This is a flow chart of a first embodiment of a SQL injection detection method according to the present invention, wherein the method comprises:
[0059] Step S10, sending a preset abnormal request to the website to be tested to obtain a response page fed back by the website to be tested, and determining whether there is a WAF in the website to be tested based on the response page;
[0060] In this embodiment, SQL (Structured Query Language) injection can be caused by the web (World Wide Web) application not judging the legitimacy of user input data or not filtering it strictly. The attacker can add additional SQL statements to the end of the pre-defined query statements in the web application, and perform illegal operations without the administrator's knowledge, thereby deceiving the database server to perform any unauthorized query, thereby further obtaining the corresponding data information. WAF (Web Application Firewall) provides protection for the system by executing a series of security policies for HTTP / HTTPS. And a normal request can be a normal request to access a website page. An abnormal request is a request to modify one or more parameters in a normal request.
[0061] In this embodiment, before performing SQL injection detection, the URL (uniform resource locator) of the website to be tested needs to be preprocessed, that is, to detect whether the format of the URL is correct. The detection method can be to use regular expressions to determine whether the URL format is correct, and then perform subsequent operations when the URL format is correct. And if there is a site with WAF deployed on the website to be tested, the SQL injection request will be rejected, so that SQL detection cannot be effectively performed. Therefore, it is also necessary to detect whether there is WAF on the website to be tested, that is, Figure 4 As shown, a normal request is constructed and sent to the website to be tested to obtain the original page fed back by the website to be tested, and an abnormal request is constructed based on the normal request and sent to the website to be tested. The website to be tested will feed back a response page based on the abnormal request. At this time, it is necessary to detect whether the feedback time of the website to be tested has timed out. If it has timed out, it is determined that there is a WAF in the website to be tested. If it has not timed out, it is necessary to detect whether the response page and the original page match. If so, it is determined that there is a WAF; if not, it is determined that there is no WAF.
[0062] Step S20: If there is no WAF, then check whether the network of the website to be tested is stable;
[0063] If it is found that there is no WAF on the website to be tested, it is necessary to continue to test the network stability of the website to be tested. The way to test whether the network of the website to be tested is stable can be as follows: Figure 5As shown, first determine the target site URL, and determine whether the DNS (Domain Name System, Domain Name System (Service) Protocol) is successfully resolved. If not, it is determined that the network of the website to be tested cannot be connected. If so, request the target URL to the website to be tested, and detect whether the response fed back by the website to be tested has a return value, and the return value is not an HTTP (Hypertext Transfer Protocol) error. If not, it is determined that the website cannot be connected. If so, it is determined that the website can be connected, and at this time it can be determined that the network of the website to be tested is stable.
[0064] Step S30: If it is stable, filter the normal request corresponding to the abnormal request to detect whether there is a dynamic parameter in the filtered normal request;
[0065] When it is determined that the network of the website to be tested is stable, it is necessary to determine the normal request corresponding to the abnormal request (where the normal request and the abnormal request are basically the same, with only one or several parameters being different), and filter the parameters of the normal request, such as Figure 6 As shown, first send the original request to the website to be tested, and take the response fed back by the website to be tested as the original response. Replace the original request parameter with a random number, and then send it to the website to be tested, get the response R1 replied by the website to be tested, and detect whether the original page corresponding to the original response and the result page corresponding to R1 are similar. If not, it is determined that the parameter cannot be filtered. If so, replace the original request parameter value with another random number, and send it to the website to be tested, get the response R2 replied by the website to be tested, and detect whether R1 and R2 are similar. If not, it is determined that the parameter cannot be filtered. If so, it is determined that the parameter can be filtered.
[0066] After filtering the normal request, it is also necessary to detect whether there are dynamic parameters in the filtered normal request, and perform different operations according to different detection results. In addition, in the present embodiment, it is determined whether there is a vulnerability according to different return packets corresponding to different request parameters, and since there may be advertisements on the pages of the website to be tested, the pages refreshed each time are different. Therefore, it is necessary to perform dynamic page detection to improve the accuracy of SQL injection detection, that is, the detector inputs a string or a regular expression, which exists under the correct page and does not exist under the error page. Therefore, it can be determined based on this whether there is SQL injection on the returned page.
[0067] Among them, the method of detecting dynamic parameters can be to first send a normal request to the website to be tested, obtain the original page fed back by the website to be tested, and determine all parameters in the normal request, then traverse each parameter in turn, and modify the current parameter of the current traversal to obtain the modified parameter, and use the normal request with the modified parameter as a modification request, send the modification request to the website to be tested, obtain the first page fed back by the website to be tested, and detect whether the first page and the original page are the same. If they are not the same, use the current parameter as a dynamic parameter. If they are the same, use the current parameter as a static parameter until the traversal of each parameter is completed.
[0068] Step S40: If there are dynamic parameters, SQL injection detection is performed on the website to be tested according to the dynamic parameters.
[0069] When it is determined that there are dynamic parameters, SQL injection detection can be performed on the website to be tested according to the dynamic parameters. In this embodiment, the SQL injection detection method can be a blind injection based on Boolean or a blind injection based on time.
[0070] Among them, since the responses to the input values of True (accurate) and False (wrong) in the website to be tested are different, a blind injection based on Boolean can be performed, that is, an original normal request is sent to the website to be tested, and the return value of the website to be tested is R, and then the parameters of this normal request are modified one by one. And for each modified request, there is a corresponding Boolean value (for example, an erroneous request will inevitably get an erroneous response; a normal request will also inevitably get a normal response). That is, in this embodiment, each different request corresponds to a different Boolean value, and different requests are determined according to the differences in dynamic parameters in the request, so it can be considered that different dynamic parameters at a certain dynamic parameter position in the request correspond to different Boolean values. When the responses R1, R2, R3, etc. corresponding to each modified request are obtained, the similarity between R and R1, or R2, or R3, etc. can be detected according to the page similarity detection method, and it can be determined whether there is SQL injection according to the level of similarity. The page similarity detection method can be to remove dynamic content from R1 and R2 to obtain the common part K of R1 and R2. After calculating K, the page similarity can be determined as (2*K) / (R1+R2). The dynamic content removal method using the method of finding the longest common subsequence can be as follows Figure 7 As shown, the calculation algorithm can be:
[0071]
[0072] Among them, i can be 0-7, but not limited to this, and j can also be 0-6, but not limited to this. iIt can be any one of A, B, C, or D. i It can also be any one of A, B, C, and D.
[0073] The time-based blind injection uses the sleep() function, which detects how much the response time corresponding to each modified request is delayed relative to the response time corresponding to the normal request, that is, determines the delay time, and determines that SQL injection exists when the delay time is greater than the preset delay time.
[0074] In addition, to assist in understanding the principle of SQL injection detection in this embodiment, an example is given below.
[0075] For example, Figure 8 As shown, when starting the SQL injection detection, the URL of the website to be tested is first preprocessed (i.e., the format is determined), and then it is detected whether there is a WAF in the website to be tested. If so, the WAF in the website to be tested is identified, and a suitable bypass method is selected according to the identified WAF for bypass processing, and then the SQL injection detection is performed. When there is no WAF in the website to be tested, the network stability of the website to be tested is detected. If the website is unstable, the SQL injection detection is terminated. If the network is stable, the parameters of the normal request are processed, and the parameters of each position are checked in a certain order, and repeated parameters and parameters that do not need to be checked are filtered, and then the parameters are checked whether they are dynamic parameters. If so, SQL injection detection is performed and the results are recorded. After the detection is completed, it is determined whether to test the next parameter. If so, the filtering process continues. If not, the SQL injection detection is terminated.
[0076] In this embodiment, a preset abnormal request is sent to the website to be tested to obtain the response page fed back by the website to be tested, and based on the response page, it is determined whether there is a WAF in the website to be tested; if there is no WAF, it is detected whether the network of the website to be tested is stable; if it is stable, the normal request corresponding to the abnormal request is filtered and processed, and it is detected whether there are dynamic parameters in the normal request after filtering; if there are dynamic parameters, the website to be tested is subjected to SQL injection detection according to the dynamic parameters. By sending an abnormal request to the website to be tested, and determining whether there is a WAF in the website to be tested according to the response page fed back by the website to be tested, the phenomenon of SQL injection detection failure due to the existence of WAF in the website to be tested is avoided, and when it is determined that there is no WAF and the website is stable, the normal request is filtered and processed, and then the website to be tested is subjected to SQL injection detection according to the dynamic parameters in the normal request, thereby avoiding the phenomenon that only string matching is performed when performing SQL injection detection in the prior art, resulting in a high false alarm rate. The accuracy of SQL injection detection is improved.
[0077] Further, based on the first embodiment of the SQL injection detection method of the present invention, a second embodiment of the SQL injection detection method of the present invention is proposed. This embodiment is a refinement of step S40 of the first embodiment of the present invention, and the step of performing SQL injection detection on the website to be tested according to the dynamic parameters includes:
[0078] Step a, sending the dynamic parameter to the website to be tested to obtain a standard return value fed back by the website to be tested;
[0079] In this embodiment, when it is determined that there are dynamic parameters, the dynamic parameters can be sent to the website to be tested together with the normal request, and the website to be tested will feedback a return packet, ie, a standard return value, according to the normal request with the dynamic parameters.
[0080] Step b, modifying the dynamic parameter and sending the modified dynamic parameter to the website to be tested to obtain a modified return value fed back by the website to be tested, and detecting whether the similarity between the standard return value and the modified return value is less than a preset value;
[0081] Modify the dynamic parameters, such as randomly replacing a random number to obtain the modified dynamic parameters. At this time, the request with the modified dynamic parameters can be sent to the website to be tested to obtain the return package returned by the website to be tested, that is, modify the return value, and then use the page similarity detection method to detect the similarity between the standard return value and the modified return value, that is, the longest common subsequence can be determined first according to the page similarity detection method, and after obtaining the longest common subsequence, the similarity can be calculated according to the preset calculation formula. For example, if the longest common subsequence is k, the standard return value is n1, and the modified return value is n2, then the similarity is (2*k) / (n1+n2). Then determine whether this corresponding degree is less than the preset value (that is, any value set by the user in advance). And perform different operations according to different detection results.
[0082] Step c: if the similarity is less than a preset value, it is determined that SQL injection exists in the website to be tested.
[0083] When it is determined that the similarity is less than the preset value, it is determined that SQL injection exists in the tested website. However, if the similarity is greater than or equal to the preset value, the next parameter detection can be continued.
[0084] In this embodiment, by determining the similarity between the standard return value of the tested website based on the dynamic parameter feedback and the modified return value of the tested website based on the modified dynamic parameter feedback, and when the similarity is less than a preset value, it is determined that SQL injection exists in the tested website, thereby ensuring the accuracy of SQL injection detection.
[0085] Furthermore, the step of detecting whether the similarity between the standard return value and the modified return value is less than a preset value comprises:
[0086] Step d, detecting whether the delay time of the modified return value fed back by the tested website is greater than a preset delay time;
[0087] In this embodiment, after the modified dynamic parameters are sent to the website to be tested, the difference between the return time of the modified return value fed back by the website to be tested and the normal feedback time fed back by the website to be tested based on the unmodified dynamic parameters is determined, i.e., the delay time, and whether the delay time is greater than the preset delay time (which can be set by the user based on the normal feedback time) is detected. Different operations are then performed according to different detection results.
[0088] Step e: if the delay time is greater than the preset delay time, it is determined that SQL injection exists in the website to be tested;
[0089] When it is determined that the delay time is greater than the preset delay time, it is determined that SQL injection exists in the website to be tested.
[0090] Step x: if the delay time is less than or equal to the preset delay time, detect whether the similarity between the standard return value and the modified return value is less than a preset value.
[0091] If the delay time is less than or equal to the preset delay time, it is possible to continue to detect whether the similarity between the standard return value and the modified return value is less than a preset value, so as to determine whether there is SQL injection in the website to be tested.
[0092] In this embodiment, when it is determined that the delay time for the tested website to feedback the modified return value is greater than the preset delay time, it is determined that SQL injection exists in the tested website, thereby ensuring the accuracy of SQL injection detection.
[0093] Further, the step of determining whether there is a WAF in the website to be tested based on the response page includes:
[0094] Step f, detecting whether the response time corresponding to the response page is greater than a preset response time;
[0095] In this embodiment, when performing WAF detection, it is also necessary to detect the response time of the tested website when responding to the page based on the abnormal request feedback, and detect whether this response time is greater than the preset response time (any response time set by the user in advance), and then perform different operations based on different detection results.
[0096] Step h: if the response time is less than or equal to the preset response time, determine the normal request corresponding to the abnormal request, obtain the original page fed back by the tested website based on the normal request, and detect whether the response page matches the original page;
[0097] When it is determined that the response time is less than or equal to the preset response time, the parameters of the normal request can be determined based on the parameters of the abnormal request, and the parameters of the normal request can be sent to the website to be tested. The website to be tested will feedback page information (i.e., the original page) based on the parameters of the normal request. And detect whether the response page matches the original page. Then perform different operations based on different detection results.
[0098] Step k: If the response page does not match the original page, it is determined that there is no WAF in the website to be tested.
[0099] When it is determined that the response page and the original page do not match, it is determined that there is no WAF in the website to be tested. However, if the response page and the original page match, it is determined that there is a WAF in the website to be tested. That is, in this embodiment, if there is a WAF in the website to be tested, the abnormal request will be intercepted and the same page as the normal request will be fed back, that is, the response page and the original page match at this time.
[0100] In this embodiment, when the response time is less than the preset response time and the response page does not match the original page corresponding to the normal request, it is determined that there is no WAF in the website to be tested, thereby ensuring the accuracy of detecting the WAF.
[0101] Further, after the step of detecting whether the response time corresponding to the response page is greater than the preset response time, the method further includes:
[0102] Step g: if the response time is greater than the preset response time, it is determined that there is a WAF on the website to be tested, and the WAF is bypassed according to a preset bypass processing method. After the bypass processing is completed, SQL injection detection processing is performed on the website to be tested.
[0103] When the response time is greater than the preset response time, it is determined that there is a WAF in the website to be tested, and the WAF can be bypassed according to the preset bypass processing method, that is, a confusion process is performed on the request to bypass the interception of the WAF. For example, select is confused as SeleCT. After the bypass process is completed, the SQL injection detection process is performed on the website to be tested.
[0104] In this embodiment, when it is determined that a WAF exists in the website to be tested, bypass processing is performed, and after the bypass processing is completed, SQL injection detection is performed on the website to be tested, thereby ensuring the accuracy of SQL injection detection.
[0105] Furthermore, the step of filtering the normal request corresponding to the abnormal request includes:
[0106] Step w, determining a normal request corresponding to the abnormal request, obtaining the original page fed back by the tested website based on the normal request, and detecting whether the original page and the response page are the same;
[0107] In this embodiment, it is necessary to first determine the parameters of the normal request according to the parameters of the abnormal request, and determine to send the parameters of the normal request to the website to be tested. The website to be tested feeds back page information (i.e., the original page) based on the parameters of the normal request, and detects whether the original page and the response page are the same. If the original page and the response page are not the same, the difference parameters between the normal request and the abnormal request are determined, and it is determined that the difference parameters cannot be filtered. If they are the same, the subsequent detection process continues.
[0108] Step p, if the original page and the response page are the same, replace the parameters in the normal request to obtain a replacement request, and obtain a replacement page fed back by the tested website based on the replacement request, and detect whether the replacement page and the response page are the same, wherein the abnormal request and the replacement request are not the same;
[0109] When it is found that the original page and the response page are the same after judgment, the parameters in the normal request can be replaced with a random value, and the normal request after the replacement parameters are used as the replacement request, and then the replacement request is sent to the website to be tested, and the page information fed back by the website to be tested according to the replacement request is obtained, that is, the replacement page, and then the replacement page is detected to be the same as the response page, and different operations are performed according to different detection results. That is, in this embodiment, all parameters in the normal request are obtained, and these parameters are checked in turn to determine whether there are target parameters that do not meet the SQL injection detection conditions, that is, to determine which parameters are redundant. That is, assuming that there are three parameters A, B, and C in the normal request, first obtain the original response of the website to be tested based on the normal request feedback. Then modify parameter A to parameter a, and send the normal request with parameter a to the website to be tested, obtain the modified response fed back by the website to be tested, and detect whether the page corresponding to the original response and the page corresponding to the modified response are similar. If they are similar, it is determined that parameter A can be filtered. If not similar, it is determined that parameter A cannot be filtered. And the same detection method is used for parameter B and parameter C to determine whether parameter B or parameter C can be filtered. Among them, abnormal requests and replacement requests cannot be the same.
[0110] Step z: If the replacement page and the response page are the same, determine to filter the normal request.
[0111] When it is found that the replacement page and the response page are the same, it can be directly determined to filter the normal request, that is, if there are parameters that can be filtered in the normal request, the parameters are filtered. However, if the replacement page and the response page are different, the same replacement process is performed on the next parameter in the normal request until all parameters in the normal request have been detected, thereby filtering the correct request.
[0112] In this embodiment, when the original page and the response page are the same, the parameters in the normal request are replaced to obtain a replacement request, and when the response page and the replacement page corresponding to the replacement request are the same, the normal request is filtered, thereby ensuring the efficiency of SQL injection detection on the website to be tested.
[0113] Furthermore, the step of detecting whether there are dynamic parameters in the normal request after filtering includes:
[0114] Step v, obtaining all parameters in the normal request that has been filtered, and traversing each of the parameters in turn, modifying the current parameter currently traversed to obtain a modification request, and sending the modification request to the website to be tested to obtain the first page fed back by the website to be tested, and detecting whether the first page is the same as the original page;
[0115] In this embodiment, when determining the dynamic parameters in a normal request, it is necessary to first obtain all the parameters in the normal request after filtering, and traverse each parameter in turn to determine the current parameter of the current traversal, modify the current parameter to obtain the modified parameter, and use the normal request with the modified parameter as a modification request, send the modification request to the website to be tested, obtain the page fed back by the website to be tested, that is, the first page, and detect whether the first page is the same as the original page, and perform different operations according to different detection results.
[0116] Step t: if they are not the same, it is determined that there are dynamic parameters in the normal request, and the current parameters are used as dynamic parameters until the traversal of all the parameters is completed.
[0117] When it is determined that the first page is different from the original page, it can be determined that there are dynamic parameters in the normal request, and the current parameters can be directly used as dynamic parameters that can be modified. However, if the first page is the same as the original page, it can be determined that the current parameters cannot be used as dynamic parameters, but are static parameters. The same detection method is performed on other parameters in the normal request to determine whether there are dynamic parameters in other parameters, that is, until the traversal of each parameter is completed.
[0118] In this embodiment, by obtaining all parameters in a normal request and modifying the current parameters currently traversed, the modification request and the first page corresponding to the modification request are determined, and when the first page and the original page are different, the current parameters are used as dynamic parameters, thereby ensuring the accuracy of the obtained dynamic parameters.
[0119] Furthermore, the step of detecting whether the network of the website to be tested is stable includes:
[0120] Step n, sending a request URL instruction to the website to be tested, and detecting whether the response of the website to be tested has a return value;
[0121] In this embodiment, when performing network stability detection, it is necessary to first determine whether the DNS can be successfully resolved. If it can be successfully resolved, a request URL instruction is sent to the website to be tested, and it is detected whether there is a return value in the response of the website to be tested based on this URL instruction, and then different operations are performed based on different detection results.
[0122] Step k: if there is a return value, and the return value is not an http error, it is determined that the network of the website to be tested is stable.
[0123] When it is determined that the response in the tested website has a return value and the return value is not an http error, it can be determined that the network of the tested website is stable and SQL injection detection can be performed. Otherwise, it is determined that the network of the tested website is unstable.
[0124] In this embodiment, by sending a request URL instruction to the website to be tested, and when there is a return value in the response of the website to be tested and the return value is not an http error, it is determined that the network of the website to be tested is stable, thereby ensuring the normal progress of SQL injection detection.
[0125] The present invention also provides a SQL injection detection device, referring to Figure 3 , the SQL injection detection device comprises:
[0126] The acquisition module A10 is used to send a preset abnormal request to the website to be tested to obtain a response page fed back by the website to be tested, and determine whether there is a WAF in the website to be tested based on the response page;
[0127] The detection module A20 is used to detect whether the network of the website to be tested is stable if there is no WAF;
[0128] The filtering module A30 is used to filter the normal request corresponding to the abnormal request if it is stable, and detect whether there is a dynamic parameter in the normal request after filtering;
[0129] The injection detection module A40 is used to perform SQL injection detection on the website to be tested according to the dynamic parameters if there are dynamic parameters.
[0130] Optionally, the injection detection module A40 is further used to:
[0131] Sending the dynamic parameter to the website to be tested to obtain a standard return value fed back by the website to be tested;
[0132] Modify the dynamic parameter and send the modified dynamic parameter to the website to be tested to obtain a modified return value fed back by the website to be tested, and detect whether the similarity between the standard return value and the modified return value is less than a preset value;
[0133] If the similarity is less than a preset value, it is determined that SQL injection exists in the website to be tested.
[0134] Optionally, the injection detection module A40 is further used to:
[0135] Detect whether the delay time of the modified return value fed back by the tested website is greater than a preset delay time;
[0136] If the delay time is greater than the preset delay time, it is determined that SQL injection exists in the website to be tested;
[0137] If the delay time is less than or equal to the preset delay time, it is detected whether the similarity between the standard return value and the modified return value is less than a preset value.
[0138] Optionally, the acquisition module A10 is further used to:
[0139] Detecting whether the response time corresponding to the response page is greater than a preset response time;
[0140] If the response time is less than or equal to the preset response time, a normal request corresponding to the abnormal request is determined, and the original page fed back by the tested website based on the normal request is obtained to detect whether the response page matches the original page;
[0141] If the response page does not match the original page, it is determined that no WAF exists in the website to be tested.
[0142] Optionally, the acquisition module A10 is further used to:
[0143] If the response time is greater than the preset response time, it is determined that there is a WAF on the website to be tested, and the WAF is bypassed according to a preset bypass processing method. After the bypass processing is completed, SQL injection detection processing is performed on the website to be tested.
[0144] Optionally, the filtering module A30 is further used for:
[0145] Determine a normal request corresponding to the abnormal request, obtain the original page fed back by the tested website based on the normal request, and detect whether the original page and the response page are the same;
[0146] If the original page and the response page are the same, replace the parameters in the normal request to obtain a replacement request, obtain a replacement page fed back by the tested website based on the replacement request, and detect whether the replacement page and the response page are the same, wherein the abnormal request and the replacement request are not the same;
[0147] If the replacement page and the response page are the same, it is determined to filter the normal request.
[0148] Optionally, the filtering module A30 is further used for:
[0149] Obtain all parameters in the normal request that has been filtered, and traverse each of the parameters in turn, modify the current parameter of the current traversal to obtain a modification request, and send the modification request to the website to be tested to obtain the first page fed back by the website to be tested, and detect whether the first page is the same as the original page;
[0150] If they are not the same, it is determined that there are dynamic parameters in the normal request, and the current parameters are used as dynamic parameters until the traversal of the parameters is completed.
[0151] Optionally, the detection module A20 is further used for:
[0152] Send a request URL instruction to the website to be tested, and detect whether the response of the website to be tested has a return value;
[0153] If there is a return value, and the return value is not an http error, it is determined that the network of the website to be tested is stable.
[0154] The methods executed by the above-mentioned program units can refer to the various embodiments of the SQL injection detection method of the present invention, which will not be repeated here.
[0155] The invention also provides a computer storage medium.
[0156] The computer storage medium of the present invention stores an SQL injection detection program, and when the SQL injection detection program is executed by a processor, the steps of the SQL injection detection method described above are implemented.
[0157] Among them, the method implemented when the SQL injection detection program running on the processor is executed can refer to the various embodiments of the SQL injection detection method of the present invention, and will not be repeated here.
[0158] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0159] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0160] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0161] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A SQL injection detection method, It is characterized in that The SQL injection detection method comprises the following steps: Sending a preset abnormal request to the website to be tested to obtain a response page fed back by the website to be tested, and determining whether a WAF exists in the website to be tested based on the response page; If there is no WAF, check whether the network of the website to be tested is stable; If it is stable, determine the normal request corresponding to the abnormal request, obtain the original page fed back by the tested website based on the normal request, and detect whether the original page and the response page are the same; If the original page and the response page are the same, replace the parameters in the normal request to obtain a replacement request, obtain a replacement page fed back by the tested website based on the replacement request, and detect whether the replacement page and the response page are the same, wherein the abnormal request and the replacement request are not the same; If the replacement page and the response page are the same, determining to filter the normal request; Detecting whether there are dynamic parameters in the normal request after filtering; the dynamic parameters refer to parameters that when the parameter value changes, the page fed back by the tested website is different from the original page; If there are dynamic parameters, the dynamic parameters are sent to the website to be tested to obtain a standard return value fed back by the website to be tested; Modify the dynamic parameter and send the modified dynamic parameter to the website to be tested to obtain a modified return value fed back by the website to be tested, and detect whether the similarity between the standard return value and the modified return value is less than a preset value; If the similarity is less than a preset value, it is determined that SQL injection exists in the website to be tested.
2. The SQL injection detection method according to claim 1, It is characterized in that The step of detecting whether the similarity between the standard return value and the modified return value is less than a preset value comprises: Detect whether the delay time of the modified return value fed back by the tested website is greater than a preset delay time; If the delay time is greater than the preset delay time, it is determined that SQL injection exists in the website to be tested; If the delay time is less than or equal to the preset delay time, it is detected whether the similarity between the standard return value and the modified return value is less than a preset value.
3. The SQL injection detection method according to claim 1, It is characterized in that The step of determining whether a WAF exists in the website to be tested based on the response page includes: Detecting whether the response time corresponding to the response page is greater than a preset response time; If the response time is less than or equal to the preset response time, a normal request corresponding to the abnormal request is determined, and the original page fed back by the tested website based on the normal request is obtained to detect whether the response page matches the original page; If the response page does not match the original page, it is determined that no WAF exists in the website to be tested.
4. The SQL injection detection method as claimed in claim 3, It is characterized in that After the step of detecting whether the response time corresponding to the response page is greater than the preset response time, the method further includes: If the response time is greater than the preset response time, it is determined that there is a WAF on the website to be tested, and the WAF is bypassed according to a preset bypass processing method. After the bypass processing is completed, SQL injection detection processing is performed on the website to be tested.
5. The SQL injection detection method according to claim 1, It is characterized in that The step of detecting whether there is a dynamic parameter in the normal request after filtering includes: Obtain all parameters in the normal request that has been filtered, and traverse each of the parameters in turn, modify the current parameter of the current traversal to obtain a modification request, and send the modification request to the website to be tested to obtain the first page fed back by the website to be tested, and detect whether the first page is the same as the original page; If they are not the same, it is determined that there are dynamic parameters in the normal request, and the current parameters are used as dynamic parameters until the traversal of the parameters is completed.
6. The SQL injection detection method according to any one of claims 1 to 5, It is characterized in that The step of detecting whether the network of the website to be tested is stable comprises: Send a request URL instruction to the website to be tested, and detect whether the response of the website to be tested has a return value; If there is a return value, and the return value is not an http error, it is determined that the network of the website to be tested is stable.
7. A SQL injection detection device, It is characterized in that The SQL injection detection device comprises: An acquisition module is used to send a preset abnormal request to the website to be tested to obtain a response page fed back by the website to be tested, and determine whether there is a WAF in the website to be tested based on the response page; A detection module, used for detecting whether the network of the website to be tested is stable if WAF does not exist; A filtering module, used to determine the normal request corresponding to the abnormal request if it is stable, and obtain the original page fed back by the tested website based on the normal request, and detect whether the original page and the response page are the same; if the original page and the response page are the same, replace the parameters in the normal request to obtain a replacement request, and obtain a replacement page fed back by the tested website based on the replacement request, and detect whether the replacement page and the response page are the same, wherein the abnormal request and the replacement request are not the same; if the replacement page and the response page are the same, determine to filter the normal request; detect whether there are dynamic parameters in the filtered normal request; the dynamic parameter refers to the parameter that when the parameter value changes, the page fed back by the tested website is different from the original page; The injection detection module is used to send the dynamic parameters to the website to be tested if there are any, so as to obtain the standard return value fed back by the website to be tested; modify the dynamic parameters and send the modified dynamic parameters to the website to be tested to obtain the modified return value fed back by the website to be tested, and detect whether the similarity between the standard return value and the modified return value is less than a preset value; if the similarity is less than the preset value, it is determined that SQL injection exists in the website to be tested.
8. A SQL injection detection device, It is characterized in that The SQL injection detection device comprises: a memory, a processor, and a SQL injection detection program stored in the memory and executable on the processor. When the SQL injection detection program is executed by the processor, the steps of the SQL injection detection method according to any one of claims 1 to 6 are implemented.
9. A computer storage medium, It is characterized in that The computer storage medium stores a SQL injection detection program, and when the SQL injection detection program is executed by the processor, the steps of the SQL injection detection method according to any one of claims 1 to 6 are implemented.
