After the root permission is logged on, the/etc/shadow file is obtained and the text is opened.
Shadow file:
In Linux, the/etc/shadow file stores the user's password hash value.
The ciphertext format of the password stored in shadow is as follows:
$ ID $ salt $ encrypted
Id indicates the hash algorithm used:
The following values are recommended:
Id | Method
--------------------------
1 | MD5
2a | blowfish (not in mainline glibc; added in some
| Linux distributions)
5 | SHA-256 (since glibc 2.7)
6 | SHA-512 (since glibc 2.7)
Salt: it is an interference value that uses the hash algorithm above to hash the password.
Encrypted:
This value is the hash of the password, but it is not a direct Hash ("passwd"), but a hash ("passwd + salt") and then encoded.
Practical application:
1. brute-force cracking (only brute-force cracking) on the premise of shadow files
2. Implement your own passwd command. It is useful in some scenarios (in cloud computing, different passwords can be easily generated for Linux virtual machines using the same template)
Example:
This program uses the crypt function in Linux to generate a password hash that can replace the password hash in the password field in shadow.
# DEFINE _ xopen_source
# Include <stdio. h>
# Include <unistd. h>
// For more information about how to use crypt, see man crypt.
// Exemple:
//./Bin password $6 $ ffffffff
Int main (INT argc, char * argv [])
{
If (argc! = 3)
Return-1;
Char * Buf = crypt (const char *) argv [1], (const char *) argv [2]);
Printf ("salt: % s, crypt: % s \ n", argv [2], Buf );
Return 0;
}
Compilation Method: gcc a. C-lcrypt-O passwd
Use:./passwd 123 \ $6 \ $ abcdefgh
Output:
Salt: $6 $ abcdefgh, crypt: $6 $ abcdefgh $ Encrypt
Use $6 $ abcdefgh $ domains to replace the password domain of the user you want to modify in the shadow file, and the password is automatically changed to 123.
Shadow file format:
See here for details: http://www.tldp.org/HOWTO/Shadow-Password-HOWTO.html
Crypt usage:
See man crypt.
Source http://hi.baidu.com/gzlick/item/fdedea7b45517a2c5d1789e0