Thursday, September 13, 2012

What Is An SQL Injection? [MakeUseOf Explains]

Whenever a database is being acted upon, there are SQL commands being given and processed. If you think about all of the times when a database is being acted upon, you’ll conclude that it only happens in a handful of circumstances:

When new data needs to be inserted,When current data needs to be changed,When old data needs to be deleted,When a particular piece of data needs to be searched and retrieved.

Any time one of these actions needs to occur, an SQL command is being executed somewhere on a server. For the most part, the programmer gets to determine when and where these SQL commands occur in the source code. However, there are unavoidable circumstances when a user can force a manipulation of a database – and those opportunities are all around you.

Have you ever logged into a website? Have you ever posted a comment on a blog article or a reply in a forum thread? Ever sent a Facebook message to a friend? Typed an email in Gmail? Searched for a website on Google? Any time you see an input field on a website (username, password, search query, message box, etc.), that text is sent to the database and acted upon.

Now, if a malicious user wanted to tamper with a database, there aren’t very many choices for him. One possibility would be to gain actual physical access to the server and destroy it at its base. But otherwise, it makes the most sense for the malicious user to hijack an existing SQL command when using an input field, thus forcing the server to perform a command different from what was originally intended.

The SQL Injection Technique

This act of hijacking an existing SQL command is what SQL injection refers to. Why is it called injection? Because hijacking an SQL command requires the user to inject his own SQL code when using an input field. Does that sound confusing? Let me illustrate with an example.

Consider MakeUseOf’s login page. When you enter your username and password and hit “Submit“, you’re forcing the web server to generate an SQL command that involves the information you just gave–that is, your username and password. The database receives the information, verifies that the username/password combination is correct, then gives you the proper access to other areas of the site.



View the Original article

No comments:

Post a Comment