Tip

Free sqlmap tool helps ward off SQL injection attacks

SQL injection attacks are the bane of most admins responsible for databases that power Internet-facing sites. All it takes is one publicly-exposed page that doesn’t have its inputs sanitized and

    Requires Free Membership to View

you can end up with a trashed database.

I’d like to think I don’t speak out of uninformed alarmism, since I’ve had a few such disasters

come my way. Each time, I was grateful for being in the habit of making daily backups of everything -- but one such incident alone was enough to convince me that I needed to do a better job of policing the way even the most trivial pages processed input from the Web.

One tool I’ve used to determine the vulnerability of a given site to SQL injection attacks is sqlmap, an open source command-line tool that can detect injection attacks on a wide variety of database systems, including Microsoft SQL Server. It’s been written in Python, so it can run on any platform that supports it, but Windows users can download a self-contained executable that doesn’t need a full installation of Python to run.

Running sqlmap requires that you provide it with at least one parameter -- the URL that you want to test for SQL injection. This needs to be a URL with at least one parameter in it; barring that, you can also test for manually-supplied GET/POST parameters, an HTTP cookie or user-agent string. The range of options available is quite broad, so it’s probably a good idea to read through the documentation and to get a good idea of exactly what you can test for and how.

Note: Since many pages process user-agent strings for the sake of determining, for instance, whether or not to load the low-bandwidth version of a site, the user-agent has become an attack vector all by itself.

Again, the most basic way to use the sqlmap program is to pass it a URL with some parameters already embedded in it. Once this is done, sqlmap will attempt to use each of those parameters as an attack vector for a variety of injection techniques. It will then report back the results for each parameter on a status line prefixed with “[WARNING]”. The results can be pretty verbose, so you can use the –v switch to control the level of verbosity (use –v 0 for the most minimal report). It’s also possible to test against a list of URLs provided in a file or even “Google dork” pages exposed through Google searches of your site that inadvertently reveal vulnerabilities as well.

One of the sqlmap program’s best features is the ability to craft tests based on the kind of database you’re using and the operating system hosting it. With SQL Server, for instance, there are tests to determine if the underlying system can have arbitrary shellcode executed and Windows Registry hives mounted, added or deleted. These are all attacks that have proof-of-concept code or some variety of in-the-wild attack already staged, so we are not talking about hypotheticals.

The sqlmap program has been released as a GPLv2 project, so you can redistribute it freely or modify it for your own use under the terms of the license.

Figure 1. Sample output from sqlmap at the default level of verbosity.  (click to enlarge)

ABOUT THE AUTHOR
Serdar Yegulalp
has been writing about computers and information technology for more than 15 years for a variety of publications, including InformationWeek and Windows Magazine.

This was first published in June 2010

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.