• Home
  • Download Free eBook
  • OC Archives
  • Tools I Use
  • Webmaster Forum
  • Write For Us
Logo

  • Discounts
  • SEO Central
    • All other Search
    • Bing
    • Google Central
    • Yahoo
  • Social Networks
    • Digg
    • facebook
    • Squidoo
    • Technorati
    • Twitter
  • Web Design & Development
    • Ajax
    • Coding
    • Database
    • Graphic Design
    • Joomla
    • jQuery
    • OScommerce
    • Photoshop
  • Webmaster Central
    • Author's Corner
    • Case Studies
    • Content Writing
    • Featured Interviews
    • Guest Posts
    • Make Money Online
    • OC Promos
    • Premium Reviews
    • Video Tutorials
    • Web Hosting
    • Web News
    • Web Security
  • Wordpress

What is SQL injection, All about SLQ Injection

Posted by Joshu Thomas on Nov 11, 2009 in Database, Web Security | 5 comments

SQL injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed. It is an instance of a more general class of vulnerabilities that can occur whenever one programming or scripting language is embedded inside another. SQL injection attacks are also known as SQL insertion attacks.

Forms of vulnerability
Incorrectly filtered escape characters
This form of SQL injection occurs when user input is not filtered for escape characters and is then passed into an SQL statement. This results in the potential manipulation of the statements performed on the database by the end user of the application.

The following line of code illustrates this vulnerability:
statement = "SELECT * FROM users WHERE name = '" + userName + "';"

This SQL code is designed to pull up the records of the specified username from its table of users. However, if the “userName” variable is crafted in a specific way by a malicious user, the SQL statement may do more than the code author intended. For example, setting the “userName” variable as

a' or 't'='t

renders this SQL statement by the parent language

SELECT * FROM users WHERE name = 'a' OR 't'='t';

If this code were to be used in an authentication procedure then this example could be used to force the selection of a valid username because the evaluation of ‘t’='t’ is always true.

While most SQL server implementations allow multiple statements to be executed with one call, some SQL APIs such as php’s mysql_query do not allow this for security reasons. This prevents hackers from injecting entirely separate queries, but doesn’t stop them from modifying queries. The following value of “userName” in the statement below would cause the deletion of the “users” table as well as the selection of all data from the “data” table (in essence revealing the information of every user), using an API that allows multiple statements:

a';DROP TABLE users; SELECT * FROM data WHERE 't' = 't

This input renders the final SQL statement as follows:

SELECT * FROM users WHERE name = 'a';DROP TABLE users; SELECT * FROM DATA WHERE 't' = 't';

Incorrect type handling
This form of SQL injection occurs when a user supplied field is not strongly typed or is not checked for type constraints. This could take place when a numeric field is to be used in a SQL statement, but the programmer makes no checks to validate that the user supplied input is numeric. For example:

statement := "SELECT * FROM data WHERE id = " + a_variable + ";"

It is clear from this statement that the author intended a_variable to be a number correlating to the “id” field. However, if it is in fact a string then the end user may manipulate the statement as they choose, thereby bypassing the need for escape characters. For example, setting a_variable to

1;DROP TABLE users

will drop (delete) the “users” table from the database, since the SQL would be rendered as follows:
SELECT * FROM DATA WHERE id=1;DROP TABLE users;

Vulnerabilities inside the database server
Sometimes vulnerabilities can exist within the database server software itself, as was the case with the MySQL server’s mysql_real_escape_string() function[2]. This would allow an attacker to perform a successful SQL injection attack based on bad Unicode characters even if the user’s input is being escaped. This bug was patched with the release of version 5.0.22 (released on 24th May 06).

Blind SQL injection
Blind SQL Injection is used when a web application is vulnerable to SQL injection but the results of the injection are not visible to the attacker. The page with the vulnerability may not be one that displays data but will display differently depending on the results of a logical statement injected into the legitimate SQL statement called for that page. This type of attack can become time-intensive because a new statement must be crafted for each bit recovered. There are several tools that can automate these attacks once the location of the vulnerability and the target information has been established.

Conditional responses
One type of blind SQL injection forces the database to evaluate a logical statement on an ordinary application screen.

SELECT booktitle FROM booklist WHERE bookId = 'OOk14cd' AND 1=1;
will result in a normal page while
SELECT booktitle FROM booklist WHERE bookId = 'OOk14cd' AND 1=2;

will likely give a different result if the page is vulnerable to a SQL injection. An injection like this may suggest that a blind SQL injection is possible, leaving the attacker to devise statements that evaluate to true or false depending on the contents of a field in another table

Conditional errors
This type of blind SQL injection causes an SQL error by forcing the database to evaluate a statement that causes an error if the WHERE statement is true. For example,

SELECT 1/0 FROM users WHERE username='Ralph';
the division by zero will only be evaluated and result in an error if user Ralph exists.

Time delays
Time Delays are a type of blind SQL injection that cause the SQL engine to execute a long running query or a time delay statement depending on the logic injected. The attacker can then measure the time the page takes to load to determine if the injected statement is true.

Compiled by Joshu
Content : www.Wikipedia.com


About Joshu Thomas

I enjoy blogging about webmaster related stuff and technology. Xtras - I Design, Develop, Blog and Support the Open Source. Passions: I Love Music, Photography, Design, Development, Cycling, Travelling.

No related posts.

5 Responses to “What is SQL injection, All about SLQ Injection”

  1. Aish says:
    November 25, 2009 at 9:34 am

    Hey Josh, this is a VERY critical aspect to be taken into consideration while developing a dynamic website. A slight carelessness in this part would end up in getting the site hacked the worst way!!! Thanks for including this one in the blog…
    Cheers…Aish

    Reply
  2. Aish says:
    November 25, 2009 at 9:34 am

    Hey Josh, this is a VERY critical aspect to be taken into consideration while developing a dynamic website. A slight carelessness in this part would end up in getting the site hacked the worst way!!! Thanks for including this one in the blog…
    Cheers…Aish

    Reply
  3. web design hyderabad says:
    November 29, 2009 at 12:37 am

    Excellent Article, Very intersting

    Reply
  4. web design hyderabad says:
    November 29, 2009 at 12:37 am

    Excellent Article, Very intersting

    Reply
  5. Smith says:
    December 23, 2010 at 2:54 pm

    SQL Injection Tutorial:
    http://sec4app.com/download/SQL_Injection_Tutorial.pdf
    SQL Injection Tutorial describes how to use SQL Injection manually

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

*

*

CAPTCHA Image
Refresh Image

*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 Subscribe to OC Blog! 

Subscribe to OC Blog

Stay tuned to the Latest updates and tips in the Webmaster World




Most Popular Posts

  • List of High PR do follow blogs (Verified) (364)
  • Next Google Page rank - PR update 2011 (288)
  • Market Samurai Discount – Save 80 USD! (244)
  • 300 High paying adsense keywords 2011 (112)
  • List of High PR Dofollow Directories 2011 (104)
  • Best Classifieds Ads Scripts (86)
  • 22 OpenSource Forum Scripts - Details and Download: update list (83)
  • Next Google PageRank update 2012 (75)
  • Review of the List of the Best Social Networking websites 2011 (72)
  • How to modify the Wordpress comment Form (70)
  • List of 200 Highest paying Adsense Keywords : Updated list 2010 (54)
  • Featured Interviews: Harsh Agarwal from ShoutMeLoud.com (49)
  • One of the Biggest SEO Secret for Linkbuilding (48)
  • 10 Best Premium Wordpress Plugins (46)
  • Elegant Themes Discount 2011 (Save 10 USD) (44)
  • List of all Top Social Networking websites as on 2010 (42)
  • How i earn Big Bucks from my blog Doing Nothing! (42)
  • 30 Best wordpress Plugins required for Any WP Blog (39)
  • Download KeywordLuv WordPress Plugin (39)
  • Fatal Error on WordPress 3.3 Version Upgrade (39)
  • +Joshu Thomas

    • Founder of OrangeCopper Webmaster Networks, Writes for our latest Launch of 2011 - HippieMonk Tech & LifeStyle Blog!
About OrangeCopper Network 

Who am I? Am Joshu. I enjoy blogging about webmaster related stuff and technology. Xtras - I Design, Develop, Blog and Support the Open Source. Passions: I Love Music, Photography, Design, Development, Cycling, Travelling and sleeping (Favorite)

What i could do for you: Ive been working on various shades of the web for over 11 years now and learned the hard way, Now i could help you learn it the Easy way. OrangeCopper is a Webmaster community that i started in the year 2002 and is now a platform for webmasters around the world. Thankyou for spending your time to visit Blog. I would love to get connected every webmaster reading this, follow me on Twitter and i would auto follow you. Thanks again, Happy Surfing!

Interested to Learn Professional Blogging? Check out my NapIncome Blog where I share all the secrets to build a professional blog and earn money from ProBlogging.

Please Subscribe to the Blog Newsletter to get regular weekly update
Twitter: http://www.twitter.com/orangecopper | Subscribe to feeds : http://feeds.feedburner.com/orangecopper/ilRl

Other OrangeCopper Network Websites

ConnectRing Web Directory | UsedMobiles.in | UsedGadgets.in | NapIncome Strategy Blog | HippieMonk Technology Blog | All Good WordPress Themes | PixelTribes Photography Blog | Yscream Web Hosting

Favorite Articles

  • List Of Best Classifieds Ads Scripts Ever (Free & premium)
  • How to triple your Blog Subscription rates / opt-ins – It Worked for me!
  • You can certainly spend Half a Dollar For creating a GREAT Blog
  • How i earn Big Bucks from my blog Doing Nothing!
  • 35 best free wordpress themes for download: updated list 2010
  • 22 Web 2.0 Colors and their codes in HTML
  • 48+ web Design Related Twitter Accounts To Follow
  • Make a web 2 icon with Photoshop in easy 8 steps
  • List of 62 Free Press Release websites

    Most Rated Articles

  • Compare WordPress – Joomla – Drupal and their features
  • 7 Excellent jQuery menus and jQuery examples and downloads
  • 5 Most Important To Do s for a New Blog Launch
  • How to colorize with adobe Photoshop
  • Free Magento Themes / Templates Download: updated list
  • How to install wordpress step by step tutorial
  • List of 200 Highest paying Adsense Keywords : Updated list 2010
  • How to display Exit Splash or Exit message for website
  • How to promote your old Blog posts