You Want Salt With That? Part Three: Salt The Hash

You Want Salt With That? Part Three: Salt The Hash

Rate This
  • Comments 21

Last time we were considering what happens if an attacker gets access to your server's password file. If the passwords themselves are stored in the file, then the attacker's work is done. If they're hashed and then stored, and the hash algorithm is strong, then there's not much to do other than to hash every string and look through the password file for that hash. If there's a match, then you've discovered the user's password.

You don't have to look through the vast space of strings in alphabetical order of course. An attacker will start with a dictionary of likely password strings. We want to find some way to make that attacker work harder. Setting a policy which disallows common dictionary words as passwords would be a good idea. Another technique is to spice up the hashes a bit with some salt.

System #3

For every user name we generate a random unique string of some fixed length.  That string is called the “salt”.  We now store the username, the salt and the hash of the string formed by concatenating the user’s password to the salt. If user Alpha's password is "bigsecret" and the salt is "Q3vd" then we'll hash "Q3vdbigsecret".

Since every user has their own unique random salt, two users who happen to have the same password get different salted hashes.  And the dictionary attack is foiled; the attacker cannot compute the hashes of every word in a dictionary once and then check every hash in the table for matches anymore.  Rather, the attacker is going to have to re-hash the entire dictionary anew for every salt.  A determined attacker who has compromised the server will have to mount an entire new dictionary attack against every user’s salted hash, rather than being able to quickly scan the list for known hashes.

Salting essentially makes it less feasible to attack every user at once when the password file is compromised; the attacker must start a whole new attack for each user.  Still, given enough time and weak passwords, an attacker can recover passwords.

In this system the client sends the username and password to the server, the server appends the password to the salt, hashes the result, and compares the result to the salted hash in the table. 

This answers the original question posed by the JOS poster; the salt can be public because it is just a random string. Ideally, both the salt and the salted hash would be kept private so that an attacker would not be able to mount a dictionary attack against that salt.  But there is no way to deduce any information whatsoever just from the salt.

And of course, it's better to not get into this situation in the first place -- don't allow your password list to be stolen! But it's a good idea for a security system to not rely on other security systems for its own security. We call this idea "defense in depth". You want to make the attacker have to do many impossible things to compromise your security, so that if just one of those impossible things turns out to be possible after all, you're not sunk. 

But what about the fact that the password goes over the wire in the clear, where anyone can eavesdrop? That's now the weak point of this system. Can we do something about that? Tune in next time and we'll see what we can come up with.


  • Defense in Depth?

    That would be, for example, not allowing a web browser to access operating system functionality?
  • Blobby, you could unplug your computer from the network if you want the ultimate security, but most people care about functionality more than security. So we as programmers need to provide the functionality with the best security feasible.
  • I believe Mr. Blobby is referring to running under least privilege.
  • We concatenate the "user name" before the password before hash it. This way even users with same password have different hashes.

    What is the advantage os using "salt" over our algorithm?
  • The "Principle of Least Privilege" and the "Principle of Defense In Depth" are different principles of secure design.

    By "Least Privilege" I mean that a system should grant the smallest number of privileges possible. Some examples:

    * If you're running a bank, only give the combination to the safe to people who absolutely positively need it -- not the tellers, the security guards, the customers...

    * If you're running a script from a web page, the web browser should restrict that script to the smallest possible set of functionality that allows the script to get safe work done.

    * If you're logging in to check your email, log in from a "regular user" account, not from an "administrator" account. If you don't need a privilege, don't be in a situation where it's going to be granted; if an attacker manages to get you to run a Trojan horse, you'll run it with regular user privileges and not administrator privileges.

    * If you're writing a managed application that needs to assert a privilege, then don't assert Full Trust. Just assert the privilege you're going to need, and revert the assert when you're done with it. That way if an attacker takes advantage of a security hole in your program, they get the right to, say, read an environment variable, rather than full trust.

    The principle of Defense In Depth by contrast, is the principle that secure systems are built in layers, and each layer is designed so that if every other layer has failed, it is still reasonably secure. You want to keep a resource safe, so you protect it with a password. What if an attacker gets onto the server? Protect the password file so that it can only be read by administrators. What if the attacker defeats that protection? Encrypt the file. What if he breaks the encryption? Store hashes rather than passwords. What if he runs a dictionary attack against the hashes? Salt them to make dictionary attacks harder. What if an individual user's password is being attacked? Ensure that all users choose long passwords that are hard to brute-force. Etc, etc, etc.

    The idea of a defense-in-depth security system is to make the system sufficiently strong that the expense of mounting a successful attack is higher than the value of the resource being protected.

  • Carlos - actually that user name would work as a "salt" value for your algorithm. But, you have the potential problem that if you change the user name through other means, you won't be able to successfully evaluate your hashed password anymore.

  • > What is the advantage os using "salt" over our algorithm?

    You are using a salt, you're just using the user name rather than a random salt.

    The problem with using user names is that they are highly predictable. And if they're highly predictable, that means that attackers can precompute large dictionaries of username-followed-by-password hashes which can then be used to attack the system.

    Also, if you use a random salt then you can choose how much entropy is added to the password by choosing the salt length.
  • "We concatenate the "user name" before the password before hash it. This way even users with same password have different hashes."

    The only problem some may have with that is if multiple sites use the same method, then you have the user's password equiv on all those sites too (i.e. banks, etc). It is just as easy to use a random salt and store the salt with the user. This does not slow down dictionary attacks on that one user, but does make all user/pwd combos unique *and unique to your site only. The algo could then become:
    PWEquiv = SHA1(username + pw)
    SHA1(DBSalt + PWEquiv)

    Note hashes should *only be sent encrypted on the wire as it is too easy to dictionary attack simple hashes off wire. Even passwords like "Sunlight;12" can be cracked in seconds. So the encryption protects the wire all the way down to your verifier logic which does the decryption. A strong pw policy is also required to help protect against the inside dictionary attack.

  • You obviously have a good understanding of the basics of security design, Eric. Why doesn't Microsoft actually implement such designs?

    Why does so much of Microsoft's own software require administrator access to run when it could easily be adapted to only affect userspace, thus encouraging people to run as Administrator? Why does XP default to 'Administrator' status when setting up a new account?

    Why does IE need to access operating system functionality?

    Why is there no easy, simple way for a user to securely encrypt a file or directory for themselves?

    XP SP2 had security-focus and did quite well, but the underlying principles need changing. Yeah, I'm sure it will all be rosy in Longhorn, if it ever comes out...
  • Mr Blobby, Why doesn't Linux have any concept of a domain? Why doesn't Linux support any concept of group policies or SMS? Sure Linux may make for a good web or FTP server, but in the IT enterprise... sadly lacking.

    Anyway, I can see this series going for awhile. Sure you can hash the password on the client and send that, but you are still susceptible to replay attacks. At this point it gets interesting, for me at least. I seem to remember something using digitally signed timestamps.

  • > Why doesn't Microsoft actually implement such designs?

    I reject the premise of the question. Microsoft implements such designs all the time.

    Every product now must go through threat modeling during design and security-specific code reviews after coding.

    I will be the first person to admit that the Microsoft coding culture at large was not very security-conscious in the past. This has changed massively in the last few years.

    > Why does so much of Microsoft's own software require administrator access to run when it could easily be adapted to only affect userspace,

    I reject the premise of the question. It is NOT easy to design software that works in partial trust situations.

    I work on Visual Studio. We have done a HUGE amount of research into finding ways to make Visual Studio work well for non-administrator developers, but it is a VERY HARD PROBLEM. Fundamentally, debugging a process is one of the most security-breaking things you can do to a machine, and it is therefore a highly privileged operation.

    We are working extremely hard in devdiv to come up with ways to write software developer tools that do not require admin to run, and we will get there eventually because this is a high-priority goal for the company.

    > Why does XP default to 'Administrator' status when setting up a new account?

    Because otherwise people can't install video games.

    Video games are very high on the list of reasons why people buy computers, and if they can't get their video game to install, do you think their first call is to the video game company to demand that they implement a user-mode installer, or to Microsoft tech support?

    I would very much like to see improvements to our security model so that video games can be installed and run by normal users, but this will require the cooperation of game companies. Historically the game industry has done a very poor job of implementing secure designs.

    > Why is there no easy, simple way for a user to securely encrypt a file or directory for themselves?

    I reject the premise of the question.

    Right click the file. Select properties. Select General. Select Advanced. Check "Encrypt contents".

    That's five mouse clicks. How much easier do you want it to be?

  • Blobby: actually, very little of Microsoft's software - at least, recent software - requires administrator access.

    IE only requires the same access to operating system functionality as any other user mode process. It's a common myth that IE is somehow integrated into Windows, using private features. The Internet Explorer we all know is pretty much just a frame around the WebBrowser control. The WebBrowser control is one of the components supplied with the OS. It runs on top of the WinInet library, which is also a component supplied with the OS. That in turn runs on top of Windows Sockets, which is a sanitizing wrapper over the raw AFD driver interface which _actually_ drives the TCP/IP stack in kernel mode.

    The WebBrowser control is also used by HTML Help, on Windows 2000 and later the Add/Remove Programs box, Windows Media Player's built-in browser, WinAmp's built-in browser, RealPlayer's built-in browser, a number of third-party browser shells, and the RSS Bandit window I'm currently typing this comment into.

    To encrypt a file or directory, right-click the item in Explorer, choose Properties, click Advanced, tick 'Encrypt contents to secure data' and OK, then OK again. I'm not sure why you think that's complicated. The Administrator gets a recovery key. The technical details are that the file itself is encrypted with a secret key algorithm such as DES, then the secret key is encrypted with your file-encryption public key and the Administrator's recovery public key. The encrypted secret key blocks are attached to the file as well. If you grant permission to someone else, your encryption block is decrypted, the secret key is encrypted again with the new user's public key, and the newly encrypted block is added to the file. If you revoke permissions again that user's key block is deleted.

    If the option isn't present your disk may not be formatted with the NTFS filesystem, or you're running some version of Windows prior to Windows 2000.
  • Mike's comment raises an extremely important point about encryption. Encryption is EASY, but KEY MANAGEMENT is a pain in the rear!

    There's no easy encryption because encryption is not a simple panacea. To use encryption correctly you need to understand what is being encrypted, why, for how long, what attacks are likely, how you're going to manage the keys, blah blah blah blah blah. It is just fundamentally a really hard technology to use correctly.

    Part of secure design is understanding your users. Users are not professional cryptographers. They don't understand what they want, they don't understand the attacks, they don't understand any of that stuff. All they understand is "encrypted = safe", which is not even true.

    You can't just build a general-purpose arbitrary-algorithm encryption system into a consumer-grade operating system and hope that people use it correctly, because they won't. You have to very carefully look at the scenarios in which they will use it, and design a system which meets those requirements, and steers people down that path. The encrypting file system meets the needs of a very large segment of our customers and has a reasonably misuse-proof key management system so that's where we focused our efforts.
  • Fabulous Adventures in Coding assays this week a, well, fabulous adventure, in simple cryptography. I know enough to get myself in deep trouble with this subject, but Eric has put together three short and knowledgeable posts that begin easy and...
  • Thanks for pointing out the encryption thing, I didn't realise! </blush>

    Regading IE, I don't mean the process itself, I mean the way ActiveX controls can have control beyond the application.

    Regarding (for example) Visual Studio: Why do you need an Administrator account at all? Why not have a set of granular privileges, and something like su? SELinux is a start in the *nix world but still unfortunately not widely deployed. It's excellent to hear it's a priority.

    Linux certainly does have the capability to set group level privileges, but I get your point - yes, it has a lot to learn about security too. I reject the notion that (for example) RHES isn't enterprise ready, but that is irrelevant here. Why should that stop me pointing out (what I perceive to be) weaknesses in Microsoft security?
Page 1 of 2 (21 items) 12