News for hackers. Stuff that matters.
Re:Simply Secure PHP Cryptography by pasta on Thursday July 13, 2017 @02:25PM (#14763840)
1. Clean up old tutorials, forum posts, and blogs.

This! I'm still seeing code snippets on StackOverflow that use hashing for password storage and queries without prepared statements.

I think at the moment that is still a weak spot of PHP.

Edit: my mistake. I was refering to weak hashes like md5 and sha1 or 'home brew' hashing.

Re:Simply Secure PHP Cryptography by stephenr on Thursday July 13, 2017 @02:41PM (#14763957)
> use hashing for password storage

As opposed to...?

Re:Simply Secure PHP Cryptography by aruggirello on Thursday July 13, 2017 @03:04PM (#14764179)
PHP has had a dedicated password hashing function since version 5.5: it's password_hash().

But at least, if you want to roll your own password hashing, do it right: use hmac, salting, stretching and a decent hash function - or use bcrypt/scrypt and save yourself a few headaches.

Re:Simply Secure PHP Cryptography by stephenr on Thursday July 13, 2017 @03:08PM (#14764215)
I'm well aware of that. The original comment suggested that password hashing is bad, I was trying to identify what the poster thought should be used instead.
Re:Simply Secure PHP Cryptography by idlewords on Thursday July 13, 2017 @03:22PM (#14764327)
Re:Simply Secure PHP Cryptography by CiPHPerCoder on Thursday July 13, 2017 @02:43PM (#14763970)
I assume they meant the use of a cryptographic hash function (which is wrong) instead of a password hash function (which, as the name implies, is suitable for password storage).

For example, I see a lot of this construction in proprietary code:

    $passwordHash = md5(md5($password) . md5($salt));
    if ($storedHash == $passwordHash) {
        // Authenticated successfully
    }
I'm quick to find these offending snippets and migrate our clients to use password_hash() and password_verify().
Re:Simply Secure PHP Cryptography by duskwuff on Thursday July 13, 2017 @02:48PM (#14764010)
Or, for that matter...

    SELECT * FROM user WHERE username = '$username' AND password_hash = MD5('$password')
Re:Simply Secure PHP Cryptography by chx on Thursday July 13, 2017 @06:46PM (#14765967)
Surely not after all these years! Does this easy SQL injection still exist...?
Re:Simply Secure PHP Cryptography by bitexploder on Thursday July 13, 2017 @08:13PM (#14766446)
Yes. Even in places where people use prepared statement and things like LINQ to build queries, somewhere someone will end up wanting or needing a query that is hard to express so they will start string building a raw SQL query and forget or not know to use prepared statements. We see this /all/ the time on our assessment of our customer's software.

It is markedly less common, but still quite common, if not pervasive like it used to be. PHP apps are dramatically more likely to have security vulnerabilities of any sort. It is a running joke we have that one of our recommendations to remediate security issues with PHP is to "rewrite in a different language". For whatever reason PHP has a history of encouraging vulnerable code. Even in good shops. PHP itself isn't really to blame (it is, of course much less likely for an experienced shop to write crappy PHP... but they probably wouldn't pick PHP to begin with).

Re:Simply Secure PHP Cryptography by duskwuff on Thursday July 13, 2017 @09:25PM (#14766750)
What deserves a lot of the blame is the awful mysql_* API, which didn't support query placeholders. (The mysqli and PDO APIs weren't available until much later, and weren't reliably available on many web hosts for even longer.) This forced PHP developers to become comfortable with constructing SQL queries as strings -- a habit which proved hard to break for many of them.
Re:Simply Secure PHP Cryptography by zaphar on Thursday July 13, 2017 @08:01PM (#14766378)
If you only knew the horrors I've seen. This week no less...
Re:Simply Secure PHP Cryptography by yjftsjthsd-h on Thursday July 13, 2017 @02:46PM (#14763992)
Perhaps no salt?
Re:Simply Secure PHP Cryptography by owenmarshall on Thursday July 13, 2017 @02:54PM (#14764077)
Salts don't save you from an attacker who can calculate millions of hashes per second on a GPU.

Using bcrypt/scrypt/Argon2id does.

Re:Simply Secure PHP Cryptography by wongarsu on Thursday July 13, 2017 @07:19PM (#14766122)
Salting is incredibly effective. Without salting, the entire power of the attacker can be used against all password hashes at once. With salting, those millions of hashes per second translates to only being able to crack simple passwords, or only the passwords of a few users.
Re:Simply Secure PHP Cryptography by tedunangst on Thursday July 13, 2017 @08:24PM (#14766492)
Except in the case of MD5, it's billions, many billions, of hashes per second, which translates to cracking lots of users' passwords.
Re:Simply Secure PHP Cryptography by TheRealPomax on Thursday July 13, 2017 @05:08PM (#14765264)
Salt is not intended to save you, just to make unhashing the next user's password just as much work as the one you just cracked.
Re:Simply Secure PHP Cryptography by olegkikin on Thursday July 13, 2017 @06:32PM (#14765899)
MD5 is not that weak, it's just fast, so you have to use a few rounds of it. The preimage vulnerability reduced the search space from 128 bits to 124 [1], which is still extremely secure. People who claim it's broken are probably thinking about the collision vulnerability, which doesn't help you at all to recover the password from a hash.

[1]: https://en.wikipedia.org/wiki/MD5#Preimage_vulnerability

If you think I'm wrong, I will gladly admit so, just tell me what the $password is here:

   if (md5(md5($password)) == 'c9876599e5e54aa12962ae1fe7b0f752') ...
Re:Simply Secure PHP Cryptography by astrodust on Thursday July 13, 2017 @06:50PM (#14765982)
The problem is not that hard passwords are easy to crack, it's that easy passwords are stupid easy to crack.

An attacker doesn't care about your password so much as they care about getting 50-80% of the passwords on the system, the majority of which are going to be "password123" or some other garbage you can find in a dictionary attack. If you use something like Bcrypt or Scrypt then running your dictionary cracker becomes a real ordeal, it will take a long time to grind through those entries and find matches. With MD5 it's a joke, you can do most of the common ones in seconds and the trickier variants within hours.

Hashcat (https://hashcat.net/hashcat/) can and will make short work of your double MD5 nonsense.

Additionally, if I can find a bit of text that hashes the same I don't care what the original password was. I have a key that works.

Re:Simply Secure PHP Cryptography by olegkikin on Thursday July 13, 2017 @07:05PM (#14766054)
That's why I mentioned "a few rounds of it". Use 1000 if you're paranoid, you can make it as computationally complex as BCrypt. And, of course, you should use salts. Good luck breaking that. You couldn't even break my double MD5.

Another thing you should do is not allow common or short passwords. That includes "password123". That alone will immediately elevate your security.

> Additionally, if I can find a bit of text that hashes the same I don't care what the original password was. I have a key that works

And you clearly don't understand how the collusion vulnerability works. You can't create one with a given hash. You carefully craft two documents that hash to the same hash, which you don't know in advance. Again, you can prove me wrong by doing just that to the hash in the code snippet.

Re:Simply Secure PHP Cryptography by stouset on Thursday July 13, 2017 @10:04PM (#14766874)
FFS, stop making cryptographic recommendations to others when you don't have expertise in this area.

Cryptographers nowadays are recommending PKBDF2 (essentially iterated hashing with the hash algorithm of your choice) with at least 100,000 rounds. And it's considered to by far the weakest of "modern" password hashing approaches, behind bcrypt, scrypt, and Argon2 (in that order).

Your double-MD5 is garbage, and nobody is going to bother wasting their time breaking it because it's a bullshit challenge. If you used a strong, unique password, you've missed the point, because users in the real world don't. If you used a weak password, we have a few billion points of empirical data that contradict you, so why bother installing hashcat and mucking about with password cracking rules when anyone paying attention for the past ten years knows what the outcome is going to be?

Re:Simply Secure PHP Cryptography by olegkikin on Friday July 14, 2017 @03:46PM (#14772620)
So use 100,000 rounds, use 1 million rounds, whatever amount makes you happy. You guys can't even break 2 rounds.

I actually do use PKBDF2 / Bcrypt in real world projects. My original comment was entirely about MD5 not really being broken, just too fast.

> because users in the real world don't.

No, you missed the point, and I wrote about it specifically. You should not allow weak / common / short passwords.

Re:Simply Secure PHP Cryptography by stouset on Sunday July 16, 2017 @03:47AM (#14781026)
MD5 is broken for passwords because it is too fast. Sure, if you use PBKDF2-MD5 with a random salt and 100k iterations you're going to be fine but that's not what anyone in this thread, including you, has been talking about.

You started off saying MD5 is fine, then backed off to saying it's fine with a salt, then fine with two rounds, then suggested 1,000 is okay, now we're at 100,000. At what point do you stop making excuses and acknowledge that your original advice was garbage, and backpedaling repeatedly is not helping your case?

Further, it is impossible to categorically prevent weak passwords. You can impose length restrictions. You can disallow common passwords. You can require special characters. But people's ability to come up with weak, pattern-based passwords fundamentally outperforms our ability to stop them, and at some point restrictions become so burdensome that people stop signing up for your app altogether.

"Just block weak passwords" is ridiculous on its face and you either know it and are arguing simply to save face, or you don't know it and are infuriatingly overconfident for your level of incompetence. I'm past the point of caring which.

Re:Simply Secure PHP Cryptography by astrodust on Friday July 14, 2017 @01:58AM (#14767839)
A thousand rounds of MD5 is absolute insanity, I mean that's the sort of thing that gets you banned from ever writing security critical code ever again. The cost of an MD5 cycle is basically zero. Zero times a thousand is still zero. Zero times a million is zero. It's got zero value in terms of protection.

Even SHA1, which is a much harder hash to compute, can be processed at trillions of hashes per second on some hardware. If you did a million cycles of SHA1, guess what? That thing can still crack a million guesses per second.

Bcrypt has a difficulty number you can pin at a level that's uncomfortably high. It may take 200ms to verify a password if you really crank it. That means you can't do thousands of hashes per second, but you're stuck doing maybe a thousand hashes per minute. You can't dictionary attack that.

I know how the collision vulnerability works. People have been creating MD5 collisions for fun for a while now, unconcerned with the original hash. If they focused their effort on matching hashes, they could probably do it by exploiting fundamental weaknesses in the MD5 hash system itself.

At this point a sufficiently robust SAT solver can probably crack it.

All your hand-waving about disallowing easy passwords doesn't matter. If you add restrictions, people find ways around them. It also doesn't matter if you make passwords incrementally harder if someone can crack them easily. Their computer doesn't care if they set it to search ten characters instead of eight, modern crackers are pretty efficient to fairly intimidating lengths.

Re:Simply Secure PHP Cryptography by olegkikin on Friday July 14, 2017 @03:47PM (#14772632)
> The cost of an MD5 cycle is basically zero. Zero times a thousand is still zero. Zero times a million is zero.

I don't think you have any clue what you're talking about. Do a million sequential rounds of MD5 on your CPU and measure how long it takes. I guarantee you, it's not zero. Not even close.

Re:Simply Secure PHP Cryptography by astrodust on Monday July 17, 2017 @09:55PM (#14793798)
GPU accelerated MD5 is a thing and I assure you it's a lot closer to zero than you'd think.

High-end FPGAs can smash through SHA1 at rates of billions per second and MD5 is not even that complicated. A million rounds is not as hard as Bcrypt cranked up to a sufficiently robust level.

Re:Simply Secure PHP Cryptography by tedunangst on Thursday July 13, 2017 @08:22PM (#14766483)
1000 rounds of MD5 is nowhere close to enough. Don't use MD5 for password hashing.
Re:Simply Secure PHP Cryptography by idlewords on Thursday July 13, 2017 @08:38PM (#14766567)
I don't know if you care, but "prove me wrong by breaking this" is a red flag for crackpottery in crypto, and people will set the bozo bit on you.
Re:Simply Secure PHP Cryptography by stouset on Thursday July 13, 2017 @10:10PM (#14766902)
He doesn't care because he's "right".
Re:Simply Secure PHP Cryptography by thehardsphere on Friday July 14, 2017 @08:16AM (#14769172)
Did you previously work for Yahoo?