Skip to main content

Security questions are salt

It's common for web sites to have a password recovery feature and some ask the user to set up answers to security questions which they can answer later. The main feature of these is that they are intended to be something the user knows and can answer later without remembering. So questions like "What was the make of your first car?" are common.

Unfortunately, these questions are weak because a determined attacker can often find out the information required to answer the questions. In one notable case a US Vice Presidential candidate's email was hacked by searching for and finding the target's high school name and date of birth. This leads to these questions being very insecure.

In addition, some questions, such as "What was the make of your first car?" have a very small likely answer space. If the target is British, for example, the number of car makers is small and a guess is quite likely to work, especially considering that it's unlikely that a first car will come from a luxury manufacturer.

My personal approach is to not forget my passwords (because I use unique passwords that I can access as needed), and I fill in these questions with nonsense.

But, if you do want the option of using the recovery feature then there's a simple solution: consider the question as password salt and answer using a hash.

Here's how that works:

1. Think of a password that you will remember, that's long and complex (perhaps even a passphrase as you will not need it often). You'll use this password to create answers to security questions everywhere.

2. When confronted by a security question answer with the result of hash_function(passphrase, security_question).

For example, suppose that you've chosen the passphrase "honi soit qui mal y pense" and you are being asked to choose an answer to the question "What is the make of your first car?" you would calculate (here I am using bcrypt (program below) because it's secure and slow) a hash:

    perl bcrypt.pl "honi soit qui mal y pense" "What is the make of your first car?"
  ouVXFntvrfbJCHwoEvfbF8Hn3gYik.W

and enter the response as "ouVXFntvrfbJCHwoEvfbF8Hn3gYik.W"

Any time you actually have to answer the question it's simply a matter of recalculating the hash from the question and the password you've chosen.

The security question is acting as salt, the security of this relies on: the long, complex passphrase chosen and the secure hash algorithm.
use strict;
use warnings;

use Digest::SHA1 qw(sha1);
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);

my ($passphrase, $question) = @ARGV;
my $salt = en_base64(substr(sha1($passphrase),0,16));

my $hash = bcrypt($question, '$2a$16$' . $salt);
$hash =~ /$salt(.*)$/;
print "$1\n";
PS As Damian points out below, reading one of these would be a nightmare over the phone. So an improvement is to find a sequence of words that encodes the hash. Here's one approach based on finding words that contain subsequences of the hash value in the dictionary.
use strict;
use warnings;

use Digest::SHA1 qw(sha1);
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);

my ($passphrase, $question) = @ARGV;
my $salt = en_base64(substr(sha1($passphrase),0,16));

my $hash = bcrypt($question, '$2a$16$' . $salt);
$hash =~ /$salt(.*)$/;
my $output = $1;
print "$output\n";

my @words;

open F, "</usr/share/dict/words";
while (<F>) {
 chomp;
 my $w = $_;
 if ( $w =~ /^[a-z]{5,}$/ ) { 
  push @words, lc($w);
 }
}
close F;

@words = sort { length($a) <=> length($b) } @words;

$output = lc($output);
$output =~ tr/0123456789/oizeasblxq/;
$output =~ s/[^a-z]//g;

print word($output), "\n";

sub word {
 my ( $w ) = @_;

 my $found = find_word($w);

 if ( $found ne "" ) {
  return $found;
 } else {
  foreach my $i (reverse 1..length($w)-1) {
   my ( $left, $right ) = (substr( $w, 0, $i), substr($w, $i));
   $found = find_word($left);
   if ( $found ne "" ) {
    return "$found " . word($right);
   }
  }

  die "Couldn't find a word";
 }
}

sub find_word {
 my ( $w ) = @_;

 $w = join('.', split(//,$w));

 foreach my $x (@words) {
  if ( $x =~ /$w/ ) {
   return $x;
  }
 }

 return "";
}

Then instead of trying to say "ouVXFntvrfbJCHwoEvfbF8Hn3gYik.W" you say "bogus vexed definitive prefab jackhammer whole vivify abaft exchange angry bilks aglow"

And you could likely get away with not the entire response but something shorter, say just take the first two words. So, the response to "What was the make of your first car?" could be simply "bogus vexed"

Comments

Anonymous said…
Nice!

My only quibble is that they might rephrase the security question slightly which would ruin everything, and you better use an algorithm you can if need be write the script for extemporaneously on someone else’s computer, just in case of emergencies!

It will also be really annoying reading these ‘answers’ over the phone to a call centre person … :-)
zyphlar said…
I like the idea of at least lying about the answer (your first car was a banana?) or salting it in English (your first car was a holli polli cracker BMW?)
Unknown said…
Smart work. It's a nice touch that your passphrase is my old grammar school motto. Theoretically discoverable in my case ;)
btilly said…
A compromise of one site that uses a given security question may result in someone being able to get into a different site that uses the same security question.

To fix that the site MUST be part of your hashing algorithm.
Anonymous said…
I would suggest the following, which should work on most linux/unix/*bsd systems:

echo "sitename username answer" | openssl dgst -sha1 -binary | openssl enc -nosalt -bf -base64

The first digest ensures that passwords will always be 33 characters long,
and that the passwords for "sitename username", "sitename1 username", "sitename username1" will not be similar.

The -binary on dgst ensures consistent results on different linux/unix/*bsd systems.

We use unsalted blowfish encryption. There seems to be nothing gained by using salt in this usecase.
If you DO use a salt (option -S), remember to filter the base64 password throuhg "cut -b22-".

Finally, a note on the use of "words":
Using /usr/share/dict/words is dangerous!
On a different system, or after a system upgrade, the list may be different,
and your password/answer difficult to obtain!
Anonymous said…
Questions such as "the make of first car" do not have to be answered with a real make. My first car was a Ford, but I would never give "Ford" as an answer to the above question.
Wandering Logic said…
Brilliant post! Thank you.

I've been just creating random responses to security questions and then storing the question/answer pairs encrypted. Your technique is way better.

The only problem (for both of our techniques) is that many sites are starting to limit what you can type as answers. They have maximum lengths, won't accept non-alpha, etc.

The worst example is a bank I am forced to work with where one of the security questions is the year you graduated from high-school, and they won't let you enter anything other than a 4 digit number!!!
Wandering Logic said…
Brilliant post! Thank you.

I've been just creating random responses to security questions and then storing the question/answer pairs encrypted. Your technique is way better.

The only problem (for both of our techniques) is that many sites are starting to limit what you can type as answers. They have maximum lengths, won't accept non-alpha, etc.

The worst example is a bank I am forced to work with where one of the security questions is the year you graduated from high-school, and they won't let you enter anything other than a 4 digit number!!!

Popular posts from this blog

Your last name contains invalid characters

My last name is "Graham-Cumming". But here's a typical form response when I enter it:


Does the web site have any idea how rude it is to claim that my last name contains invalid characters? Clearly not. What they actually meant is: our web site will not accept that hyphen in your last name. But do they say that? No, of course not. They decide to shove in my face the claim that there's something wrong with my name.

There's nothing wrong with my name, just as there's nothing wrong with someone whose first name is Jean-Marie, or someone whose last name is O'Reilly.

What is wrong is that way this is being handled. If the system can't cope with non-letters and spaces it needs to say that. How about the following error message:

Our system is unable to process last names that contain non-letters, please replace them with spaces.

Don't blame me for having a last name that your system doesn't like, whose fault is that? Saying "Your last name …

All the symmetrical watch faces (and code to generate them)

If you ever look at pictures of clocks and watches in advertising they are set to roughly 10:10 which is meant to be the most attractive (smiling!) position for the hands. They are actually set to 10:09.14 if the hands are truly symmetrical. CC BY 2.0image by Shinji
I wanted to know what all the possible symmetrical watch faces are and so I wrote some code using Processing. Here's the output (there's one watch face missing, 00:00 or 12:00, because it's very boring):



The key to writing this is to figure out the relationship between the hour and minute hands when the watch face is symmetrical. In an hour the minute hand moves through 360° and the hour hand moves through 30° (12 hours are shown on the watch face and 360/12 = 30).
The core loop inside the program is this:   for (int h = 0; h <= 12; h++) {
    float m = (360-30*float(h))*2/13;
    int s = round(60*(m-floor(m)));
    int col = h%6;
    int row = floor(h/6);
    draw_clock((r+f)*(2*col+1), (r+f)*(row*2+1), r, h, floor(m…

The Elevator Button Problem

User interface design is hard. It's hard because people perceive apparently simple things very differently. For example, take a look at this interface to an elevator:


From flickr

Now imagine the following situation. You are on the third floor of this building and you wish to go to the tenth. The elevator is on the fifth floor and there's an indicator that tells you where it is. Which button do you press?

Most people probably say: "press up" since they want to go up. Not long ago I watched someone do the opposite and questioned them about their behavior. They said: "well the elevator is on the fifth floor and I am on the third, so I want it to come down to me".

Much can be learnt about the design of user interfaces by considering this, apparently, simple interface. If you think about the elevator button problem you'll find that something so simple has hidden depths. How do people learn about elevator calling? What's the right amount of informati…