9. Linux - PAM and etcpasswd

PAM - Pluggable Authentication modules

https://web.archive.org/web/20220622215926/http://www.linux-pam.org/Linux-PAM-html/Linux-PAM_SAG.html The modules used for this are called pam_unix.so or pam_unix2.so and are located in /usr/lib/x86_x64-linux-gnu/security/ in Debian based distributions.

Manage:

Using passwd calls PAM. pam_unix.so standard module for mgmt and uses standardized API calls from system libraries + files to update acct info. Std files are etc/passwd and /etc/shadow

PAM includes other svc modules, such as LDAP, mount, and Kerberos.

Shadow file: ![](/img/Pasted image 20240810132829.png) If the password field contains a character, such as ! or *, the user cannot log in with a Unix password. However, other authentication methods for logging in, such as Kerberos or key-based authentication, can still be used. The same case applies if the encrypted password field is empty. This means that no password is required for the login. However, it can lead to specific programs denying access to functions. The encrypted password also has a particular format by which we can also find out some information:

As we can see here, the encrypted passwords are divided into three parts. The types of encryption allow us to distinguish between the following:

Algorithm Types

Sha512 is the default enc method on latest linux distros.

Opasswd

PAM library pam_unix.so can prevent reusing old pws. The file where old pws are stored is in /etc/security/opwassd - Admin/root perms required to read this file.

After collecting some hashes we can crack them in different ways -

Cracking linux credentials

Unshadow

sudo cp /etc/passwd /tmp/passwd.bak 
sudo cp /etc/shadow /tmp/shadow.bak 
unshadow /tmp/passwd.bak /tmp/shadow.bak > /tmp/unshadowed.hashes

Hashcat - cracking unshadowed hashes

hashcat -m 1800 -a 0 /tmp/unshadowed.hashes rockyou.txt -o /tmp/unshadowed.cracked

MD5:

hashcat -m 500 -a 0 md5-hashes.list rockyou.txt