Discussion:
[j-nsp] Format of SHA1 Passwords
Chip Marshall
2013-12-03 16:31:21 UTC
Permalink
I'm trying to write a utility for generating JUNOS-compatible
password hashes outside of JUNOS, and I've hit a bit of a
stumbling block with JUNOS SHA-1 passwords. They don't seem to
follow the normal crypt() pattern of $format$salt$hash and I
can't seem to find the format documented anywhere.

I get things like "$sha1$19418$aoTClyGU$cix8MhZsXwG6OrwUgeHAoOA8f.AX"
where it appears to have the format, some number, what I think is
the salt, and then the hash.

Anyone know how these things are calculated?
--
Chip Marshall <chip at 2bithacker.net>
http://2bithacker.net/
Chris Morrow
2013-12-03 16:34:12 UTC
Permalink
Post by Chip Marshall
I'm trying to write a utility for generating JUNOS-compatible
password hashes outside of JUNOS, and I've hit a bit of a
stumbling block with JUNOS SHA-1 passwords. They don't seem to
follow the normal crypt() pattern of $format$salt$hash and I
can't seem to find the format documented anywhere.
I get things like "$sha1$19418$aoTClyGU$cix8MhZsXwG6OrwUgeHAoOA8f.AX"
where it appears to have the format, some number, what I think is
the salt, and then the hash.
Anyone know how these things are calculated?
we do this calculation.... I believe your intended format is:
$1$salt$hash

or that seems to be what our code does.
Chip Marshall
2013-12-03 16:46:43 UTC
Permalink
Post by Chris Morrow
Post by Chip Marshall
I get things like "$sha1$19418$aoTClyGU$cix8MhZsXwG6OrwUgeHAoOA8f.AX"
where it appears to have the format, some number, what I think is
the salt, and then the hash.
Anyone know how these things are calculated?
$1$salt$hash
or that seems to be what our code does.
That's for MD5 passwords. I have a requirement to use SHA-1.
--
Chip Marshall <chip at 2bithacker.net>
http://2bithacker.net/
Chris Morrow
2013-12-03 17:05:47 UTC
Permalink
Post by Chip Marshall
Post by Chris Morrow
Post by Chip Marshall
I get things like "$sha1$19418$aoTClyGU$cix8MhZsXwG6OrwUgeHAoOA8f.AX"
where it appears to have the format, some number, what I think is
the salt, and then the hash.
Anyone know how these things are calculated?
$1$salt$hash
or that seems to be what our code does.
That's for MD5 passwords. I have a requirement to use SHA-1.
oh, ha! :( hrm... so, I set a passwd of 'flipfl0p!' for a user after
setting the passwd format to sha1 ... and I see:

"$sha1$19295$mROzSQ4a$SFnJ1fAbP4cHqw/16.xDV4s1LpMA"
Post by Chip Marshall
Post by Chris Morrow
Post by Chip Marshall
import hashlib
p = 'flipfl0p!'
s = 'mROzSQ4a'
hashlib.sha1(p+s).hexdigest()
bummer.
Paul Goyette
2013-12-03 17:20:15 UTC
Permalink
Looks like the output is identical to what would be generated by
the *BSD pwhash(1) utility.

# pwhash -S 24680 stuff
$sha1$23933$/WgTkHoe$25rdwdZ95cfgY/Tl6li2/LRIbuVT
#

pwhash(1) in turn calls the crypt(3) library function after it
generates a salt.

Digging through the sources, we find the following comment block
in src/lib/libcrypt/crypt-sha1.c

* The format of the encrypted password is:
* $<tag>$<iterations>$<salt>$<digest>
*
* where:
* <tag> is "sha1"
* <iterations> is an unsigned int identifying how many rounds
* have been applied to <digest>. The number
* should vary slightly for each password to make
* it harder to generate a dictionary of
* pre-computed hashes. See crypt_sha1_iterations.
* <salt> up to 64 bytes of random data, 8 bytes is
* currently considered more than enough.
* <digest> the hashed password.



-----Original Message-----
From: juniper-nsp [mailto:juniper-nsp-bounces at puck.nether.net] On Behalf Of Chris Morrow
Sent: Tuesday, December 03, 2013 9:06 AM
To: chip at 2bithacker.net; juniper-nsp at puck.nether.net
Subject: Re: [j-nsp] Format of SHA1 Passwords
Post by Chip Marshall
Post by Chris Morrow
Post by Chip Marshall
I get things like "$sha1$19418$aoTClyGU$cix8MhZsXwG6OrwUgeHAoOA8f.AX"
where it appears to have the format, some number, what I think is
the salt, and then the hash.
Anyone know how these things are calculated?
$1$salt$hash
or that seems to be what our code does.
That's for MD5 passwords. I have a requirement to use SHA-1.
oh, ha! :( hrm... so, I set a passwd of 'flipfl0p!' for a user after
setting the passwd format to sha1 ... and I see:

"$sha1$19295$mROzSQ4a$SFnJ1fAbP4cHqw/16.xDV4s1LpMA"
Post by Chip Marshall
Post by Chris Morrow
Post by Chip Marshall
import hashlib
p = 'flipfl0p!'
s = 'mROzSQ4a'
hashlib.sha1(p+s).hexdigest()
bummer.
_______________________________________________
juniper-nsp mailing list juniper-nsp at puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp
Chip Marshall
2013-12-03 17:32:24 UTC
Permalink
Post by Paul Goyette
Looks like the output is identical to what would be generated by
the *BSD pwhash(1) utility.
# pwhash -S 24680 stuff
$sha1$23933$/WgTkHoe$25rdwdZ95cfgY/Tl6li2/LRIbuVT
#
pwhash(1) in turn calls the crypt(3) library function after it
generates a salt.
Digging through the sources, we find the following comment block
in src/lib/libcrypt/crypt-sha1.c
Ah ha! Perfect! It appears this is specifically a NetBSD thing,
or at least my OpenBSD and FreeBSD boxes don't have crypt-sha1.c
or the pwhash utility.
--
Chip Marshall <chip at 2bithacker.net>
http://2bithacker.net/
Mark Felder
2013-12-03 17:16:05 UTC
Permalink
Post by Chip Marshall
Post by Chris Morrow
Post by Chip Marshall
I get things like "$sha1$19418$aoTClyGU$cix8MhZsXwG6OrwUgeHAoOA8f.AX"
where it appears to have the format, some number, what I think is
the salt, and then the hash.
Anyone know how these things are calculated?
$1$salt$hash
or that seems to be what our code does.
That's for MD5 passwords. I have a requirement to use SHA-1.
JunOS is based on FreeBSD, and FreeBSD doesn't support SHA-1 password
hashes. Your choices are:

DES: (no identifier)
MD5: $1$
Blowfish: $2$
NTHASH: $3$
SHA256: $5$
SHA512: $6$ (likely not supported as it's recent to FreeBSD)

And how to generate a hash (just change the identifier; it will create
the right hash):

python -c "import crypt, getpass, pwd; print crypt.crypt('password',
'\$1\$SALTsalt\$')"

Just make sure you use a different salt for each password.
Giuliano Cardozo Medalha
2013-12-03 17:21:52 UTC
Permalink
set system password format sha-1

Sent from my iPhone
Post by Mark Felder
Post by Chip Marshall
Post by Chris Morrow
Post by Chip Marshall
I get things like "$sha1$19418$aoTClyGU$cix8MhZsXwG6OrwUgeHAoOA8f.AX"
where it appears to have the format, some number, what I think is
the salt, and then the hash.
Anyone know how these things are calculated?
$1$salt$hash
or that seems to be what our code does.
That's for MD5 passwords. I have a requirement to use SHA-1.
JunOS is based on FreeBSD, and FreeBSD doesn't support SHA-1 password
DES: (no identifier)
MD5: $1$
Blowfish: $2$
NTHASH: $3$
SHA256: $5$
SHA512: $6$ (likely not supported as it's recent to FreeBSD)
And how to generate a hash (just change the identifier; it will create
python -c "import crypt, getpass, pwd; print crypt.crypt('password',
'\$1\$SALTsalt\$')"
Just make sure you use a different salt for each password.
_______________________________________________
juniper-nsp mailing list juniper-nsp at puck.nether.net
https://puck.nether.net/mailman/listinfo/juniper-nsp
Mark Felder
2013-12-03 17:47:03 UTC
Permalink
Post by Giuliano Cardozo Medalha
set system password format sha-1
Hmm, it does appear Juniper went ahead and added sha1 support as well.
Neat.

# set system login password format sha1

Continue reading on narkive:
Loading...