Speaking of URL encoding, you may think of the URL Encoding Vulnerability N years ago. Unfortunately, when I got in touch with the Internet, the vulnerability had long been extinct.
What is URL encoding? Let's take a look at the definition I copied from the Internet:
Reference: URL encoding is a format used by a browser to package form input. The browser obtains all names and values from the form, and encodes them with the name/value parameter (removing characters that cannot be transferred, ranking data, and so on) as part of the URL or sent to the server separately. In either case, the form input format on the server is as follows:
Thename = Ichabod + crane & Gender = male & status = Missing & headless = Yes
URL encoding follows the following rules: each pair of name/value is separated by the & operator; each pair of name/value from the form is separated by the = Operator. If the user does not enter a value for this name, the name still appears, but there is no value. Any special characters (that is, those which are not simple seven-digit ASCII characters, such as Chinese characters) will be encoded in hexadecimal notation with percentages. Of course, they also include = ,&, and %.
The URL encoding is a hexadecimal ASCII code. However, there are some changes. You need to add "%" to the front ". For example, the ASCII code of "/" is 92,92's hexadecimal code is 5C, so the URL encoding of "/" is % 5c. What about the URL encoding of Chinese characters? For example, the ASCII code of "Hu" is-17670, The hexadecimal code is BAFA, And the URL code is "% Ba % Fa ". You know how to switch.
We usually cannot use URL encoding because IE will automatically convert non-numeric letters you enter into the address bar to URL encoding. Therefore, for browsers, http://blog.csdn.net/l31661ke2and http://blog.csdn.net/lake2are equivalent (note that I replaced a with % 61 for the first URL ). Well, you may have remembered that some people put "#" in the database name to prevent downloading, because when ie Encounters "#", it will ignore the following letters. The solution is simple-replace # With the URL code % 23 #. I tried to escape the injection check by using URL encoding, but it failed because the server will convert the URL encoding into characters.
Wait, it seems that I have run the question. Haha, sorry :)
Currently, SQL injection is very popular, so someone has written some injection prevention scripts. Of course, there are different ideas and different effects. For more information, see the following section of the SQL universal anti-injection ASP code.
Fy_url = request. servervariables ("QUERY_STRING ")
Fy_a = Split (fy_url ,"&")
Redim fy_cs (ubound (fy_a ))
On Error resume next
For fy_x = 0 to ubound (fy_a)
Fy_cs (fy_x) = left (fy_a (fy_x), instr (fy_a (fy_x), "=")-1)
Next
For fy_x = 0 to ubound (fy_cs)
If fy_cs (fy_x) <> "" then
If instr (lcase (Request (fy_cs (fy_x), "and") <> 0 then
Response. Write "error! "
Response. End
End if
End if
Next
The idea is to first obtain the submitted data, obtain and process the name/value group based on "&", and then determine whether the value contains the defined keywords (this is simple, I only left "and"). If yes, It is injection.
At first glance, the value is checked, and it seems that there is no problem. Well, yes, there is no problem with the value, but what about the name?
Its name/value group value comes from request. servervariables ("QUERY_STRING"). Sorry, there is a problem. Request. servervariables ("QUERY_STRING") is the string submitted by the client. The URL encoding is not automatically converted here. Haha, If we encode the name and submit it again, then you can bypass the check. For example, if the parameter is ph4nt0m = lake2 and lis0, the program can detect it. If you submit % 50h4nt0m = lake2 and lis0 (URL encoding for P ), the program will judge the value of % 50h4nt0m, and % 50h4nt0m will be converted to ph4nt0m, so the value of % 50h4nt0m is null, so it bypasses the detection.
Wait, why can't value be bypassed since name cannot be decoded? Because the value is obtained from request (fy_cs (fy_x), the server will decode it.
How can we improve the program? You only need to obtain the decoded data submitted by the client. Change the name statement to for each submitname in request. querystring.
Thank you for your patience.