Threat Level: green Handler on Duty: Bojan Zdrnja

SANS ISC: SQL injection: why can’t we learn? - Internet Security | DShield SANS ISC InfoSec Forums


Sign Up for Free!   Forgot Password?
Log In or Sign Up for Free!
SQL injection: why can’t we learn?

Recently we have been all witnesses of two high profile incidents where the attackers exploited SQL injection vulnerabilities: the now infamous HBGary Federal hack and the Barracuda Networks hack. What’s even more worrying about these two incidents is that they happened to companies which are information security consultants/product developers.

SQL injection vulnerabilities have really been around for ages – the first reference I can remember of was Rain Forest Puppy’s article for Phrack 54 “NT Web Technology Vulnerabilities” that was published back in 1998 (yes – SQL injection is almost 13 years old!). However, as we can see from the examples that happened recently (and from many other cases – just take a look at the mass SQL injection attacks that are performed automatically by malware these days) SQL injection vulnerabilities are unfortunately here to stay.

During my penetration testing engagements I often see various frameworks that are being used to develop web applications. These frameworks are really more and more advanced these days and can in many cases automatically protect the application against common attacks such as SQL Injection or Cross Site Scripting.

While this is good and frameworks definitely help make applications more secure (note that I didn’t say secure), one thing that I always like to stress out to developers that they should still pay attention to all these vulnerabilities. If nothing else, you never know if your application will end up on a server that will have a different or misconfigured version of the framework you used which will suddenly make your application vulnerable!

Another thing to keep in mind is that web application firewalls aren’t almighty. While they can do a good job, I’ve also seen too many misconfigured WAF products that were easy to bypass. The web technology is developing quickly and if you don’t keep up with it, it is quite possible that in 6 months a new attack/language/whatever will be introduced that will allow one to bypass your (old) WAF. Take Adobe Flash for example – not only for client side vulnerabilities – but also for attacks such as Cross Site Flashing that are more and more common.

So are the bad guys any better? Unfortunately, the answer is YES. When I get my hands on, I always try to analyze server side scripts that the bad guys use – these are usually scripts running on their C&C servers that help them control infected machine, issue and schedule tasks and so on.

While previously we were seeing all kinds of bad code (both bad looking and full of vulnerabilities), today I can unfortunately say that the bad guys have much improved their game. Below you can see an excerpt of a server side script used by some malware. It’s in PHP (the most popular platform for bad guys) and besides being nice and easy to read, notice how they nicely used the addslashes() call on all variables to make sure that any occurrence of a single quote, double quote, backslash and NULL byte characters is properly escaped.

PHP code

So, if the bad guys can do it, we should be better to – so please use couple of minutes to educate your developers about the dangers of writing insecure code.

--
Bojan
INFIGO IS

I will be teaching next: Web App Penetration Testing and Ethical Hacking - SANS Prague August 2019

Bojan

379 Posts
ISC Handler
I think the biggest problem with on-line applications today is that data that should not be on the same server often is. Database servers should be connected to the main server by way of an application interface, not a data interface. A data interface should not be possible. That application interface then exchanges well parsed data with the database server. Only basic data should be allowed through the interface, thereby limiting the possible breach if one were to occur. I am also reluctant to use PHP due to the many configuration options that could allow an attacker to gain full control through an application installed by a client. If the more advanced configuration were locked into a secure state at compilation then I would consider using it.
Al of Your Data Center

80 Posts
And yet there is still a "minor" but at least a bug on the BotNet that still allow us to get some SQL Injected on the query... just pay more attetion to the code and its context.

Regards..
PS: Also addslashes is not safe for certain encodings.
Al of Your Data Center
1 Posts
I believe that this, as with most IT issues, is a case of the "Dunning-Kruger effect".

The people writing the vulnerable code do not know enough (but think that they do) to avoid the most basic errors.

But because they THINK that they're good enough, they will not learn more. Any vulnerabilities are blamed on other factors.
Al of Your Data Center
11 Posts
evil will always triumph because good is dumb
Al of Your Data Center
27 Posts

Sign Up for Free or Log In to start participating in the conversation!