Sqlmap: Automatic SQL injection and database takeover tool
sqlmap.org
sqlmap.org
There's a free version, which disables the (mostly vestigial, anyways) "scanner", and slows down the fuzzer tool; if you're really automating security testing --- which, do --- pay for the real version; you want the fuzzer to work.
There are things sqlmap does that Burp does not do easily, but they're not important to app developers; if you're generating database exceptions with inputs, don't dick around trying to make time-based blind SQL work; just fix the bugs.
If you're a talented programming (we especially like talking to people who are good in C, but we're happy to meet anyone) and you're seriously interested in working from Chicago, NYC, or SFBA doing appsec, but don't feel like you have the background, drop me a line. My usual next step for people who I think would be ready to interview with us but for some web app knowledge is to shoot them a copy of that book. Infinite free books is a small perk here.
http://www.schneier.com/blog/archives/2012/07/how_to_become_...
There are links within his blog posting to other tools.
I'm not a fan of Schneier's take on this. Don't start a career in security by thinking about certification.
The cert curriculum can be a great learning tool, in addition to just plain playing around and learning from other social networks.
I am enthusiastic about automation.
The holy grail is to strip away all the tedium from testing, leaving only the mental challenge of finding and exploiting the broken assumptions of our adversary developers.
Burp Suite does a very good job here. sqlmap crosses the line for us. But that doesn't make it a bad tool.
Just my $0.02 here, since I think tptacek has it covered (as usual). The way I explain use of automated tools to our clients is that, yes, the assessment you're paying for is to have a skilled security expert manually assessing your application. That said, in order to get the most efficiency out of manual testing, those parts which can be easily automated should be.
A few trivial examples would be finding open ports, or detecting expired/weak SSL certificates. Sure, an engineer could manually connect to all 65535 ports to see if they're open, and manually grab banners, or he could just run `nmap -p- -sV hostname`. Similarly, he could use openssl to check all aspects of an SSL certificate, but why bother when there are tools to do this for you?
The same is true in application security, although the examples can be a little fuzzier (pun intended?). The more seamless automation can be integrated into testing, the more time for manual analysis can be allotted. I think this is the point that tpatacek was making, and just wanted to expand upon it for those that might be a little confused.
Such as? If you only use PreparedStatment (Java), or the equivalent for your language, and have a rule against, and never broken, to concatenate SQL strings together, you are safe from SQL injection.
There are options available as one or more of the above 3 requirements is dropped: http://stackoverflow.com/questions/149380/dynamic-sorting-wi...
Paging is equally easy, using ROWNUM < X in Oracle or equivalent in other RDBMS.
The order by is a good point. The obvious solution here would be to always have the same sorting as default, and do the user sorting client side (by client here, I mean calling application).
Do you agree that this is a scenario requiring dynamic SQL?
This is somewhat less efficient, but if the alternative is to be open to sqli attacks it'd be my pleasure.
Congratulations, we are no longer relying on bound parameters to prevent SQL injection. THREAD FINISHED! :)
(See another person discussing this here in this thread: http://news.ycombinator.com/item?id=4203929 )
I do not allow the client direct access to the database. They access the database through objects, which have methods that only permit parameterized input.
The client cannot specify the database, table, or columns. That is hard-coded. They can only specify values. Values that are always entered through a prepared statement.
In that scenario, isn't injection impossible?
I've implemented a [complex?] white-listing solution to a problem in a domain where there is a long history of developer mistakes, passing user input to a 3rd-party technology most developers only know the minimum required for their job. Isn't injection impossible?
Edit: Sorry for any confusion; this was my way of saying 'this is only bulletproof if you got every edge case 100% right; few security experts make guarantees of impossibility of failure'.
Also code review, of which there will be need for plenty, when bare minimum developers is involved.
Obviously, you can write simple code to do each of these safely. But then, you can write simple code to handle query parameters too.
By all means, use parameterized queries. Just don't assume they're a magic totem against SQLI.
For example the following example from http://de.php.net/manual/en/sqlite3.prepare.php :
$stmt = $db->prepare('SELECT bar FROM foo WHERE id=:id');
$stmt->bindValue(':id', 1, SQLITE3_INTEGER);
$stmt = $db->prepare('SELECT bar FROM foo
LIMIT :offset, :count');
...
You can't do that. You can only bind data to fields. $stmt = $db->prepare('SELECT bar FROM foo
ORDER BY :column :direction');
$stmt->bindValue(':column', 'foo');
$stmt->bindValue(':direction', 'DESC');
You can't do that either, because again, it's not data.So, you end up having to do something similar to this (for the love of god, don't actually do this):
$stmt->prepare("SELECT bar FROM foo WHERE id = :id
ORDER BY {$column} {$direction}
LIMIT {$offset}, {$count}");
Bound parameters won't save you, and the potential attack vector is there if you're not really careful. That example shows the most stupid thing you could ever do, so don't do it.Even if the DB interface doesn't directly support this, it seems like it's something all client wrappers should handle, preferably at the low level in addition to having to pull in a whole ORM + assorted bacon for the purpose.
That would not have been a "real" prepared statement in my mindset so I get why I was confused.
I don't feel super smart, but wouldn't I simply make sure that $column is a valid column (ok, that one might need extra attention) and $direction would be either ASC or DESC and that $offset and $count are integers?
The lexical structure of the statement and the parameters themselves are two different things. You are correct that "parameterization can't save you from SQL injection", if you're such a bad programmer that you're feeding user input directly to produce lexical tokens. One example is a recent blog post talking about how to escape table names for apps that feed things like "customer_name" to serve as the table name (totally insane). Your example of feeding in "sort=xyz" to produce the column name in the ORDER BY is also a pretty awful practice - I haven't seen that one in like a decade, but sure.
So of course parameterization doesn't magically protect a system against all forms of attack - the programmer could be feeding user input directly into shell commands too. The recommendation for parameterization is addressing the bulk of the issue at least among the code that I regularly work with, maybe you deal with crappier programmers than I do on a regular basis.
This still happens every day. Google how to do dynamic sorting and you'll find a hundred examples of it in PHP, and as unfortunate as it is, that's how a significant portion of code is authored.
The better answer is a parameterized query, which actually controls the inputs properly to ensure that no dynamic SQL is possible.
SELECT sp_enroll("bob\"); DROP TABLE students; --");
or SELECT sp_enroll("bob"); DROP TABLE students; --");
?At least if you grant the user only SELECT and EXECUTE privileges and define the procedures using the SECURITY DEFINER property, you could still prevent this type of damage. (This relies on the procedures to be as strict as possible or the whole scheme essentially fails.)
If, however, simply demonstrating that SQLi is there is not sufficient, or if the blind SQLi is too ephemeral sounding to the client, Sqlmap can help you dump the entire database. This will convince even the most skeptical.
I like the code for Skipfish a lot, but neither tool is particularly important in the profession; if you're working with a contract application security firm and they give you findings that came from sqlmap or Skipfish, you should be irritated.
The latter I agree with, the former I don't. Any automated security scanner has its shortcomings - combining the results of various scanner products generally has a positive effect upon the quality of the test. I've often been in a situation where one tool (commercial or otherwise) indicated or hinted at a vulnerability while all other tools (commercial or otherwise) used did not indicate anything.
But even practices that do use automated scanners won't be relying on Skipfish or sqlmap.
This obviously doesn't hold for network pentesters. For tests in which application flaws aren't the whole story, and you're just looking for the fastest way in you can find, sure; sqlmap is valuable there, much more so than Skipfish. We don't do those kinds of tests often.
I find myself writing a lot of custom fuzzers in python, and am looking to improve my toolkit.
Another faction of our team uses Mike Tracy's WWMD toolkit, which does some of what Burp does but from an irb prompt.
I'm allergic to both approaches and tend to just start from EventMachine and ev-http-request.
Good example of the kind of scenario that'll get me into "writing code to test web apps" mode: testing those goofy cryptographic tokens applications send via email to reset passwords.
Yes: the better approach is to have the token be a 256 bit cryptographically strong random number that corresponds to a row in the database with metadata sufficient to expire the token and invalidate it on password reset.
Have you looked into Haskell's QuickCheck? It's essentially a fuzzer for unit testing. You might find some interesting ideas there.
What it seems like you're saying is that you have found that scanners are almost always a distraction at best, misleading at worst, and that they offer zero useful information about the app or about the MO of the app developer.
You (matasano) are good enough that any information those scanners could reveal about the app or the developer, you'd probably turn up independently. Not everyone has those skills, and the results of a scan might include something that a lesser practitioner wouldn't have noticed any other way.
I'm not against automation. I don't think testers need to launch every fiddley little query they need to gauge behavior. What I'm against are tools that run some unspecified number of fiddley little queries, do some bogus analysis, and then spit out a "YES XSS" or "NO XSS" answer.
but I'm going through the exercise of building out an app sec practice, and for what it's worth, I've adopted the same approach (we're not using automated scanners).
I work in an AppSec practice. Scanners help me find the low hanging fruit. I can now spend more time looking for logic bugs.
Reasonable people can disagree on this point, but we're a pretty large, well-established practice and our belief isn't coming out of nowhere.
Your argument is literally the first thing anyone who wants to convince us to use scanners brings up. It is the point we've thought about and debated most. I just don't think it pans out in the real world:
(1) The bugs you find "because" your scanner took the low-hanging fruit will be bugs any good tester will find;
(2) meanwhile, the extra scrutiny you're not giving the app to find that low-hanging fruit is costing you insight that would reveal still more bugs...
(3) also, your scanner is missing bugs, probably in the neighborhood of 20-30%, and:
(4) you're not making up for that because it's very difficult to force yourself to focus on terrain that a scanner has covered and flagged bugs in.
I am not as philosophically opposed to scanners as I think Thomas is, I've just found that they provide nearly no useful value. For many years, I argued that although they provided no value, "they didn't hurt", so there was no harm in also running them at the end of a test to make sure there aren't any low-hanging fruit that a tester may have missed.
What started to turn me around in that belief was that I noticed an increasing number of tests being performed by my team where the scanner wasn't just not providing value, but actually causing issues.
Under the best case scenario, you are now having to take the time to validate your scanner findings (which are all things you would/should have found anyway but are relying on the scanner to do for you).
Under the scenarios I've witnessed play out, people assume that the scanners will actually find the low-hanging fruit, and they slack off on that part of the assessment (because, hey, the scanner will cover it, and now they can spend more time looking for logic bugs). Then the scanner doesn't find something trivial (which happens about one in every...oh, I don't know...actually it happens in nearly every test).
I'm happy you've found that scanners don't make your work product worse, but that's not what I've found at all.
EDIT: Furthermore, how embarrassing would it be if someone hired you and then ran one of these scanners themselves and did find something you missed? Given the magnitude of the potential downside, and the marginal cost of using them as described, it'd almost be more of a business insurance tactic than anything else.
Last point first:
Try real hard not to miss stuff. Seriously, that's it. Appsec is a competitive field. Forget scanners: many clients are going to hire a different firm for their next test, and some of those firms are really, really good. When you're testing an app, that is the thing that is animating your work: trying not to leave nuggets for the next team to find and shame you with. Think we're worried about missing things sqlmap finds? Try worrying about what iSec Partners is going to find.
To your first point: this is hard to articulate well, but let me take a stab at it: it's very hard to double back over terrain a scanner has already covered. Think of security testing like a treasure hunt. Have you ever had a fun treasure hunt? Can you get a bead on the feeling you had when you started out hunting for stuff? Imagine trying to put the same focus and motivation together if, before the treasure hunt, the organizers announced "we sent a bunch of people out before you to try to make sure there's no treasure".