passlib.hash.msdcc - Windows' Domain Cached Credentials¶
Danger
This algorithm is not considered secure by modern standards. It should only be used when verifying existing hashes, or when interacting with applications that require this format. For new code, see the list of recommended hashes.
This class implements the DCC (Domain Cached Credentials) hash, used
by Windows to cache and verify remote credentials when the relevant
server is unavailable. It is known by a number of other names,
including "mscache" and "mscash" (Microsoft CAched haSH). Security wise
it is not particularly strong, as it's little more than nthash
salted with a username. It was replaced by msdcc2
in Windows Vista.
This class can be used directly as follows:
from passlib.hash import msdcc
# hash password using specified username
hashed = msdcc.hash("password", user="Administrator")
print(hashed)
# > '25fd08fa89795ed54207e6e8442a6ca0'
# verify correct password
print(msdcc.verify("password", hashed, user="Administrator"))
# > True
# verify correct password w/ wrong username
print(msdcc.verify("password", hashed, user="User"))
# > False
# verify incorrect password
print(msdcc.verify("letmein", hashed, user="Administrator"))
# > False
Tip
password hash usage-- for more usage examplesmsdcc2-- the successor to this hash
Interface¶
msdcc
¶
msdcc(user=None, **kwds)
This class implements Microsoft's Domain Cached Credentials password hash,
and follows the :ref:password-hash-api.
It has a fixed number of rounds, and uses the associated username as the salt.
The :meth:~passlib.ifc.PasswordHash.hash, :meth:~passlib.ifc.PasswordHash.genhash, and :meth:~passlib.ifc.PasswordHash.verify methods
have the following optional keywords:
Parameters:
-
user(str, default:None) –String containing name of user account this password is associated with. This is required to properly calculate the hash.
This keyword is case-insensitive, and should contain just the username (e.g. ``Administrator``, not ``SOMEDOMAIN\Administrator``).Note that while this class outputs lower-case hexadecimal digests, it will accept upper-case digests as well.
encrypt
classmethod
¶
encrypt(*args, **kwds)
Legacy alias for :meth:hash.
.. deprecated:: 1.7
This method was renamed to :meth:!hash in version 1.7.
This alias will be removed in version 2.0, and should only
be used for compatibility with Passlib 1.3 - 1.6.
parsehash
classmethod
¶
parsehash(hash, checksum=True, sanitize=False)
[experimental method] parse hash into dictionary of settings.
this essentially acts as the inverse of :meth:hash: for most
cases, if hash = cls.hash(secret, **opts), then
cls.parsehash(hash) will return a dict matching the original options
(with the extra keyword checksum).
this method may not work correctly for all hashes, and may not be available on some few. its interface may change in future releases, if it's kept around at all.
Parameters:
-
hash–hash to parse
-
checksum–include checksum keyword? (defaults to True)
-
sanitize–mask data for sensitive fields? (defaults to False)
raw
classmethod
¶
raw(secret, user)
encode password using mscash v1 algorithm
Parameters:
-
secret–secret as str or utf-8 encoded bytes
-
user–username to use as salt
Returns:
-
–
returns string of raw bytes
Format & Algorithm¶
Much like lmhash and nthash, MS DCC hashes
consists of a 16 byte digest, usually encoded as 32 hexadecimal characters.
An example hash (of "password" with the account "Administrator") is
25fd08fa89795ed54207e6e8442a6ca0.
The digest is calculated as follows:
- The password is encoded using
UTF-16-LE. - The MD4 digest of step 1 is calculated.
(The result of this step is identical to the
nthashof the password). - The unicode username is converted to lowercase,
and encoded using
UTF-16-LE. This should be just the plain username (e.g.UsernotSOMEDOMAIN\User) - The username from step 3 is appended to the digest from step 2; and the MD4 digest of the result is calculated.
- The result of step 4 is encoded into hexadecimal, this is the DCC hash.
Security Issues¶
This algorithm is should not be used for any purpose besides manipulating existing DCC v1 hashes, due to the following flaws:
-
Its use of the username as a salt value (and lower-case at that), means that common usernames (e.g.
Administrator) will occur more frequently as salts, weakening the effectiveness of the salt in foiling pre-computed tables. -
The MD4 message digest has been severely compromised by collision and preimage attacks.
-
Efficient brute-force attacks on MD4 exist.
References¶
- Description of DCC v1 algorithm - http://openwall.info/wiki/john/MSCash