Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

Free sqlmap tool helps ward off SQL injection attacks

DBAs can minimize the risk of injection attacks on their databases with this open source utility designed for Microsoft SQL Server and other systems.

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 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)
Sample output from sqlmap at the default level of verbosity

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.

Dig Deeper on Microsoft SQL Server Tools and Utilities