[nSLUG] Crypt in Perl

George N. White III gnwiii at gmail.com
Wed Jan 7 13:46:19 AST 2009


On Wed, Jan 7, 2009 at 1:19 PM, D G Teed <donald.teed at gmail.com> wrote:
> On Wed, Jan 7, 2009 at 11:58 AM, D G Teed <donald.teed at gmail.com> wrote:
>>
>> I have an unmaintained open source web app which used crypt
>> calls to test for passwords stored in flat files.  I copied it
>> from a FreeBSD system with Perl 5.5.3 to a Redhat
>> box with 5.8.8 and it can't validate the passwords.
>>
>> Does anyone happen to know there were changes
>> to crypt in this time or it's workings has
>> dependence on something?
>>
>> --Donald
>>
>
> Here is a test which perplexes me:
>
> old FreeBSD:
> $ perl -e 'print crypt("cow","xy") . "\n";'
> xytJwuhSBf7w.
>
> modern Linux:
> $ perl -e 'print crypt("cow","xy") . "\n";'
> xytJwuhSBf7w.
>
> This matches.
>
> But with a salt of a single letter, say "X", things are different:
>
> old FreeBSD:
> $ perl -e 'print crypt("cow","X") . "\n";'
> XXI4zfZAWwgt6
>
> modern Linux:
> $ perl -e 'print crypt("cow","X") . "\n";'
> XX6CWUsAaU4R.
>
> Our legacy web app has a single letter for the salt, so this is
> why the problem is happening.

info libc has:

"The salt parameter does two things. Firstly, it selects which
algorithm is used, the MD5-based one or the DES-based one. Secondly,
it makes life harder for someone trying to guess passwords against a
file containing many passwords; without a salt, an intruder can make a
guess, run crypt on it once, and compare the result with all the
passwords. With a salt, the intruder must run crypt once for each
different salt. "

"For the MD5-based algorithm, the salt should consist of the string
$1$, followed by up to 8 characters, terminated by either another $ or
the end of the string. The result of crypt will be the salt, followed
by a $ if the salt didn't end with one, followed by 22 characters from
the alphabet ./0-9A-Za-z, up to 34 characters total. Every character
in the key is significant."

"For the DES-based algorithm, the salt should consist of two
characters from the alphabet ./0-9A-Za-z, and the result of crypt will
be those two characters followed by 11 more from the same alphabet, 13
in total. Only the first 8 characters in the key are significant. "

I think there have been different ways of manipulating/extending short
"salt" strings -- you may have to dig out sources to
see exactly what was done.

<http://docs.python.org/library/crypt.html>: "Since a few crypt(3)
extensions allow different values, with different sizes in the salt,
it is recommended to use the full crypted password as salt when
checking for a password."

-- 
George N. White III <aa056 at chebucto.ns.ca>
Head of St. Margarets Bay, Nova Scotia



More information about the nSLUG mailing list