As you all know, Hiawatha has the ability to detect and block SQL injection attacks. It does so by matching user input with several regular expression patterns, which can be found at the top of src/session.c. I've always said that there is no 100% guarantee that all SQL injections are detected, hoping that someone would pick up the challenge and provide me with SQL injections that would bypass Hiawatha's filter. Unfortunately, no one did.
For the 9.7 release, I want to further improve Hiawatha's SQL injection detection capability. I've already made some improvements. Not only to the patterns itself, but to the entire approach. I've already seen that the filter can easily be bypassed by using the /* */ comment syntax, so those are stripped first. What I need is someone with good knowledge of SQL injection and regular expressions to pick up the challenge to provide me with a set of regular expressions that block SQL injections without false positives.
To make this all more easy, I've created a PreventSQLi test page. What this page does is strip the /* */ style comments, match it with the detection patterns and if no match was found, execute the query in a sandbox.
If you have good hacking skills or you know someone who does, please help to make Hiawatha an even more secure webserver.
Update:
To be clear, the PreventSQLi feature was never intended as a replacement for writing safe code. It's only purpose is to reduce the risk of being hacked while you wait for a patch for a vulnerable application when taking the application offline is not a real option. Nothing more than that.
https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet for 2013 top 1 prio Injection.
t is very hard to create a list of SQLi pattern as the SQLi is depending on the web application vulnerability and web server configuration.
However, it is worth to study the mod_security rules set at https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project and http://www.atomicorp.com/wiki/index.php/Atomic_ModSecurity_Rules. Most hardened Apache web server will use this set of rules.
mod_security is not perfect too. You can take a look in it for reference.
There are some papers for SQLi and Obfuscate, such as http://www.exploit-db.com/papers/17934/, http://code.google.com/p/teenage-mutant-ninja-turtles/wiki/AdvancedObfuscation, http://code.google.com/p/teenage-mutant-ninja-turtles/wiki/BasicObfuscation.
I just named some here.
Thanks for your works!
This post is not new, I know, apologies for the late reply.
A very simple SQLi string that should be catched by pattern #3 actually succeeds. The string and a pattern that catches it (not sure if the change is okay!) are given below:
blah' or 'x'='x
'\s*(and|or|xor|&&|\|\|)\s*('|[0-9]|`?[a-z\._-]+`?\s*=|[a-z]+\s*\()
one of Tiki Wiki devs sent me the following email today:
Subject: Would Hiawatha have protected against DRUPAL-SA-CORE-2014-005 ?
Hi!
Ref:
http://www.bbc.com/news/technology-29846539
https://www.hiawatha-webserver.org/weblog/70
What is the answer?
with this username filed sql injection has been bypassed
username fild : ' group by ExtractValue(1,(if(1=1,1,@@version))) #
1=1 is condition
and
group by ExtractValue(1,(if(substring(version(),1,1)=5,1,@@version)))#
please patched it !!!!!
thanks for your project !!!
The symbol ` in your Patterns regular expression really confuses me. Could you explain it?
I get a array of Query result, when I input '--'. Is it a injection omitted?
Thanks for the '--'. A block for it will be included in the next release.