Application Security // Database Security
11/15/2012
12:32 AM
50%
50%

The Root Of All Database Security Evils = Input

Input validation and prepared SQL statements crucial to preventing SQL injection attacks

Some of the most embarrassing database breaches of the past few years boil down to one big root cause: poor input validation and sanitization imposed by developers who create Web applications that tap into these data stores. In the rush to get code compiled and out the door, developers create input fields that allow users to type in anything they want. That's fine for most users who just need to type in their usernames, a search term, or an address and phone number. But when the bad guys get their hooks into these unchecked input fields, they're one step closer to hacking the database.

"User input is the root of all evil," says Trevor Hawthorn, CTO for security consultancy Stratum Security. "Ultimately, user input in some way, shape, or form makes its way to the database, and so where that could spell trouble is if a user submits input to a Web application that is then interpreted by the database as database commands rather than what it is -- user input."

[Hackers fixate on SQL injections--CSOs, not so much. See The SQL Injection Disconnection.]

According to Hawthorn, SQL injection is the "800-pound gorilla" when it comes to input-related problems.

As Bill Karwin, principal consultant for Percona, explains, this most-widespread security risk on the Internet is essentially a coding gaffe where the developer "interpolates untested content into SQL queries," giving malicious users the tools to type SQL queries into input fields to directly interact with the database without the application ever acting as a filter.

"Developers should make sure their code never executes user input as code," Karwin warns.

Here's why: With that kind of power in the hands of a knowledgeable attacker or even an unknowledgeable one using an automated SQL injection attack tool like Havij, any outside user can input commands that will allow them to retrieve data from the database or add content to a database. This opens up the possibility not only of theft, but also adding malware into a database that powers a website so that it is serving up malicious content to users, or even adding content to something like a story on a news website, Hawthorn says.

For example, one client that his company serviced ran into a situation where a public policy organization had messaging on its site that was diametrically opposed to its policy positions.

"They were essentially lobbying against themselves, and nobody noticed it for quite a while," he says. "That was a case where it was a SQL injection vulnerability that allowed someone to make just a couple of crucial changes."

Experts agree that a big reason why so many SQL injection vulnerabilities remain out there in the wild is because developers only assume their users will type inputs with good intentions.

"From a security professional's perspective, a good programmer will sanitize all data sent to the server, aggressively fuzz their input fields, and constantly patch their components," says Dylan Evans, vice president of operations for Reveal Digital Forensics and Security. "However, from the programmer's perspective, these concerns may not reach a high priority. The vast majority of Web programmers are familiar with SQL injection -- and its sibling, cross-site scripting -- on a conceptual level. However, understanding why something is dangerous and actively preparing for that danger are two different issues."

Part of that preparation is to not only test and plan for typical use cases, but also those atypical abuse cases. It's the only way that organizations will be able to effectively stamp out SQLi attacks like the one that hit Adobe this week, experts say.

"If you filter user inputs to only respond to known queries, you are golden, but too many Web applications trust the unknown user's input," says Mark Goudie, managing principal for the RISK Team at Verizon Enterprise Solutions. "Bad people do bad things with user input and [then] they can access all of your database."

First and foremost, Hawthorn says, developers need to be aware of how data comes into their application.

"Understand where your inputs are, how people could abuse them, and what would happen if things were to go seriously wrong," he says, explaining that one of the biggest best practices developers should strive to implement is whitelisting input as much as possible.

"Whitelist the types of content you are expecting for a given input," he says.

So, for example, a phone number input box shouldn't accept letters or apostrophes. Hawthorn says he understands that, in many cases, this may not always be feasible, particularly as more sites are built with social features that allow for greater freeform user input functionality. In these cases, developers should seek to use prepared SQL statements so that user input is never entered into the database as code.

"So if I enter my username as ' or 1=1, what the application should do is reach back into the database and say, 'Do I have a user name ' or 1=1 ?' So what it should do is look in the database for literally the characters that were put in," he says. "That's a good way to solve most of your input validation-based database challenges."

Have a comment on this story? Please click "Add Your Comment" below. If you'd like to contact Dark Reading's editors directly, send us a message.

Comment  | 
Print  | 
More Insights
Comments
Newest First  |  Oldest First  |  Threaded View
matcohen
50%
50%
matcohen,
User Rank: Apprentice
11/21/2012 | 12:15:45 AM
re: The Root Of All Database Security Evils = Input
It's sad that years after the SQL and
Blind SQL Injection attacks were crated, so many web applciations are
still vulnerable.

Best,

Matthew Cohen

www.ntobjectives.com

Register for Dark Reading Newsletters
White Papers
Cartoon
Current Issue
Dark Reading December Tech Digest
Experts weigh in on the pros and cons of end-user security training.
Flash Poll
Video
Slideshows
Twitter Feed
Dark Reading - Bug Report
Bug Report
Enterprise Vulnerabilities
From DHS/US-CERT's National Vulnerability Database
CVE-2014-4807
Published: 2014-11-22
Sterling Order Management in IBM Sterling Selling and Fulfillment Suite 9.3.0 before FP8 allows remote authenticated users to cause a denial of service (CPU consumption) via a '\0' character.

CVE-2014-6183
Published: 2014-11-22
IBM Security Network Protection 5.1 before 5.1.0.0 FP13, 5.1.1 before 5.1.1.0 FP8, 5.1.2 before 5.1.2.0 FP9, 5.1.2.1 before FP5, 5.2 before 5.2.0.0 FP5, and 5.3 before 5.3.0.0 FP1 on XGS devices allows remote authenticated users to execute arbitrary commands via unspecified vectors.

CVE-2014-8626
Published: 2014-11-22
Stack-based buffer overflow in the date_from_ISO8601 function in ext/xmlrpc/libxmlrpc/xmlrpc.c in PHP before 5.2.7 allows remote attackers to cause a denial of service (application crash) or possibly execute arbitrary code by including a timezone field in a date, leading to improper XML-RPC encoding...

CVE-2014-8710
Published: 2014-11-22
The decompress_sigcomp_message function in epan/sigcomp-udvm.c in the SigComp UDVM dissector in Wireshark 1.10.x before 1.10.11 allows remote attackers to cause a denial of service (buffer over-read and application crash) via a crafted packet.

CVE-2014-8711
Published: 2014-11-22
Multiple integer overflows in epan/dissectors/packet-amqp.c in the AMQP dissector in Wireshark 1.10.x before 1.10.11 and 1.12.x before 1.12.2 allow remote attackers to cause a denial of service (application crash) via a crafted amqp_0_10 PDU in a packet.

Best of the Web
Dark Reading Radio
Archived Dark Reading Radio
Now that the holiday season is about to begin both online and in stores, will this be yet another season of nonstop gifting to cybercriminals?