







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








This section describes how passwords are implemented inside the Unix operating system for both locally administered and network-based systems.
Traditionally, Unix uses the /etc/passwd file to keep track of every user on the system. The /etc/passwd file contains the username, real name, identification in- formation, and basic account information for each user. Each line in the file con- tains a database record; the record fields are separated by a colon (:).
You can use the cat command to display your system’s /etc/passwd file. Here are a few sample lines from a typical file:
root:x:0:1:System Operator:/:/bin/ksh daemon:x:1:1::/tmp: uucp:x:4:4::/var/spool/uucppublic:/usr/lib/uucp/uucico rachel:x:181:100:Rachel Cohen:/u/rachel:/bin/ksh arlin:x.:182:100:Arlin Steinberg:/u/arlin:/bin/csh
The first three accounts, root, daemon, and uucp, are system accounts, while rachel and arlin are accounts for individual users.
SIGN IN TRY NOW
The individual fields of the /etc/passwd file have fairly straightforward meanings. Table 4-1 explains a sample line from the file shown above.SIGN IN^ TRY NOW
Passwords were traditionally stored in the /etc/passwd file in an encrypted format (hence the file’s name). However, because of advances in processor speed, en- crypted passwords are now almost universally stored in separate shadow pass- word file s, which are described later.
The meanings of the UID and GID fields are described in Chapter 5.
When Unix requests your password, it needs some way of determining that the password you type is the correct one. Many early computer systems (and quite a few still around today!) kept the passwords for all of their accounts plainly visible in a so-called “password file” that contained exactly that—passwords. Under nor- mal circumstances, the system protected the passwords so that they could be ac- cessed only by privileged users and operating system utilities. But through acci- dent, programming error, or deliberate act, the contents of the password file could occasionally become available to unprivileged users. This scenario is illus- trated in the following remembrance:
Perhaps the most memorable such occasion occurred in the early 1960s when a sys- tem administrator on the CTSS system at MIT was editing the password file and an- other system administrator was editing the daily message that is printed on everyone’s terminal on login. Due to a software design error, the temporary editor files of the two users were interchanged and thus, for a time, the password file was printed on every terminal when it was logged in.
—Robert Morris and Ken Thompson, “Password Security: A Case History” Communic- ations of the ACM, November 1979.
The real danger posed by such systems, explained Morris and Thompson, is not that software problems might someday cause a recurrence of this event, but that people can make copies of the password file and purloin them without the know- ledge of the system administrator. For example, if the password file is saved on backup tapes, then those backups must be kept in a physically secure place. If a backup tape is stolen, then everybody’s password needs to be changed.
Unix avoids this problem by not keeping actual passwords anywhere on the sys- tem. Instead, Unix stores a value that is generated by using the password to en-
SIGN IN TRY NOW
crypt a block of zero bits with a one-way function called crypt( ) ; the result of the calculation was traditionally stored in the /etc/passwd file.[41]^ When you try to log in, the program /bin/login does not decrypt the stored password. Instead, /bin/login takes the password that you typed, uses it to transform another block of zeros, and compares the newly transformed block with the block stored in the /etc/passwd file. If the two encrypted results match, the system lets you in.
The security of this approach rests upon the strength of the encryption algorithm and the difficulty of guessing the user’s password. To date, the crypt ( ) algorithm and its successors have proven highly resistant to attacks. Unfortunately, users have a habit of picking easy-to-guess passwords, which creates the need for shadow password files.
The algorithm that traditional crypt( ) uses is based on the Data Encryption Stand- ard (DES) of the National Institute of Standards and Technology (NIST). In normal operation, DES uses a 56-bit key (8 7-bit ASCII characters, for instance) to en- crypt blocks of original text, or cleartext , that are 64 bits in length. The resulting 64-bit blocks of encrypted text, or ciphertext , cannot easily be decrypted to the original cleartext without knowing the original 56-bit key.
The Unix crypt( ) function takes the user’s password as the encryption key and uses it to encrypt a 64-bit block of zeros. The resulting 64-bit block of ciphertext is then encrypted again with the user’s password; the process is repeated a total of 25 times. The final 64 bits are unpacked into a string of 11 printable characters that are stored in the shadow password file.[42]
Don’t confuse the crypt( ) algorithm with the crypt encryption program. The crypt program uses a different encryption system from crypt( ) and is very easy to break. See Chapter 7 for more details.
Although the source code to crypt( ) is readily available, no technique has been discovered (or publicized) to translate the encrypted password back into the ori- ginal password. Such reverse translation may not even be possible. As a result,
SIGN IN TRY NOW
bit number, between 0 and 4,095, which slightly changes the result of the DES function. Each of the 4,096 different salts makes a password encrypt a different way.
When you change your password, the /bin/passwd program selects a salt based on the time of day. The salt is converted into a two-character string and is stored in the /etc/passwd file along with the encrypted “password.”[43]^ In this manner, when you type your password at login time, the same salt is used again. Unix stores the salt as the first two characters of the encrypted password.
Table 4-2 shows how a few different words encrypt with different salts.
Table 4-2. Passwords and salts
Password Salt Encrypted password
nutmeg Mi MiqkFWCm1fNJI
ellen1 ri ri79KNd7V6.Sk
Sharon ./ ./2aN7ysff3qM
norahs am amfIADT2iqjAf
norahs 7a 7azfT5tIdyh0I
Notice that the last password, norahs, was encrypted two different ways with two different salts. As a side effect, the salt makes it possible for a user to have the same password on a number of different computers and to keep this fact a secret (usually), even from somebody who has access to the /etc/passwd files on
SIGN IN TRY NOW
all of those computers; two systems would not likely assign the same salt to the user, thus ensuring that the encrypted password field is different.[44]
ON THE IMPORTANCE OF ENCRYPTED PASSWORDS ON THE IMPORTANCE OF ENCRYPTED PASSWORDS Alec Muffett, the author of the Crack program (discussed in Table 19-1), related an entertaining story to us about the reuse of passwords in more than one place, which we paraphrase here. A student friend of Alec’s (call him Bob) spent a co-op year at a major computer company site. During his vacations and on holidays, he’d come back to school and play AberMUD (a network-based game) on Alec’s computer. One of Bob’s responsibilities at the company involved system management. The company was concerned about security, so all passwords were random strings of letters with no sensible pattern or order. One day, Alec fed the AberMUD passwords into his development version of the Crack program as a dic- tionary, because they were stored on his machine as plaintext. He then ran this file against his system user-password file, and found a few student account passwords. He had the students change their pass- words, and he then forgot about the matter. Some time later, Alec posted a revised version of the Crack program and associated files to the Usenet. They ended up in one of the Usenet sources newsgroups and were distributed quite widely. Eventually, after a trip of thousands of miles around the world, they came to Bob’s company. Bob, being a concerned administrator, decided to download the files and check them against his company’s passwords. Imagine Bob’s shock and horror when the widely distributed Crack promptly churned out a match for his randomly chosen, super-secret root password! The moral of the story is that you should teach your users never to use their account passwords for other purposes—such as games or web sites. They never know when those passwords might come back to haunt them! For developers, the moral is that all programs—even games—should store passwords encrypted with one-way hash functions.
In recent years the security provided by the salt has diminished significantly. Hav- ing a salt means that the same password can encrypt in 4,096 different ways. This makes it much harder for an attacker to build a reverse dictionary for trans- lated encrypted passwords back into her unencrypted form: to build a reverse dictionary of 100,000 words, an attacker would need to have 409,600, entries. But with 8-character passwords and 13-character encrypted passwords, 409,600,000 entries fit in roughly 8 GBs of storage.
Another problem with the salt was an error in implementation: many systems se- lected which salt to use based on the time of day, which made some salts more likely than others.
SIGN IN TRY NOW
Table 4-3. The modular crypt format
Field Purpose Notes
#1 Specifies encryption al- gorithm to use
1 specifies MD5.2 specifies Blowfish.
#2 Salt Limited to 16 characters.
#3 Encrypted password Does not include salt, unlike traditional Unix crypt( ) function.
Although changes to the encrypted password system (as described in the previ- ous section) have improved the security of encrypted passwords, they have failed to fundamentally address the weakness exploited by password crackers: people pick passwords that are easy to guess. If an attacker can obtain a copy of the password file, it is a simple matter to guess passwords, perform the encryption transform, and compare against the file.
Ultimately, the best way to deal with the problem of poorly-chosen passwords is to eliminate reusable passwords entirely by using one-time passwords, some form of biometrics, or a token-based authentication system. Because such sys- tems can be awkward or expensive, modern Unix systems have adopted a second approach called shadow password files or master password files.
As the name implies, a shadow password file is a secondary password file that shadows the primary password file. On Solaris and Linux systems, the shadow password is usually stored in the file /etc/shadow and contains the encrypted password and a password expiration date. The /etc/shadow file is protected so that it can be read only by the superuser. Thus, an attacker cannot obtain a copy to use in verifying guesses of passwords.
SIGN IN TRY NOW
Instead of a shadow password file, FreeBSD uses a master password file. This file, /etc/master.passwd, is a complete password file that includes usernames, pass- words, and other account information. The /etc/passwd file is identical to the /etc/master.passwd file, except that all encrypted passwords have been changed to the letter “x”.
Mac OS X stores all account information in the NetInfo network-based account management system. Mac OS X does this for all computers, even for standalone computers that are never placed on a network. The version of NetInfo that is sup- plied in Mac OS 10.0 and 10.1 does not provide for shadow passwords, although the /etc/master.passwd file is present and is used during boot-up.
The most effective way to minimize the danger of bad passwords is not to use conventional passwords at all. Instead, your site can install software and/or hard- ware to allow one-time passwords. A one-time password is exactly that—a pass- word that is used only once.
There are two popular techniques for implementing one-time passwords:
Hardware tokens An example is the RSA SecureID card, which displays a new PIN or password for each login. Some token-based systems display a differ- ent code every minute. Other token-based systems look like little calculators. When you attempt to log in you are presented with a challenge. You type this challenge into your calculator, type in your personal identification number, and then type the resulting number that is displayed into the computer.
Codebooks These list valid passwords. Each password is crossed off the list after it is used. S/Key is a popular codebook system.[45]
SIGN IN TRY NOW
Public key authentication systems have two fundamental problems. The first problem is the management of private keys. Private keys must be kept secure at all costs. Typically, private keys are encrypted with a passphrase to protect them, but all of the caveats about choosing a good password (and not transmitting it where others can eavesdrop) apply.
The second problem is the certification of public keys. If an attacker can substi- tute his public key for someone else’s (or for that of a server to which you wish to connect) all your communication will be visible to the attacker. One solution to this problem is to use a secure channel to exchange public keys. With the Secure Shell (ssh), the public key is merely copied to the remote system (after logging in with a password or another non-public key method) and put into a file in the user’s home directory called ~/.ssh/authorized_keys.
A more sophisticated technique for distributing public keys involves the creation of a public key infrastructure (PKI). A group of users and system administrators could all certify their keys to one another in person, or each could have his own key certified by a common person or organization that everyone trusts to verify the identities associated with the keys. SSL, the Secure Socket Layer, provides transparent support for PKI.
[41] (^) These days, the encrypted password is stored either in the shadow password file or on a network-based server, as we’ll see in a later section. [42] (^) Each of the 11 characters holds six bits of the result, represented as one of 64 characters in the set “.”, “/”, 0-9, A-Z, a-z, in that order. Thus, the value 0 is represented as “.”, and 32 is the letter “U”. [43] (^) By now, you know that what is stored in the /etc/passwd file is not really the encrypted password. However, everyone calls it that, and we will do the same from here on. Otherwise,tributing to the premature we’ll need to keep typing “the demise of yet more trees. superencrypted block of zeros that is used to verify the user’s password” everywhere in the book, filling many extra pages and con-
[44] (^) This case occurs only when the user actually types in his password on the second computer. Unfortunately, in practice, system administrators commonly cut and paste /etc/passwdon more than entries from one computer to another one system. when they build accounts for users on new computers. As a result, others can easily tell when a user has the same password
[45] (^) More correctly, it is a one-time pad and not a codebook.
SIGN IN TRY NOW