Full access to SQL injection vulnerabilities-entry (2) _ MySQL

Source: Internet
Author: User
Tags sql server injection
Full access to SQL injection vulnerabilities-Article 2. what test methods are more accurate? The answer is as follows:

① Http://www.19cn.com/showdetail.ASP? Id = 49
② Http://www.19cn.com/showdetail.ASP? Id = 49 and 1 = 1
3 http://www.19cn.com/showdetail.ASP? Id = 49 and 1 = 2

This is the classic 1 = 1, 1 = 2 test method. how can this problem be determined? You can see the results returned from the above three URLs:

Injection performance:

① Normal display (this is inevitable, or the program is wrong)
② Normally displayed, the content is basically the same as ①
③ Prompt BOF or EOF (when the program does not make any judgment), or prompt that the record cannot be found (rs is determined. eof), or the display content is null (the program adds on error resume next)

If it cannot be injected, it is easier to judge. ① it is displayed normally. ② and ③ There are generally program-defined error prompts or error prompts during type conversion.

Of course, this is only the judgment method used when the input parameters are numeric. in actual application, there will be between numeric and search parameters, I will analyze the SQL injection general steps in the intermediate section.

Section 3. database types and injection methods

Different database functions and injection methods are different. Therefore, before injection, we need to determine the database type. Generally, Access and SQLServer are the most commonly used databases in ASP. more than 99% of websites on the Internet are among them.

How can a program tell you what database it uses? Let's take a look:

SQLServer has some system variables. if IIS on the server prompts that it is not closed and SQL Server returns an error message, you can directly obtain the error information as follows:

Http://www.19cn.com/showdetail.ASP? Id = 49 and user> 0

This statement is very simple, but contains the essence of the SQL Server injection method. I also found this efficient method in an unintentional test. Let me take a look at its meaning: first, the preceding statement is normal, with emphasis on and user> 0. we know that user is a built-in variable of SQLServer, the value is the username of the current connection and the type is nvarchar. Compare the nvarchar value with the int value 0. The system will first try to convert the nvarchar value to the int type. of course, the conversion process will definitely fail. the SQLServer error prompt is: a syntax error occurs when converting the nvarchar value "abc" to an int column. The value of abc is the value of the variable user. in this way, the user name of the database is obtained without any effort. In the future, we will see many statements using this method.

By the way, as we all know, the SQLServer user sa is a role equivalent to the Adminstrators permission. with the sa permission, you can almost certainly get the Administrator of the host. The above method can be used to easily test whether to log on with sa. Note that, if it is a log on with sa, an error occurs when "dbo" is converted to an int column, instead of "sa ".

If IIS on the server does not allow an error message to be returned, how can we determine the database type? We can start with the difference between Access and SQLServer. Access and SQLServer both have their own system tables, such as tables that store all objects in the database. Access is in the system table [msysobjects, however, when reading the table in the Web environment, the system prompts "no permission". SQLServer is in the table [sysobjects] and can be read normally in the Web environment.

Use the following statement to confirm that the injection can be performed:

Http://www.19cn.com/showdetail.ASP? Id = 49 and (select count (*) from sysobjects)> 0
Http://www.19cn.com/showdetail.ASP? Id = 49 and (select count (*) from msysobjects)> 0

If the database is SQLServer, then the first web site page with the original page http://www.19cn.com/showdetail.ASP? Id = 49 is roughly the same. However, because the second website cannot find the table msysobjects, an error is Prompted. even if the program is fault tolerant, the page is completely different from the original page.

If the database uses Access, the situation is different. the page of the first website is completely different from the original page. the second website is determined by whether the database allows reading the system table, generally, this is not allowed, so it is completely different from the original website. In most cases, the database type used by the system can be known through the first Web site. The second web site is used only for verification when the IIS error prompt is enabled.

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.