The History of SQL Injection, the Hack That Will Never Go Away (vice.com)
An anonymous reader writes with this history of SQL injection attacks. From the Motherboard article: "SQL injection (SQLi) is where hackers typically enter malicious commands into forms on a website to make it churn out juicy bits of data. It's been used to steal the personal details of World Health Organization employees, grab data from the Wall Street Journal, and hit the sites of US federal agencies. 'It's the most easy way to hack,' the pseudonymous hacker w0rm, who was responsible for the Wall Street Journal hack, told Motherboard. The attack took only a 'few hours.' But, for all its simplicity, as well as its effectiveness at siphoning the digital innards of corporations and governments alike, SQLi is relatively easy to defend against. So why, in 2015, is SQLi still leading to some of the biggest breaches around?"
HIV is easy to defend against. Relatively so, also, are things like malaria. Yet they still manage to kill millions. Why, in 2015? Also, is that more or less of a concern than SQL injection attacks?
Each year brings a fresh crop of computer science graduates into the industry, barely any of them having a clue about attacks like this. Many of them will make these mistakes and learn about defending against them the hard way.
Maybe a few schools teach about this now. Maybe a few companies will pair senior devs with new devs to transfer this knowledge on the job. Even so, there will be enough new programmers who don't know this, and enough companies who eschew senior talent as a cost-savings measure, that this vulnerability will continue to rear its ugly head.
So, Bobby Tables will have his name tattooed on his face...
Sleep your way to a whiter smile...date a dentist!
It is usually accomplished by accepting the lowest bidder.
Because typical PHP tutorials still teach old, broken ways of doing things and this shows no signs of abating. Go ahead and search the web for things like php mysql tutorial. The top hits are crap like this, written by incompetent developers who don't know what they are doing. PHP developers learn from crap like that, then they go on to write their own tutorials that are the same or worse.
And before you start, yes, this is something where PHP is stand-out bad. Go ahead and try the same searches with other languages. There is a vast difference in quality of learning materials. I mean, PHP had XSS vulnerabilities in its official tutorials until relatively recently. Newbies don't stand a chance in those circumstances.
Bogtha Bogtha Bogtha
...SQLi is relatively easy to defend against.
Relatively? It's trivial to defend against (spoiler: use prepared statements), and anyone creating software that has even the potential for SQL injection is an incompetent moron.
Hiring a programmer who doesn't know how to eliminate SQL injection is like hiring a surgeon who doesn't know how to use a scalpel, or a bridge builder who doesn't understand weight distribution. It's the first thing that a programmer should learn when learning to write database aware software.
And also too easy to do it right.
It doesn't have to be like this. All we need to do is make sure we keep talking.
You are absolutely right. I see this all the time as the hiring manager in a web shop. I always present candidates with this question:
1. Find and fix the potential SQL injection vulnerability: // .. /*@var \PDO */ //..
protected $dbh;
public function getOption($name)
$sql = "SELECT val FROM options WHERE name = {$name}";
$stmt = $this->dbh->prepare($sql);
$stmt->execute();
return $stmt->fetchColumn();
}
For those who don't know PHP, the answer is:
$sql = "SELECT val FROM options WHERE name = ?";
$stmt = $this->dbh->prepare($sql);
$stmt->execute(array($name));
Almost no candidates out of school even know what I'm asking them to do. About half of people with experience get it right; a quarter of them understand the question and get it wrong, and a quarter don't understand the question. I find that it doesn't matter how many years of experience they have, about a quarter of programmers just don't understand what SQL injection is.
I just don't get it. I've spent more than a decade programming in PHP, the language that really made SQL injection a thing because it lacked prepared statements for a long, long time and even then a lot of the input escaping functions were broken. Over those years, I've picked up a lot of bad habits; some were dictated by the shortcomings of PHP4 ("dependency injection? what's that?"), others are a side effect of spending all of my time cranking out single purpose scripts that had to work yesterday ("Ctrl+C; ctrl+V").
Nevertheless, it still blows my my mind when I encounter people in this day and age who aren't using prepared statements. Concatenating SQL is just so... messy. Seriously, it takes two minutes to write a nice, clean, understandable SQL statement as a string, and at most a three line loop to bind the values. If your are concatenating it together, you have a mess of loops and conditions (comma here?) and strings and array manipulations... It is so much more work.
Yet I still hire jokers who can't do it because I need bodies to fill seats.
The Hiawatha webserver can block SQL injection attacks. I like to hear what you think of it.
It doesn't have to be like this. All we need to do is make sure we keep talking.
If people used perl and DBI with properly prepared statements, instead of [censored] php.
Religion is what happens when nature strikes and groupthink goes wrong.
A language is not secure or unsecure. It's what developers do with it that makes the result secure or unsecure. I can write a .NET or Java application that has all the vulnerabilities you can think of.
It doesn't have to be like this. All we need to do is make sure we keep talking.
There is no way around it.
What do you mean there's no way around it? That's the stupidest thing I've heard all day. It's simple to prevent even if you write all your queries with string concatenation. It's called an escape sequence.
Myself, I prefer to use stored procedures for all db interactions, and set table access to deny for the account used by the web server. But that's me.
-1 Uncomfortable Truth
Interesting. Banshee includes many features that every other "CMS" require "extensions" for -- which winds up being mostly unverified third-party code from developers of possibly questionable skill. It would also appear that Banshee's source has undergone at least one external third-party security audit.
I wonder how Banshee compares to ProcessWire...
From the surface at least Banshee looks more "big-feature" complete|inclusive than ProcessWire.
No, I didn't write "a lack of people who write code". I exactly mean what I wrote: A lack of programmers.
What we have today is a load of people who learned programming somehow, kinda-sorta, but without understanding just what they're doing. Now add how most of them gains information about how to do things. By looking it up on the internet. And taking the first solution that looks like it works.
Of course it's easier to simply concat strings than using prepared statements and parameters. It is simply more readily understandable and less convoluted for people who have little knowledge and less time to gain it. And they don't know anything about security and why this could possibly be a security problem.
These people are cheaper than people who know what they're doing. So much cheaper even that the additional time they need to get anything done is easily compensated. And whether it is a security problem is usually only found out after a security breach happens because, well, whoever hired them has even LESS knowledge about security.
And since every year a new batch of people comes out of schools that kinda-sorta learned how to kinda-sorta do queries, this problem will mean job security for me 'til retirement.
We used to have a Bill of Rights. Now, with the rights gone, all we have left is the bill.
If any other language would have the same popularity as PHP, it would suffer the same problem. All the noobs that write bad PHP code would than write bad .NET/Java/Python/whatever code. With 'same popularity', I mean being used by all the noobish kiddo's that now abuse PHP.
It doesn't have to be like this. All we need to do is make sure we keep talking.
Absolutely PHP was originally for for non-programmers. It was a CMS written in Perl, for people who couldn't use the Perl templating systems directly. That was a long time ago, of course.
It was abused as a general programming language, often by people who didn't know about file permissions and couldn't be bothered to learn how to chmod 755. That wouldn't have been a huge problem if they weren't putting the scripts on web sites, for everyone to attack. That was a big problem for several years - non-programmers who didn't want to learn an actual programming language wrote PHP scripts and PUT THEM ON THE INTERNET. It wouldn't really have been a big deal if they wrote scripts for their own desktop or for their local intranet.
Now that PHP has been used as a general-purpose web programming language for several years, it has been significantly updated to better fit that role. Current PHP is much, much better than it was a few years ago. It's still relatively easy, though, so it -can- be used by people who are clueless. But now it's also used, correctly, by people who are actually competent.
var user={username:'bob',messages:[{username:'al',text:'hi bob!'}],contacts:[]}
When you realize how this can be translated exactly into SQL, you will be enlightened.
"First they came for the slanderers and i said nothing."
Yeah, what is or could go wrong with that?
You tell us. Or maybe you don't actually know the answer, and just want to imply that you do.
systemd is Roko's Basilisk.
There is no denying that PHP was made with design decisions that make it easy to write insecure code by default. PHP is less secure by default by itself for noobs and those far better than noobs. Look at FB's history with PHP. They created "Hack" to avoid many of PHPs problems, yet kept the good parts of PHP... noobs, hardly. Being 'popular' should have driven PHP to be secure, not used as an excuse for why it's easy to hack with SQLi.
Because businesses think software development in general, and especially web development, is easy. They hire monkeys and pay peanuts (or sometimes even serious dollars that could get them quality of they could recognise they were being taken for a ride), and we continue to see the most basic errors being repeated across most web sites. Seriously, the quality of web developers generally is absolutely appalling.
But MongoDB is web-scale.
So why, in 2015, is SQLi still leading to some of the biggest breaches around?"
Easy, idiots writing the apps because companies don't want to pay for skilled people that demand honest wages. they instead outsource ti for the lowest bidder and then bitch when they get crap quality because that is all they were willing to pay for.
Do not look at laser with remaining good eye.
There simply isn't any incentive for to build software that will last through some cyber attack some 10 months or 3 years into the future. The current incentives reward sloppily slapping together something that barely functions and gives a demo without crashing. If your demo crashes and makes the boss look bad, you're fired. If your demo works, has slick graphics and no spelling mistakes and the english dialog is polished, you get a raise. You're building software for the boss's demo, you're not building software that's robust, handles edge-cases, and input sanitizes everything. I meant, you could, but you're not getting paid any extra for it.
There's a lot more client/server going on, and a lot of programmers haven't discovered that you can't trust the client and are doing all their input validation and sanitation on the client side. As long as that's going on, this sort of attack is going to be popular. '); drop table articles.
I'm trying to teach myself to set people on fire with my mind... Is it hot in here?
This is pretty much right. We're trapped writing snippets of one language (SQL) in another (PHP/whatever).
Avoiding any single SQLi vulnerability is trivial - use stored procs, escape strings, or use parameterized queries. You can even avoid most problems at the organizational level as long as someone competent is in charge and raw SQL is banned or forced into rigid guidelines.
But it seems we've collectively decided to trust our data interface to a framework that is at its core no better than an eval() in terms of inherent safety. That's just asking for trouble.
Last post!
Learn about parameterized queries. It's not a problem.
"First they came for the slanderers and i said nothing."
There is a ton of legacy code out there that was written before people worried about SQL injection. There's so much of it, going back and refactoring it would be as monumental as fixing the two-digit year problems of Y2K. Businesses really don't like to pay money for software development that doesn't lead to more sales, so it's a hard sell for IT departments. Sadly, this means that the problems don't get fixed until after a company loses money due to an actual attack.
Somewhere along the way we dispensed with DBAs and anyone else who might freak out at insecure access to the database layer. Glad that's working out.
I always wonder why people - even professionals (ableit only the non-DB pros) - think SQL is a feasible means for an application to utilise persistance. It isn't. In fact, it's a huge smelly turd for app-persistance and using it so broadly for this sort of work is a really harebrained and abysmally stupid idea.
That we have to deal with SQL injection problems is one of the countless pieces of crap based on this technology decision.
SQL was meant as an end-user interface for interacting with relational database - and for that it is absolutely perfect. End of story.
Using SQL as intermediate for application persistance is one of the most annoying and studidest things in the history of applikation development - for reasons to countless to list them. DB designers are among those who time and time again shake their heads in disbelief when they see the mess devs do with SQL.
We suffer more in our imagination than in reality. - Seneca
PHP.net says "1994 - Started writing CGI scripts in C and Perl".
http://talks.php.net/show/comm...
By the time PHP was gaining popularity, Text::Template and HTML::Embperl were available for Perl.
Rasmus's comments in this interview are revealing:
"I donâ(TM)t know how to stop it, there was never any intent to write a programming language [â¦] I have absolutely no idea how to write a programming language, I just kept adding the next logical step on the
way."
MP3 recording of these comments:
http://web.archive.org/web/201...
The sad thing is that most programmers are still using simple string concatenation to write their SQL programmatically. In this modern day, that is beyond silly. If you use a DSL like jooq, you get several advantages. First off, all strings will automatically be bounded and avoid the simple injection tactics that most people use. Second, you can change databases on a whim by just changing the dialect. This is great for testing and using in memory databases for unit tests. If people just took that simple step, very few attacks would remain, and they would probably be much happier programmers with far fewer bugs!
Take a look at MVProc - http://mvproc.free-blog.net/ SQL Injection doesn't ever get a foothold, and it (the module) is very efficient with a tiny footprint. (Yes, I wrote it; and I'll take whatever feedback comes my way.)
Retired from software... maybe. Sort of.