Passwords CSC 193 WAKE FOREST U N I V E R S I T Y Department of Computer Science Spring 2014 Unix Passwords In Unix, users are identified by user names Authenticated by passwords Therefore to login as a certain user, must know the password Unix never stores the password in cleartext Password is encrypted a then stored A user types in a password, it is then encrypted Encrypted passwords are then compared If the encrypted versions match, then the user is authenticated a Actually hashed, there is a difference. E. W. Fulp CSC 193 Spring 2014 1
A Few Words about Hash... Hashing and encrypting may look similar, but there are differences Both take a string (unencrypted text) and convert it to another string (encrypted) Encryption implies the reverse is possible (can convert encrypted to unencrypted) Hashes are not supposed to be reversible A few qualities we d like with our hash Takes a string and produces a unique string (hash) No reasonable way to map hash back to original string Assuming openssl is installed, here are some examples Command openssl passwd -crypt Astley openssl passwd -crypt astley Output TURHa6genvd8c 1Nrd7lLLWcF8M E. W. Fulp CSC 193 Spring 2014 2 Login and User Accounts Information about the user is stored in two files /etc/passwd and /etc/shadow /etc/passwd stores the following per user, entries are : delineated pluf:x: 500: 100 :Nirre Pluf:/home/pluf:/bin/tcsh }{{}}{{}}{{}}{{}}{{}}{{} user user group user name home shell name ID ID directory userid and groupid will be explained later IDstring is the user s full name homedirectory is the home directory location loginshell is the shell environment E. W. Fulp CSC 193 Spring 2014 3
An example passwd file root:x:0:0:root:/root:/bin/tcsh pluf:x:500:10:nirre Pluf:/home/pluf:/bin/tcsh nomed:x:510:10:nomed Nocaed:/home/nomed:/bin/bash The x (second field) is where the encrypted password used to be stored Passwords are stored in the file /etc/shadow E. W. Fulp CSC 193 Spring 2014 4 Shadow Unix stores encrypted passwords in the /etc/shadow file A shadow password file is readable, only by the superusers and serves to keep encrypted passwords safe from prying eyes and password cracking programs. Therefore access to the encrypted passwords is limited However, if an attacker can obtain a copy, possible to crack E. W. Fulp CSC 193 Spring 2014 5
/etc/shadow The /etc/shadow file contains one line per user root:$1$cqopk7zh$370xdlmegd9m4af/ciilc.:14425:0:99999:7::: bin:*:14425:0:99999:7::: daemon:*:14425:0:99999:7::: Line consists of nine fields separated by colons (:), are as follows 1. Login name 2. Encrypted password 3. Date of last password change 4. Minimum password age 5. Maximum password age 6. Password warning period 7. Password inactivity period 8. Account expiration date 9. Reserved field E. W. Fulp CSC 193 Spring 2014 6 Shadow Example Consider the following line for root user root:$1$cqopk7zh$370xdlmegd9m4af/ciilc.:14425:0:99999:7::: What we can tell is... Login name is root Encrypted password: $1$CQoPk7Zh$370xDLmeGD9m4aF/ciIlC. Date of last password change: 14425, expressed as the number of days since Jan 1, 1970 Minimum password age: 0, how long to wait before password can change, no value (or 0) then no minimum password age Maximum password age: Empty, no maximum password age Password warning period: Empty, no password warning period Password inactivity: Empty, no enforcement of an inactivity period Account expiration date: Empty, the account will never expire E. W. Fulp CSC 193 Spring 2014 7
Encrypted Password Encrypted password has three parts $id$salt$encryptedpassword The $id field identifies the encryption method ID Encryption Method 1 MD5 2a Blowfish (not part of glib, but some Unix distro s include) 5 SHA-256 (since glib 2.7) 6 SHA-512 (since glib 2.7, typically used) The $salt field help prevent precomputed hash attacks Random value added to the password before it is encrypted Salt is stored in plaintext So how does this improve security? E. W. Fulp CSC 193 Spring 2014 8 The last field $encryptedpassword is the encrypted password Consider the $encryptedpassword entry for root again $1$CQoPk7Zh$370xDLmeGD9m4aF/ciIlC. The encryption is MD5 The salt is CQoPk7Zh The encrypted password is 370xDLmeGD9m4aF/ciIlC. Still got questions? No problem, go see http://goo.gl/qmet E. W. Fulp CSC 193 Spring 2014 9
Cracking Passwords Remember passwords are encrypted such that they can t be decrypted To check a password, encrypt provided string and compare hashes So the password is never decrypted So how can someone determine (crack) a password? Guess the password, encrypt it, then compare results (hashes) If hashes match, then you determined the password It s a little more involved than that... 1. Guess password 2. Add salt 3. Encrypt using the same method as the stored password 4. If results (hashes) match, then you did it! Otherwise go to step 1 E. W. Fulp CSC 193 Spring 2014 10 Brute One way to crack passwords is to try all possible passwords Use the algorithm on the previous page Assuming passwords are n characters long and there are c possible characters, how any passwords are possible? Could take some time, so let s write a program to do this for us We d like the program to do the following Take a shadow file (/etc/shadow style) and a guess file (file full o good guesses) as inputs Print a password match, if there is a match... E. W. Fulp CSC 193 Spring 2014 11
Bad Passwrods (things to check for...) Researchers gained access to Pony Botnet and found over 2M compromised accounts and passwords Top Passwords Count 123456 15820 123456789 4875 1234 3135 password 2212 12345 2094 12345678 2045 admin 1991 123 1453 1 1224 1234567 1170 111111 1046 Hopefully you don t use these... E. W. Fulp CSC 193 Spring 2014 12