ASP injection prevention vulnerability Methods

Source: Internet
Author: User

 

Before configuring security, let's take a look at the attack methods of intruders. Injection attacks are very popular nowadays. The so-called injection attacks are to execute normal SQL statements referenced in ASP together with the SQL statements required by intruders by submitting special addresses, so that intruders can intrude into the system. Now, some script injection tools are released, allowing cainiao to easily launch ASP injection attacks. Let's take a look at how these tools are injected.
First, the intruder will be on a website to determine whether injection can be carried out, assuming an article address: http://www.abc.com/news.asp? Id = 1 is usually tested by submitting two addresses, for example:
Http://www.abc.com/news.asp? Id = 1 and 1 = 1
Http://www.abc.com/news.asp? Id = 1 and 1 = 2
The first address is followed by and 1 = 1, and the SQL statement is changed: the Select * from form name where id = 1 and 1 = 1 must be set up before and after the statement is set up. The address of the previous article can be accessed, and the value 1 = 1 is also objective, so the first address can be displayed normally. On the contrary, 1 = 2 is obviously not true, the key is to take a look at this step. If the page and 1 = 2 is submitted normally, it means that it has not written and 1 = 2 into the SQL statement, and the website does not have the injection vulnerability; however, if an error page is returned after and 1 = 2 is submitted, it means that the site has brought the following statements into the SQL statement and executed it, which means that it can perform SQL injection. (Note: if the address is followed by news. asp? Id = '1' must be changed to news. asp? Id = 1 'and '1' = '1 to enclose the quotation marks)
So what can intruders do after they can be injected?
Here is a simple example, such as submitting an address:
Http://www.abc.com/news.asp? Id = 1 and exists (select * from table name where column name = data)
Check whether the table name and column name are correct based on the returned correct or error page. The specific implementation is to first guess the table name and then guess the column name. After you have guessed the table name and column name, you can use the ASC and MID functions to guess the data of each column. The MID function is in the format of mid (variable name, number of characters starting to read and reading), such as mid (pwd) you can read two characters from the first place in the variable pwd. The ASC function is in the format of ASC ("string"). For example, asc ("a") can read the ASCII code of the letter. In actual application, you can enter asc (mid (pwd,) to read the ASCII code of the first character in the pwd column. submit: asc (mid (pwd,)> 97 determines whether the ASCII code of the first character in the pwd column is greater than 97 (the ASCII code of a) based on whether the returned page is correct ), if it is correct, try again if it is less than 122 (z ASCII code )...... In this way, the ASCII code of characters is gradually reduced, and it is only a matter of time to guess the real ASCII code. The username and password in the database can be obtained by a single-digit guess. There is also an ASP authentication defect-that is, both the user name and password are lost or '1' = '1, construct the SQL statement Select * form name where username = ''or '1' = '1' and pwd ='' or '1' = '1' to bypass password verification..
After talking about this, the defense method is actually very simple. We can prevent injection by disabling the submission of special characters (such as and, or, ', and. ASP transfers data in two ways: get and post. get adds data to a URL and submits the data. post transfers the data to the server using the mail information data field.
Then, let's take a look at how to filter the special characters in the data submitted by get. First, you must know that IIS sends the get request to asp in the form of a string. dll. after QueryString, the asp parser parses the Request. queryString information, and then separate the data in each array with the data. Now we want to make the get method unable to submit the following characters:
', And, exec, insert, select, delete, update, count, *, %, chr, mid, master, truncate, char, declare

The SQL universal anti-injection program is compiled by Feng Zhiqiu of Firefox and has a complete function to prevent injection code. It can filter the defined filter characters and record the data submitted by the attacker's IP address. You only need to add code to the header of the file to be injected <! -- # Include File = "WrSky_ SQL .Asp" --> filter variables. If you add program code after the database connection file (such as conn. asp), you can implement variable filtering on the entire site to prevent injection.

<%
Dim SQL _leaching, SQL _leach_0, SQL _DATA, SQL _Get, SQL _Post
SQL _leaching = "', and, exec, insert, select, delete, update, count, *, %, chr, mid, master, truncate, char, declare"
SQL _leach_0 = split (SQL _leaching ,",")

If Request. QueryString <> "Then
For Each SQL _Get In Request. QueryString
For SQL _Data = 0 To Ubound (SQL _leach_0)
If instr (Request. QueryString (SQL _Get), SQL _leach_0 (SQL _DATA)> 0 Then
Response. Write "please do not try SQL injection! "
Response. end
End if
Next
Next
End if

If request. Form <> "" then
For each SQL _post in request. Form
For SQL _data = 0 to ubound (SQL _leach_0)
If instr (request. Form (SQL _post), SQL _leach_0 (SQL _data)> 0 then
Response. Write "please do not try SQL injection! "
Response. End
End if
Next
Next
End if
%>

To prevent brute-force database cracking, add on error resume next in front of the database file.

<%
On Error resume next
Dim Conn, connstr, DB

%>.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.