Linux Password Hashes - Technical Overview of Encryption Methods and Cracking Techniques

Onedaysec
4 min read
1 views
docx image 1770017284273 0 49bd63f60c

0x00 Preface

---

In Linux systems, user passwords are encrypted and stored in the /etc/shadow file. What are the encryption methods and cracking techniques for these passwords? This article attempts to organize this topic, introduce related foundational knowledge, test common methods, and help readers gain a more intuitive understanding.

0x01 Introduction

---

This article will cover the following topics:

  • The storage format of user passwords in Linux
  • Encryption methods for user passwords in Linux
  • Common tools and methods for cracking user password hashes

0x02 Storage Format of User Passwords in Linux

---

Linux password information is stored in two files: /etc/passwd and /etc/shadow

/etc/passwd:

Viewable by regular user permissions

Save user information, each line represents a user, each line is divided into seven parts by a colon:

  1. Username
  2. Password, x indicates the password is stored in /etc/shadow
  3. UID, 0 represents root
  4. GID, indicates the group
  5. Description information, in order: Full Name, Room Number, Work Phone, Home Phone, and Other
  6. User home directory
  7. Default shell type

e.g.

test2:x:1001:1001:test2,11111,111111-11,222222-22,test:/home/test2:/bin/bash

  • Username: test2
  • Password stored in /etc/shadow
  • UID is 1001
  • GID is 1001
  • Description information:

Full Name []: test2

Room Number []: 11111

Work Phone []: 111111-11

Home Phone []: 222222-22

Other []: test

  • The user's home directory is /home/test2
  • The default shell is /bin/bash

/etc/shadow:

Only root user privileges can view it

Stores encrypted passwords and related password information for users, each line represents a user, and each line is divided into nine parts by colons:

  1. Username
  2. Encrypted password
  3. Last password change time (total days since 1970.1.1)
  4. Minimum days between password changes, if 0, there is no restriction
  5. Maximum days between password changes, indicating how many days later the user's password will expire, if 99999, there is no restriction
  6. How many days in advance to warn the user that the password will expire
  7. How many days after password expiration to disable this user
  8. User expiration date (total days since 1970.1.1), if 0, the user is permanently available
  9. Reserved

Note:

Parameter description can be obtained via man shadow

eg.

test2:$6$C/vGzhVe$aKK6QGdhzTmYyxp8.E68gCBkPhlWQ4W7/OpCFQYV.qsCtKaV00bToWh286yy73jedg6i0qSlZkZqQy.wmiUdj0:17470:0:99999:7:::

  • Username: test2
  • Encrypted password: $6$C/vGzhVe$aKK6QGdhzTmYyxp8.E68gCBkPhlWQ4W7/OpCFQYV.qsCtKaV00bToWh286yy73jedg6i0qSlZkZqQy.wmiUdj0
  • Last password change time (total days since 1970.1.1 is 17470)
  • Minimum days between password changes: no restriction
  • Maximum days between password changes: no restriction
  • Warn the user 7 days in advance that the password will expire
  • This user is permanently available

As shown in the example, the encrypted password has a fixed format:

$id$salt$encrypted

id indicates the encryption algorithm: 1 for MD5, 5 for SHA-256, 6 for SHA-512

salt refers to the cryptographic Salt, randomly generated by the system

encrypted represents the hash of the password

0x03 Common tools and methods for cracking user password hashes

---

Since Linux password encryption uses Salt, rainbow table attacks are ineffective; common methods are dictionary attacks and brute-force attacks

Common tools for dictionary and brute-force attacks:

1. John the Ripper

(1) Dictionary attack

Kali 2.0 includes John the Ripper

The dictionary file is located at /usr/share/john/password.lst

Using the password list included with John on Kali Linux. The path is /usr/share/john/password.lst

Performing a dictionary attack:

john --wordlist=/usr/share/john/password.lst ./shadow

Note:

Other dictionaries can also be used

(2) Brute-force attack:

john ./shadow

List cracked plaintext passwords:

john --show ./shadow

Result as shown below

(2) Brute-force attack: — technical illustration 1

2. hashcat

Kali 2.0 includes hashcat

Dictionary file uses /usr/share/john/password.lst

Modify hash format: retain only $salt$encrypted

e.g.

Original hash:

test2:$6$C/vGzhVe$aKK6QGdhzTmYyxp8.E68gCBkPhlWQ4W7/OpCFQYV.qsCtKaV00bToWh286yy73jedg6i0qSlZkZqQy.wmiUdj0:17470:0:99999:7:::

Modified:

$6$C/vGzhVe$aKK6QGdhzTmYyxp8.E68gCBkPhlWQ4W7/OpCFQYV.qsCtKaV00bToWh286yy73jedg6i0qSlZkZqQy.wmiUdj0

(1) Dictionary Attack:

hashcat -m 1800 -o found1.txt --remove shadow /usr/share/john/password.lst

Parameter Description:

-m: hash-type, 1800 corresponds to SHA-512

Detailed parameters can be found in the table: https://hashcat.net/wiki/doku.php?id=example_hashes

-o: output file

--remove: indicates the hash will be removed from the hash file after being cracked

shadow: represents the hash file

/usr/share/john/password.lst: represents the dictionary file

Successfully cracked 2 hashes, as shown in the figure below

(1) Dictionary Attack: — technical illustration 2

(2) Brute Force Attack:

hashcat -m 1800 -a 3 -o found2.txt shadow ?l?l?l?l --force

Parameter description:

-a: attack-mode, default is 0, 3 represents Brute-force, i.e., brute force attack

?l: represents lowercase letters, i.e., abcdefghijklmnopqrstuvwxyz, 4 ?l indicates the brute force attack length is 4

?u: represents uppercase letters, i.e., ABCDEFGHIJKLMNOPQRSTUVWXYZ

?h: represents lowercase hexadecimal characters, i.e., 0123456789

?H: represents uppercase hexadecimal characters, i.e., 0123456789abcdef

?s: represents special symbols, i.e., !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

?a: represents all characters, i.e., ?l?u?d?s

?b: represents hexadecimal, i.e., 0x00 - 0xff

Successfully brute-forced the hash, result as shown in the figure below

(2) Brute Force Attack: — technical illustration 3

3、Online websites

1.https://hce.iteknical.com/

HCE distributed computing platform, requires points to use

2.http://www.cmd5.com/

Currently does not support SHA-512

4. mimipenguin

Download link:

https://github.com/huntergregal/mimipenguin

Similar to mimikatz in principle, extracts plaintext passwords from memory

0x04 Summary

---

This article introduced password storage formats in Linux and tested two common tools: John the Ripper and hashcat, using dictionary and brute-force cracking methods respectively.

As an article summarizing foundational knowledge, we aimed to be as concise and practical as possible. Reader feedback is welcome, and this content will continue to be refined in the future.

Related Questions & Answers

What is mimipenguin and how does it relate to extracting Linux passwords?

Mimipenguin is a tool that extracts plaintext passwords from a Linux system's memory, similar to how Mimikatz works on Windows for [Windows password hashes](/news/introduction-to-windows-password-hashes-ntlm-hash-and-net-ntlm-hash). It targets processes like SSH or GNOME keyring to retrieve credentials without needing to crack the hash. This technique bypasses hash cracking entirely, as explained in the [Linux Password Hashes article](/news/linux-password-hashes-technical-overview-of-encryption-methods-and-cracking-techniques).

What tools and methods are commonly used to crack Linux password hashes?

Common tools include John the Ripper and hashcat, both available on Kali Linux. Cracking methods are primarily dictionary attacks (using a wordlist like `/usr/share/john/password.lst`) and brute-force attacks that iterate through character combinations. For example, hashcat uses `-m 1800` for SHA-512 hashes and `-a 3` for brute-force. John the Ripper can also automatically detect the hash type. Full command examples are provided in the [Linux Password Hashes article](/news/linux-password-hashes-technical-overview-of-encryption-methods-and-cracking-techniques).

Why are rainbow table attacks ineffective against Linux password hashes?

Rainbow tables rely on precomputed hash tables for unsalted passwords. Linux password hashes include a unique, random salt for each user, which alters the final hash even if two users share the same password. This salt renders precomputed tables useless, forcing attackers to use dictionary or brute-force attacks. The [Linux Password Hashes article](/news/linux-password-hashes-technical-overview-of-encryption-methods-and-cracking-techniques) explains how the salt is embedded in the hash format (e.g., `$6$C/vGzhVe$`).

How are Linux user passwords stored and what is the format in the /etc/shadow file?

Linux user passwords are encrypted and stored in the `/etc/shadow` file, which is only readable by root. Each hash follows the format `$id$salt$encrypted`, where `id` indicates the algorithm (1=MD5, 5=SHA-256, 6=SHA-512), `salt` is a random value, and `encrypted` is the salted hash. The `/etc/passwd` file stores other user info but uses an `x` to indicate the password is in shadow. For a detailed breakdown of all fields, see the [Linux Password Hashes article](/news/linux-password-hashes-technical-overview-of-encryption-methods-and-cracking-techniques).

Continue Reading