Linux Local Password Attacks
Credential Hunting in Linux
Hunting for credentials is one of the first steps once we have access to the system. These low-hanging fruits can give us elevated privileges within seconds or minutes. Among other things, this is part of the local privilege escalation process that we will cover here. However, it is important to note here that we are far from covering all possible situations and therefore focus on the different approaches.
Common sources of credentials:
|
|
|
|
Configs | Logs | Cache | Browser stored credentials |
Databases | Command-line History | In-memory Processing | |
Notes | |||
Scripts | |||
Source codes | |||
Cronjobs | |||
SSH Keys |
Files
We should look for, find, and inspect several categories of files one by one. These categories are the following:
Configuration files | Databases | Notes |
---|---|---|
Scripts | Cronjobs | SSH keys |
There are many methods to find these configuration files, and with the following method, we will see we have reduced our search to these three file extensions.
In this example, we search for three words (user
, password
, pass
) in each file with the file extension .cnf
.
We can apply this simple search to the other file extensions as well. Additionally, we can apply this search type to databases stored in files with different file extensions, and we can then read those.
Sometimes there's notes taken by the administrators or users in generic files with arbitrary extensions, commonly .txt
or no extension at all
Scripts are files that often contain highly sensitive information and processes. Among other things, these also contain credentials that are necessary to be able to call up and execute the processes automatically. Otherwise, the administrator or developer would have to enter the corresponding password each time the script or the compiled program is called.
Cronjobs
SSH Keys
Private keys
Public keys
History
In the history of the commands entered on Linux distributions that use Bash as a standard shell, we find the associated files in .bash_history
. Nevertheless, other files like .bashrc
or .bash_profile
can contain important information.
Logs
Application Logs | Event Logs | Service Logs | System Logs |
Log File | Description |
| Generic system activity logs. |
| Generic system activity logs. |
| (Debian) All authentication related logs. |
| (RedHat/CentOS) All authentication related logs. |
| Booting information. |
| Hardware and drivers related information and logs. |
| Kernel related warnings, errors and logs. |
| Failed login attempts. |
| Information related to cron jobs. |
| All mail server related logs. |
| All Apache related logs. |
| All MySQL server related logs. |
SOME checks on those files:
Memory and Cache
Many applications and processes work with credentials needed for authentication and store them either in memory or in files so that they can be reused.
For example, it may be the system-required credentials for the logged-in users. Another example is the credentials stored in the browsers, which can also be read. In order to retrieve this type of information from Linux distributions, there is a tool called mimipenguin that makes the whole process easier. However, this tool requires administrator/root permissions.
n even more powerful tool we can use that was mentioned earlier in the Credential Hunting in Windows section is LaZagne
.
This tool allows us to access far more resources and extract the credentials. The passwords and hashes we can obtain come from the following sources but are not limited to:
Wifi | Wpa_supplicant | Libsecret | Kwallet |
---|---|---|---|
Chromium-based | CLI | Mozilla | Thunderbird |
Git | Env_variable | Grub | Fstab |
AWS | Filezilla | Gftp | SSH |
Apache | Shadow | Docker | KeePass |
Mimipy | Sessions | Keyrings |
Browsers
Browsers store the passwords saved by the user in an encrypted form locally on the system to be reused. For example, the Mozilla Firefox
browser stores the credentials encrypted in a hidden folder for the respective user. These often include the associated field names, URLs, and other valuable information.
The tool Firefox Decrypt is excellent for decrypting these credentials, and is updated regularly. It requires Python 3.9 to run the latest version. Otherwise, Firefox Decrypt 0.7.0
with Python 2 must be used.
Alternatively, LaZagne
can also return results if the user has used the supported browser.
Passwd, Shadow & Opasswd
Linux-based distributions can use many different authentication mechanisms. One of the most commonly used and standard mechanisms is Pluggable Authentication Modules (PAM
). 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.
The standard files that are read, managed, and updated are /etc/passwd
and /etc/shadow
. PAM also has many other service modules, such as LDAP, mount, or Kerberos.
/etc/passwd
It can also be that the /etc/passwd
file is writeable by mistake. This would allow us to clear this field for the user root
so that the password info field is empty. This will cause the system not to send a password prompt when a user tries to log in as root
.
/etc/shadow
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Username | Encrypted password | Last PW change | Min. PW age | Max. PW age | Warning period | Inactivity period | Expiration date | Unused |
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:
$<type>$<salt>$<hashed>
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
$1$
– MD5$2a$
– Blowfish$2y$
– Eksblowfish$5$
– SHA-256$6$
– SHA-512
Opasswd
The PAM library (pam_unix.so
) can prevent reusing old passwords. The file where old passwords are stored is the /etc/security/opasswd
.
Administrator/root permissions are also required to read the file if the permissions for this file have not been changed manually.
Cracking Linux Credentials
or to crack md5 hashes (just the hashes in a list):
Last updated