This is an old revision of the document!
You may use the UPB's OpenStack cloud to instantiate a Virtual Machine. Read these instructions if you wanna know how!
Hashing is the process of converting data — text, numbers, files, or anything, really — into a fixed-length string of letters and numbers. Data is converted into these fixed-length strings, or hash values, by using a special algorithm called a hash function.
Linux Pluggable Authentication Modules (PAM) is a suite of libraries that allow a Linux system administrator to configure methods to authenticate users.
“pam_exec” is a PAM module that can be used to run an external command.
Multi-factor authentication (MFA) is a multi-step account login process that requires users to enter more information than just a password. For example, along with the password, users might be asked to enter a code sent to their email, answer a secret question, or scan a fingerprint. A second form of authentication can help prevent unauthorized account access if a system password has been compromised.
In the current security lab, we'll explore the fundamentals of Linux authentication.
We'll start by examining how the OS performs hashing. First, we'll crack it and then we'll replicate it using Python.
Then, we'll utilize the “pam_exec” module to set up a custom Python script for user authentication. By exploiting a weak password vulnerability, we will be able to perform a successful login.
Finally, we'll enhance security measures by implementing Multi-Factor Authentication (MFA) with Google Authenticator.
We use Docker:
docker pull ghcr.io/cs-pub-ro/isc-auth-pam:latest mkdir ~/auth-lab docker run --rm --name auth-lab -v $(pwd)/auth-lab/:/home/hacker/auth-lab -it ghcr.io/cs-pub-ro/isc-auth-pam
The ~/auth-lab
folder is used as persistent volume so you won't lose + sync your work inside the container!
Download the lab archive.
Analyse the users and groups on the system. What user are we interested in?
Use John the Ripper to crack our user's password. You need to run it as super user on the file that contains the passwords.
We want to use the default mode “wordlist” with the default location /usr/share/john/password.lst
.
If you are getting an error “No password hashes loaded (see FAQ)”, you need to specify the format of the hash. It is named the same as the Linux password hashing function ;)
References:
Fill in the TODOs in gen_hash.py
to generate a new password hash. Using your super user privileges, manually overwrite the old password of our user.
Test if you were successful by trying to log in using the new password.
References:
As we want to use a Python script to log in to the user account we worked on so far, you need to delete and lock its password so that password-based authentication is disabled for this user account.
Reference:
Modify a single Linux PAM configuration file (look in /etc/pam.d
) by adding a new local rule so that authentication is done using pam_exec.so
and our Python script.
As we want to use the script to authenticate only our special user, and because it will be called for all users, it should be sufficient to authenticate using it, but not required.
In order for authentication to be successfully performed using Python, we need 3 features, which can be achieved by passing the proper options to the pam_exec.so
module:
References:
Open auth.py
and fill in TODOs(6.*).
When you're done, crack the password and try to log in.
Solve the TODOs in setup_mfa.py
and enroll the key in Google Authenticator.
Solve the remaining TODOs(7.*) in auth.py
to integrate MFA.
Getting an error while scanning the QR code? Make sure TOTP_SECRET
is 32 bytes in length ;)
References:
Please take a minute to fill in the feedback form for this lab.