Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

Create Account  |  Retrieve Password

How Prevalent Are SQL Injection Vulnerabilities?

Posted by kdawson on Thu Oct 05, 2006 11:33 AM
from the more-than-you-think dept.
Krishna Dagli writes to tell us of an investigation, by Michael Sutton, attempting to get an estimate of how widespread SQL-injection vulnerabilities are among Web sites. Sutton made clever use of the Google API to turn up candidate vulnerable sites. You might quibble with his methodology (some posters on the blog site do), but he found that around 11% of sites are potentially vulnerable to SQL injection attacks. He believes the causes for this somewhat alarming situation include development texts that teach programmers insecure SQL syntax, and point-and-click tools that allow the untrained to put up database-backed sites.
+ -
story

Related Stories

[+] Developers: Malicious Injection — It's Not Just For SQL Anymore 119 comments
nywanna writes "When most people think of malicious injection, they think of SQL injection. The fact is, if you are using XML documents or an LDAP directory, you are just as vulnerable to a malicious injection as you would be using SQL. Bryan Sullivan looks at the different types of malicious code injections and examines the very basics of preventing these injections."
This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More
Loading... please wait.
  • by Reality Master 201 (578873) on Thursday October 05 2006, @11:38AM (#16323417) Journal
    destroys thousands of lives a year. Sure, it starts small - a SELECT there, a few INSERTS on the weekend. Eventually, though, you're using stored procedures and trying to score triggers in the middle of the night.

    Just say no, kids.
  • by charleste (537078) on Thursday October 05 2006, @11:42AM (#16323485)
    This is a possibility that was obvious back when I was developing web applications as far back as 1996 using CGI. The approach in TFA was a similar approach we used "back when" to demonstrate the need for (a) not using GET, (b) turning off verbose error reporting, (c) controlling *how* queries were made (e.g. architecture of the app and DB I/O), and (d) storing sensitive data encrypted. The sad part is that it is *still* a problem. I guess it underscores the need for a decent architect as opposed to letting whiz-bang do-it-yourselfers start coding without design, and the need for security analysis, et. Al. Just my 2 cents.
    • by CastrTroy (595695) on Thursday October 05 2006, @11:48AM (#16323585) Homepage
      How does not using GET stop anything, you can POST anything you want to a webserver just like you can GET anything you want from a webserver. Only using POST will make things a little harder, but it doesn't stop anything.
      • Re: (Score:3, Insightful)

        Using POST doesn't make it any harder. It just makes the address bar less ugly.

        IMHO, any web application should be written to accept both GET and POST. I'm very annoyed with USPS.com for this very reason. I have a small Dashboard widget that I use to track packages. Short of writing some custom redirect script on a server somewhere, I cannot construct a URL that I can use to create a clickable link to the tracking results.

        I sent an email to the USPS webmaster and asked if there was anything they cou

        • So you write a widgit that creates a request object and POSTs it to the server. It's the same info being sent, it's just how it's viewed in the addressbar.
        • by Ford Prefect (8777) on Thursday October 05 2006, @01:57PM (#16325777) Homepage
          IMHO, any web application should be written to accept both GET and POST.

          No. Web applications should use GET and POST where appropriate - GET for idempotent requests (showing database records, search results, those kind of recurring, non-database-changing things) while POST should be used for things which actually change data, user state, and so on.

          Using GET in the wrong places [slashdot.org] can lead to all kinds of irritations and miniature security problems. Imagine sending an email to your web application administrator containing something like the following: <img src="http://example.com/webapp/user_admin?action=e dituser&username=me&accesslevel=administrator" width="0" height="0">...

          Many web applications do get the two horrendously mixed up (I've seen search results done via POST, which is subtly, incredibly annoying) but they're definitely not interchangeable.

          For simply displaying a non-password-protected package shipment page, GET would probably be the best solution. But blindly accepting both isn't a good alternative.
          • Re: (Score:3, Insightful)

            GET for idempotent requests (showing database records, search results, those kind of recurring, non-database-changing things) while POST should be used for things which actually change data, user state, and so on.

            You are confusing idempotence and safety. "Idempotent" merely means that repeated requests have the same effect as a single request. You should use GET because it is safe, not because it is idempotent. For contrast, DELETE is an idempotent method, but it's certainly not a safe method. For

            • Re: (Score:3, Informative)


              "SELECT `userID`,`user`, `password` FROM `table` WHERE `user` = 'trim($_POST['user'])'"


              Ack! Nice demonstration of the code that is vulnerable to attacks!

              My user id is '; drop database; --
                • Re: (Score:3, Informative)

                  I hope not, since mysql_escape_string() will also allow for SQL injection by not respecting the character set of the MySQL connection. The PHP Group, in all its brilliance, decided to add another function, which they named mysql_real_escape_string(), rather than simply fixing the first one. /me sighs
    • How do a) and b) help?

      Which "decent architect" designs a system where verbose error logs are sent to untrusted public users.

      And which "decent architect" writes web apps where GET would inherently causes security problems.

      In fact, post causes more problems if the target page doesn't issue a redirect, because then the form could be reposted. This shouldn't be a security problem of course (unless it's a login page), since duplicate posts should be handled gracefully. However with most browsers, users would be
    • the need for (a) not using GET

      WTF? GET has uses just as POST has uses. If a request is to be idempotent (read-only query), then it's a GET. Otherwise it's a POST (or a PUT, or a DELETE).

      The fact that PHP fails at understanding HTTP doesn't mean that others do so too. For example, the web.py Python microframework behaves this way: you map URLs to classes, and these classes have any of 4 methods: GET, POST, PUT, DELETE (they can have others, but the others are not important). Each method is called when th

  • Simple solution (Score:5, Insightful)

    by CastrTroy (595695) on Thursday October 05 2006, @11:44AM (#16323523) Homepage
    The simple solution is to use parameterized queries. I don't know why more books don't know why more books don't push this methodology, as it makes you program faster, easier to read, and also makes you invulnerable to SQL injection attacks.
    • Indeed, the last few project I have done use COMPLETELY parameterized queries. The only time the SQL statement structure for a command is remotely dynamically built is to add additional caluses based on specific criteria and allows no user-generated input to actually build the clause specifics. With these practices, we have absolutely *NO* SQL injection vunerabilities.

      The other side of the coin, that people still forget about, also, is data that is queried and made for display in HTML browsers. Without
  • The fact that tools can be used to put up insecure sites is not exactly a failing of the tool. The tool will have had a spec (even an informal spec) - which may have been "put sites up fast and let users sort out the security".

    It's only a failure of the tool, or the developer of the tool, if the tool is marked as being a one step solution. Of course a lot are, there is no shortage of snake oil salesmen, and in that case they take 100% of the blame. However most rapid deployment tools contain a clear disc
  • by Realistic_Dragon (655151) on Thursday October 05 2006, @12:02PM (#16323821) Homepage
    There should be some kind of government run website somewhere.

    You would answer questions and it would give you license keys to software that you were qualified to use. For example, I might tick:

    Engineer (check)
    Artist ( )
    Manager (check)
    Linux (Check)
    Mac ( )
    Windows ( )

    And it would issue keys for website point and click installation software, Vi, apache and Latex - but deny me keys to powerpoint thereby saving the lives of people who might otherwise have to gnaw off their own leg to survive my 8 hour presentation on optimising synergisyms in a web 3.0 environment by sub molecular interactions.
  • testing methods (Score:4, Insightful)

    by Akatosh (80189) on Thursday October 05 2006, @12:03PM (#16323841) Homepage
    This 11% was determine by a weak testing mechanism. For every site that baltently spews sql errors to the user there are two that silently return a generic sanitized error, and another two that return no error at all. It would produce more results if you take it a step further and ask yes no questions, such as:

    ?id=99999' OR '10

    and see if the page returns the results of id=10 as expected. It's also common for people to use weak regexp (regexp should NEVER be used to protect against sql injection, see mysql_real_escape_string) and miss some characters:

    ?id=99999)

    or fail to sanitize non us language encoding. Also, get variables are often the most protected. It is much more common to find sql injection in <input type=hidden variables, or in cookie data. The number 11% is extremely low. I'd guess more like 80%.
    • Depends on how you use a regexp. If you're defining the characters that are allowed in the user input, that's one thing. If you're defining the characters that aren't allowed in the user input, then you might as well not have wasted your time.
  • From the article:

    * Many development texts actually teach programmers insecure SQL syntax. ...
    * Many sites are exposed to SQL injection attacks but don't know it.

    I agree completely! I've seen the texts, I've seen the hordes of VB+SQL programmers that learned from said texts moving to the web porting the same "vices" to the new platform.
    And I've seen the "oh-sh*t" face on a couple of developers after demonstrating to them that their software is vulnerable to SQL Injection. In both cases the vulnerabilities e
    • by valloned (1009727) on Thursday October 05 2006, @12:14PM (#16324025)
      Microsoft VB.NET and ASP.NET texts are AWFUL in this regard. Nearly all examples use in-line SQL queries rather than paramaterized stored procedures. Why? Probably because they are trying to fit in with Microsoft's strategy that devoping applications should require absolutely no knowledge of code (or anything else for that matter). The big selling point for their VS 2005 suite is "no code required". That speaks volume.
    • by jrockway (229604) * <jon-nospam@jrock.us> on Thursday October 05 2006, @12:19PM (#16324113) Homepage Journal
      > Writing secure software is never easy.

      It's easy if you use good tools. PHP is not a good tool. Rather than hacks like mysql_replace_the_string_with_things_that_wont_com primise_my_database(), you should be using tools that make it impossible to inject SQL.

      Some ideas:

      Perl's DBI, whose docs tell you to ALWAYS write SQL like:

      $sth = $dbh->preprare('SELECT foo,bar FROM baz WHERE something=? AND another = ?')
      $sth->execute(q{''Some\ things"'}, 10);

      Notice that the programmer can't forget to escape the SQL -- because there's no escaping.

      Even better is something like DBIx::Class, which lets you write

      $resultset = $table->search({something => q{''Some\ things"'}, another => 10});

      Again, no opportunity for the programmer to fuck up the SQL in any way. It's just like getting data out of the hash... DBIx::Class will generate the SQL (for any backend), run the query, stream in the results as needed, etc. It's easier and it's better!

      Ruby on Rail's ActiveRecord is similar, but it's impossible to do certain types of joins. DBIx::Class is better in this regard. (And Perl is faster than Rails, and Catalyst is more complete rhan Rails :)... but both Ruby and Perl are MUCH better choices than PHP.

      PHP makes it easy to write insecure code. Perl makes it hard! (With taint mode, a selection of ORMs, 10000+ well-tested modules, and nicities like Moose, Moose::Autobox, etc.)
      • Re: (Score:3, Insightful)

        Or use the appropriate PEAR classes with php, like MDB2, which documents how to do prepare/executes. Don't suggest that PHP is worse than PERL because PERL has DBI, PHP has addons as well.
        • Re: (Score:3, Informative)

          Prepared statements aren't there to guarantee that every datum you insert is the "correct" type for what you're trying to do. What they do is guarantee that nothing in your variables will be interpreted as part of the SQL command.

          If I have "10; <naughty stuff>" in $numeric_var, it will attempt to insert (or select, or whatever) exactly that string, without interpreting it. The data may be useless, but it will not be executed.

    • Re: (Score:3, Interesting)

      And I've seen the "oh-sh*t" face on a couple of developers after demonstrating to them that their software is vulnerable to SQL Injection. In both cases the vulnerabilities exposed the customers to the posibility of serious financial damage.

      Have you seen the 'oh, that's not a problem, we're using SSL so it's completely secure' face yet?

      As for stupidest work-arounds - a site I was doing a vague security audit for (sans source-code, alas) was (is) rife with SQL injection vulnerabilities. On attempting to expl
  • by shawnmchorse (442605) on Thursday October 05 2006, @12:10PM (#16323973) Homepage
    If anything, I'd question how FEW sites they claim are vulnerable to SQL injection. It's an insidious problem that just creeps up on you anytime you don't think about it sufficiently (as when writing something quickly, on a deadline... not that this ever happens!). I know that at my workplace we fell victim at one point to a SQL injection attack on one of our (many) custom PHP scripts. We eventually found out how it worked through the web logs and were able to fix it, but honestly even after we did our best to clean things up... I'm dead certain that there are still probably hundreds of places that we're still vulnerable. This is due to a number things including the sheer volume of PHP code in use, the fact that the code has been written at various points in time over a period of six years or so, and the fact that this code has been written by at least twenty different people. It's like trying to plug holes in a dam.
  • by Bryansix (761547) on Thursday October 05 2006, @12:23PM (#16324175) Homepage
    Why are the point and click or turn key solutions so vulnerable to SQL injection in the first place? I had a friend with a PHPBB site that got shot to all hell when some cracker came along and defaced it. Why wasn't it secure out of the box? Second of all, why is it that every website has to worry so much about security. I know about databases but I don't know the first thing about preventing an SQL injection attack and why should I have to. There is nothing sensative on my sites. Let me throw out this analogy.

    Let's say I own a house and around Christmas time I put out an inflatable snow man. Then some vandals come along and pop it. Are you going to walk up to me while I'm sulking over my snow man and say "Don't you know you have to wrap your snow man in kevlar to prevent vandalism and then put up an electified fence with constantine wire on it."? I would give you the strangest look if you did. Then I'd probably say something pertaining to the fact that the police should catch these bastards and presecute them.

    So why is it with technology that no emphasis is put on catching vandals and bringing them to justice and a ton of emphasis is put on protecting your site from attack?
  • I've worked in web development a while and I find a SQL injection vulnerability in about 90% of the sites I've seen.

    It is extremely common to have people just cut and paste the bare-bones tutorial code they find on the web and reuse that same pattern on every page in the site rather than centralizing it in a wrapper. So not only is the string not being cleaned, but it's also a huge pain to fix.
  • by thewils (463314) on Thursday October 05 2006, @02:03PM (#16325877) Journal
    If you search for "mdb" you can download the entire database without too much trouble.

    I recently came across a commercial site where you could substitute, for instance, "(select first_name from users where id=1)" into the page url and a nice error screen came up telling you that it couldn't convert "George" into an Integer.

    It's not the SQL Injection per se that is the biggest problem, but the nice error messages you get back giving you, more or less, a SQL command line interface. Errors should be detected and redirected to a sanitized page, or if you can't be bothered, an unceremonious crash.

    I notified the owners of that site by the way.
    • This is exactly why I use NanoBlogger.
    • by ip_vjl (410654) on Thursday October 05 2006, @11:53AM (#16323677) Homepage
      Won't work. The same 'novices' who leave gaping SQL injection holes will now be writing pages that need to access the file system. Now instead of accessing the DB, script kiddies will be traversing the filesystem. Yes, this can be mitigated through file permissions, but there are a lot of servers out there (set up by these same novices) where processes run as root and would have full access to read and write files. So, a bad script could allow them to write to /etc/passwd and have all sorts of fun.
    • Stupid application construction isn't a good reason to make the design of the app even stupider.

      In the old days, everyone used flat files, because that's what there was. Then someone (several someones, most notably Codd and some others at IBM) realized that breaking the flat data into sets of discrete data that related to each other reduced redundancy and allowed for an overall better quality of data. And it wasn't app specific.

      The answer to SQL injection is to test apps more completely (including tests f
      • Absolutely. Here are some rules to defend at multiple layers against SQL injections (using SQL Server as an example; YMMV on other DB servers):

        - Run your web application as a user that connects to the database server and has rights only to SPs and views on the database; this works because the SPs and views have full access to database data, but the user can't access the data except through those pre-defined means

        - Encapsulate calls to those SPs and views inside carefully constructed functions/objects/etc.
        • For a blog with 15,000 entries and 5MB of data, use Blogger or Typepad.

          And, frankly, I don't think learning how to use the tools properly and how to test one's code is "overengineering." I think of it as competently programming the application. But I'm old fashioned.
    • by RingDev (879105) on Thursday October 05 2006, @11:55AM (#16323717) Homepage Journal
      Why convert to an entirely different structure when just implimenting proper code standards will suffice? Using parameterized stored procedure calls instead of dynamic SQL will not only protect you from the vast majority of SQL Injection attacks, but will also improve the performance of your web page.

      -Rick
    • There's no need to go back to the stone age. Just use prepared statements/parameterized queries (along with the usual stuff like validating user input client *AND* server-side)
    • If the obvious fix is to exclude special characters from password fields, then why allow them by default to begin with?

      Because that won't stop a wily hacker from using a tool such as curl to use those special characters as if they'd entered them in the password field. This has to be fixed at the server end, not the client end.

      • by tuffy (10202) on Thursday October 05 2006, @11:57AM (#16323739) Homepage Journal
        In short, trusting the client (i.e. the web browser) to not send bad values - either through the INPUT tag's maxlength attribute, JavaScript scrubbing or whatever - is entirely the wrong way to go. The web script must check all user input for validity along with properly escaping everything from the database that's getting sent back via HTML.
      • That's a valid point, but doesn't contradict mine. If the server, by default, doesn't accept special characters in a password field, then that fixes most of these problems. Obviously, the password field isn't the only place where you can muck with the SQL, but if you're getting malformed fields from a valid userid and password, then you are much further along the path to shutting out the problem user who misused or had his access compromised. Cheers.
        • If the server, by default, doesn't accept special characters in a password field, then that fixes most of these problems.

          But then you couldn't make good passwords. Also, the password field isn't the only... oh wait, you said that:

          Obviously, the password field isn't the only place where you can muck with the SQL

          Exactly. So maybe you can't write "O'Hare" as a password, but with your method you couldn't enter it as your name. You just can't disallow special characters as a generic solution.

          but if you're gettin
    • I don't think you understand SQL Injection at all.

      If the obvious fix is to exclude special characters from password fields

      It's not. First of all, it wouldn't work. Second, it makes to sense at all at any level. Sorry if I seem rude. :)

      There are a lot of new programmers (or whatever we're calling people who make websites these days), who are not naturally paranoid and sensitive to the exploitation of their code. They shouldn't need to be.

      I agree, but it's a dreamworld. I shouldn't need to fiddle with keys or
      • No worries. First, let me say IANAWD (I am not a web developer). It would not surprise me at all if my understanding of SQL injection vulnerabilities is less than yours. My understanding is that a SQL injection vulnerablity is when a user submits input to an interpreter that subverts the original intent of the script and produces a different result. I.E. I enter ' or '' = '' as the password field and that is passed through to SQL interpreter to read "where userid = 'user' and password = '' or '' = ''"
    • Re: (Score:2, Insightful)

      As some others have pointed out, there are tools to get around that sort of thing. You should be validating all input server side, whether it's validated client side or not. There are also very easy ways to deal with SQL injection already, such as parameterized stored procedures. Doing what you suggest would involve a hell of a lot of recoding, break a hell of a lot of existing sites, and proceed to punish good coders by making them work around the "safe-guard". Programmers who don't take steps to protect a
    • This is kind of like saying we can prevent buffer overflow exploits by having the windows API not allow people to enter shellcode into textboxes.

    • Re: (Score:3, Insightful)

      All the HTML standards in the world won't stop an attacker with a copy of telnet.

      bash$ telnet example.com 80
      GET /vulnerable_app.php?id=%2310 HTTP/1.1

      Two things to note here: (1) there's no HTML involved in the actual transaction at all (2) like another poster said: you can't trust the client to send valid data.

      Stick to purposing solutions for things you know about.
      • Alright, back to my PHB duties, but if we only proposed solutions for things we know about, then we'd all still be picking termites out of logs with twigs. I still hold to my fundamental belief that some things are meant for professionals, ie installing ATM machines, and some things are meant for everyone, ie posting websites, and the level of safeguards has to take that into account. Some people may feel that the web should belong to the trained professionals, but personally, I'd rather see a lot of crap
        • There's nothing wrong with the Joe Sixpack building his own website. The web wouldn't be what it is today, if it weren't for that. However, there is a problem with him developing software on systems open to the world.

          Once you add executable code, and a database, it's not 'just a website' anymore. It's a program. And running amateurs' programs on the open internet is dangerous.
        • ATM = Automatic Teller Machines

          "ATM machines" = Automatic Teller Machines Machines - definitley leave it to the pros, otherwise you may screw up on your "PIN number"

          (Apologies for being a pseudo-grammar Nazi)
    • IRL crimes have physical evidence and eye witnesses and still most people get away with it.

      Considering somebody can break into your site from any one of a million unsecured WiFis from New York to Bangkok, i'd say prosecution is not going to be an effective method of deterrance.