Advanced SQL Injection in the SQL Server application
Author: Chris Anley [chris@ngssoftware.com]
An NGSsoftware Insight Security Research (NISR) Publication
Translation: Qingyan Zhiwolf (Panderlang)
Source: Wolf Online (http://www.panderlang.com/)
The first translation, the level is limited, it is inevitable, please don't finish correct. Reprinted please keep the information intact.
Summary: This document is in detail to discuss SQL injection technology, which is adapted to compare popular IIS ASP SQL Server platforms. It discusses which SQL statements can be injected into the application through a wide variety of methods, and record the data confirmation and database lock associated with the attack.
The expected readers of this document are developers of web programs that communicate with the database and those who play audit web applications.
Introduction: SQL is a structured query language for relational databases. It is divided into many species, but most of them are loosely based on the latest standard SQL-92 for the National Standardization Organization. A typical execution statement is Query, which can collect comparisonable records and return a single result set. The SQL language can modify the database structure (data definition language) and the database content (data operation language). In this document, we will specifically discuss the Transact-SQL language used by SQL Server. When an attacker can operate data written into the application by inserting a series of SQL statements into Query, we are defined as SQL injection.
A typical SQL statement is as follows: Select ID, forename, Surname from authors This statement will return the ID, forename, and weak columns of all rows in the Authors table. This result can be limited, for example: select ID, forename, Surname from authors where forename'john 'and surname =' smith 'requires focus on string' john 'and' Smith 'being limited by single quotes. Clearly, the Forename and Surname field are entered by the user, and an attacker can inject some SQL statements from the input value to this query, as follows: Forename: Jo'Hnsurname: SMITH Query statement becomes: SELECT ID, Forename Surname from authors where forename = 'smith' When the database tries to perform this query, it will return the following error: Server: MSG 170, Level 15, State 1, Line 1Line 1: IncorRect Syntax Near 'HN' The reason for this result is inserted. As a single quotation of the delimiter. The database attempts to perform 'hn', but failed. If an attacker offers special inputs such as: Forename: JO '; Drop Table Authors-Surname: The result is that the Authors table is deleted, and the reason why this result is made later.
It seems that you can solve this problem by getting a single quotation from the input or avoiding them. This is feasible, but there are several difficulties in making a solution with this method. First, not all users provide data is a string. If the user enters an AUTHOR, then our query should be like this: SELECT ID, FORENAME, Surname from authors where id = 1234 In this case, an attacker can add very simple to the end of the numbers. SQL statement, in other versions of SQL languages, use a variety of qualified symbols; in the Database Management System JET engine, the data can be limited by '#'. Second, avoid single quotes, although it can be seen, it is not necessary. For the reason, we will talk later. We further use a simple ASP login page to point out who can enter the SQLServer database and try to authenticate access to some fictional applications. This is a code submitting a single page, allowing users to enter username and password: