| 1 |
Windows 2k/NT/XP's syskey encryption |
| 2 |
|
| 3 |
Syskey is a Windows feature that adds an additional encryption layer |
| 4 |
to the password hashes stored in the SAM database. The main purpose of |
| 5 |
this feature is to deter 'offline' attack. In fact one of the most |
| 6 |
common ways to gather passwords is to copy the system SAM database and |
| 7 |
then use one of the many good password crackers[1] to "recover" the |
| 8 |
passwords; of course physical access is almost always required. |
| 9 |
|
| 10 |
So with syskey the attacker needs to remove the additional encryption |
| 11 |
layer to get the password hashes (this is not entirely true as some |
| 12 |
tools can crack even syskeyed hashes while losing some performance). |
| 13 |
|
| 14 |
The key used by Syskey to encrypt the password hashes (called bootkey |
| 15 |
or system key) can be generated and stored in three ways. The method |
| 16 |
to use is selected when running syskey.exe on the host. |
| 17 |
|
| 18 |
1) Using a user supplied passphrase(actually the MD5 hash of it). The |
| 19 |
system will prompt for the passphrase during startup. |
| 20 |
|
| 21 |
2) Using a system generated key stored on a floppy. The system will |
| 22 |
ask for the boot floppy during startup. |
| 23 |
|
| 24 |
3) Using a system generated key stored on the "the local system using |
| 25 |
a complex obfuscation algorithm" (citing Microsoft site[2]). This is |
| 26 |
the default method used. |
| 27 |
|
| 28 |
In the first two cases generally nothing can be done. If you cannot |
| 29 |
get the passphrase or the boot floppy you are compelled to crack the |
| 30 |
syskeyed hashes. |
| 31 |
|
| 32 |
The last case is different. |
| 33 |
|
| 34 |
This document describe the "complex obfuscation algorithm" and the |
| 35 |
steps required to restore the password hashes from their syskeyed |
| 36 |
equivalent. Some tools are also presented to automate the process. |
| 37 |
|
| 38 |
From now on we will talk about the case when the bootkey is stored on |
| 39 |
the system. |
| 40 |
|
| 41 |
During Windows boot phase before user are allowed to logon to the |
| 42 |
system, the main thread of Smss (Session Manager) starts the Winlogon |
| 43 |
process. Winlogon is the process required to load the Local Security |
| 44 |
Subsystem (Lsass) which in turn loads the Security Accounts Manager |
| 45 |
(SAM) service (the interface to the SAM database). |
| 46 |
|
| 47 |
The registry is accessed by the above-mentioned processes. In |
| 48 |
particular the following keys are accessed: |
| 49 |
|
| 50 |
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\JD |
| 51 |
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Skew1 |
| 52 |
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\Data |
| 53 |
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\GBG |
| 54 |
|
| 55 |
The same keys are also accessed during the bootkey generation phase by |
| 56 |
the Syskey.exe tool. |
| 57 |
|
| 58 |
A more in depth analysis of the code accessing these keys uncover that |
| 59 |
the "complex obfuscation algorithm" is no more than a permutation of |
| 60 |
the class name of the above-mentioned keys. |
| 61 |
|
| 62 |
Is almost trivial to develop a tool to recover the syskey obfuscated |
| 63 |
bootkey from the registry. |
| 64 |
|
| 65 |
To make things simpler on pre SP4 system the ACL on the above keys |
| 66 |
allows 'Users' read access so a "normal" user can retrieve the |
| 67 |
registry stored bootkey. |
| 68 |
|
| 69 |
The tool developed to make this operation is called Bkreg. |
| 70 |
|
| 71 |
On SP4+ system it is still possible to recover the syskey bootkey. The |
| 72 |
ACLs on the keys only allow Administrator access, so Bkreg can recover |
| 73 |
the bootkey on SP4 system only if executed by the Administrator. |
| 74 |
|
| 75 |
But there is another way to access the registry keys. |
| 76 |
|
| 77 |
An attacker can steal (maybe at the same time of the SAM database) the |
| 78 |
system hive and access from there the above mentioned keys to recover |
| 79 |
the syskey bootkey. |
| 80 |
|
| 81 |
The tool developed to make this operation is called Bkhive. |
| 82 |
|
| 83 |
Now we have the bootkey, conveniently stored in a file, and the SAM |
| 84 |
hive; we need to know how to remove the syskey encryption. |
| 85 |
|
| 86 |
The process that decrypts the password hashes (using the bootkey) is |
| 87 |
Samss. |
| 88 |
|
| 89 |
The steps required to do so are: |
| 90 |
|
| 91 |
1) The value 'F' of the registry key SAM\SAM\Domains\Account is |
| 92 |
accessed. The contents of that value is of binary type. 16 byte |
| 93 |
(starting at offset 0x70) from the F value are hashed (MD5) with the |
| 94 |
bootkey and some constant. The result is used as the key to decrypt |
| 95 |
(RC4) the 32 byte of the F value (starting from 0x80). |
| 96 |
The first 16 byte of the result are used later in the algorithm. I |
| 97 |
call them hbootkey. |
| 98 |
|
| 99 |
2) For each rid subkey in SAM\SAM\Domains\Account\Users. The value 'V' |
| 100 |
of the key is accessed. The content of that value is of binary type |
| 101 |
and contain the syskey encrypted password hashes. The hbootkey |
| 102 |
(computed in step 1), the user rid and a constant string( different if |
| 103 |
decoding NT or lanman password) are hashed (MD5). The result is used |
| 104 |
as the key to decrypt (RC4) the syskeyed password hashes. |
| 105 |
|
| 106 |
So syskey encrypts the password hashes with the RC4 algorithm using as |
| 107 |
key "something" derived (through MD5) from the syskey bootkey. |
| 108 |
|
| 109 |
I've developed a tool to automate the above steps and include the |
| 110 |
features of SAMDUMP. The tool is called SAMDUMP2; SAMDUMP2 can, when |
| 111 |
given a SAM hive and a bootkey file (generated by Bkreg or Bkhive), |
| 112 |
output the password hashes in SAMDUMP/PWDUMP format. |
| 113 |
|
| 114 |
So an attacker with physical access can: |
| 115 |
|
| 116 |
0) Boot using another OS (maybe Linux or DOS) |
| 117 |
1) Steal the SAM and SYSTEM hive (from %WINDIR%\System32\config) |
| 118 |
2) Recover the syskey bootkey from the SYSTEM hive using Bkhive (or |
| 119 |
Bkreg on pre Sp4 system) |
| 120 |
3) Dump the password hashes using SAMDUMP2 |
| 121 |
4) Crack them offline using his favorite cracking tool |
| 122 |
|
| 123 |
References |
| 124 |
[1] http://www.atstake.com/products/lc/ |
| 125 |
http://www.oxid.it/cain.html |
| 126 |
http://www.openwall.com/john/ |
| 127 |
http://www.openwall.com/passwords/nt.shtml |
| 128 |
[2] http://support.microsoft.com/support/kb/articles/q143/4/75.asp |
| 129 |
|
| 130 |
|
| 131 |
Nicola Cuomo ncuomo(at)studenti.unina.it |
| 132 |
|
| 133 |
Many thanks to Jason R. DePriest for 'patching' my english ^_^ |