LS6 - Linux OS Audit & Hardening 4 (Week 3.2)
LS6 - Linux OS Audit & Hardening 4 (Week 3.2)
By the end of this lab, you need to have acquired the following
knowledge and skill set:
• Understand the different files in the linux file system that
governs user account and password settings
• Secure user account and password settings
1
Recap: Key files for user account settings
What do these files contain?
• /etc/passwd - important file containing the list of user account, UID, GID, GECOS, home directory and login.
• /etc/shadow
- Stores the “password hashes” and also allowed password aging and expiration features to be implemented
- The capture below shows the “password hash” for the root account
time
3
Recap: Default User Account Settings upon
Creation
# vi /etc/login.defs
# vi /etc/security/pwquality.conf
See next page for a sample output of
the pwquality.conf file
4
Recap: Password quality control
5
Set Password Expiration Days
Description:
The PASS_MAX_DAYS parameter in /etc/login.defs allows an administrator to force passwords to expire
once they reach a defined age. It is recommended that the PASS_MAX_DAYS parameter be set to less
than or equal to 90 days.
Rationale:
The window of opportunity for an attacker to leverage compromised credentials or successfully
compromise credentials via an online brute force attack is limited by the age of the password. Therefore,
reducing the maximum age of a password also reduces an attacker's window of opportunity.
Verification:
Execute the following command to check whether the system has been configured as required:
# grep ^PASS_MAX_DAYS /etc/login.defs
PASS_MAX_DAYS <number of days>
The <number of days> should be determined by the organisation’s user account policies, in the
absence of which, the auditor should recommend an acceptable standard based on the nature of the
system. If the system is mission critical or holds very important information, this should be as low as 30
days. For other systems, it can be as high as 180 days. A generally acceptable standard is 90 days,
which is also mentioned by the CIS benchmark.
6
Set Password Expiration Days (Cont)
Verification:
Modifying the PASS_MAX_DAYS parameter in /etc/login.defs only affects new user accounts created
and existing accounts which has to change their passwords.
To check that all existing user accounts have been updated to the <number of days>, execute the
following command for each user account in the system:
# chage --list <user account name>
Maximum number of days between password change: <number of days>
Remediation:
If the system is not configured as recommended, set the PASS_MAX_DAYS parameter to <number of
days> in /etc/login.defs:
PASS_MAX_DAYS <number of days>
7
Set Password Change Minimum Number of Days
Description:
The PASS_MIN_DAYS parameter in /etc/login.defs allows an administrator to prevent users from
changing their password until a minimum number of days have passed since the last time the user
changed their password. It is recommended that PASS_MIN_DAYS parameter be set to 7 or more days.
Rationale:
By restricting the frequency of password changes, an administrator can prevent users from repeatedly
changing their password in an attempt to circumvent password reuse controls.
Verification:
Execute the following command to check whether the system has been configured as required:
# grep PASS_MIN_DAYS /etc/login.defs
PASS_MIN_DAYS <number of days>
Similar to PASS_MAX_DAYS setting, the <number of days> should be determined by the
organisation’s user account policies, in the absence of which, the auditor should recommend an
acceptable standard based on the nature of the system. If the system is mission critical or holds very
important information, this should be as high as 15 days. For other systems, it can be as low as 1-2
days. A generally acceptable standard is 7 days, which is also mentioned by the CIS benchmark.
8
Set Password Change Minimum Number of Days
(Cont)
Verification:
Modifying the PASS_MIN_DAYS parameter in /etc/login.defs only affects new user accounts created
and existing accounts which has to change their passwords.
To check that all existing user accounts have been updated to the <number of days>, execute the
following command for each user account in the system:
# chage --list <user account name>
Minimum number of days between password change: <number of days>
Remediation:
If the system is not configured as recommended, set the PASS_MIN_DAYS parameter to <number of
days> in /etc/login.defs:
PASS_MIN_DAYS <number of days>
9
Set Password Expiring Warning Days
Description:
The PASS_WARN_AGE parameter in /etc/login.defs allows an administrator to notify users that their
password will expire in a defined number of days. It is recommended that the PASS_WARN_AGE
parameter be set to 7 or more days.
Rationale:
Providing an advance warning that a password will be expiring gives users time to think of a secure
password. Users caught unaware may choose a simple password or write it down where it may be
discovered.
Verification: Remediation:
# grep PASS_WARN_AGE /etc/login.defs Set the PASS_WARN_AGE parameter to 7 in
PASS_WARN_AGE 7 /etc/login.defs:
10
What are System Accounts?
11
Disable System Accounts
Description:
There are a number of accounts provided with the Red Hat Enterprise Linux that are used to manage
applications and are not intended to provide an interactive shell.
Rationale:
It is important to make sure that accounts that are not being used by regular users are locked to prevent
them from being used to provide an interactive shell. By default, Red Hat sets the password field for
these accounts to an invalid string, but it is also recommended that the shell field in the password file be
set to /sbin/nologin. This prevents the account from potentially being used to run any commands.
It is also important as an IT auditor to know what are the purpose of some of these system accounts. The
table below list some of the common ones and their purpose:
bin bin The bin user/group is included for compatibility with legacy
applications. New applications should no longer use the bin
user/group.
12
Disable System Accounts (cont)
User Group Description
shutdown shutdown Instead of logging on as a regular user and then issuing the
'sudo shutdown' command, simply log in as user "shutdown",
and the login takes care of running the shutdown command
immediately.
halt halt Similar to the shutdown user
13
Disable System Accounts (cont)
User Group Description
uucp uucp Owner of hidden files used by uucp protocol. The uucp user
account is used for the UNIX-to-UNIX Copy Program, which is a
group of commands, programs, and files, present on most Unix
systems, that allows the user to communicate with another Unix
system over a dedicated line or a telephone line.
operator operator Operator special privileges
nobody nobody nobody is the conventional name of a user account which owns
no files, is in no privileged groups, and has no abilities except
those which every other user has. It is common to run daemons
as nobody, especially servers, in order to limit the damage that
could be done by a malicious user who gained control of them.
However, the usefulness of this technique is reduced if more than
one daemon is run like this, because then gaining control of one
daemon would provide control of them all. The reason is that
nobody-owned processes have the ability to send signals to each
other and even debug each other, allowing them to read or even
modify each other's memory.
14
Disable System Accounts (cont’d)
Verification:
Run the following command to determine if any system accounts can be accessed:
# awk -F: '($1!="root" && $1!="sync" && $1!="shutdown" && $1!="halt" && $3<1000 &&
$7!="/sbin/nologin") {print}‘ /etc/passwd
Remediation:
Execute the following commands for each misconfigured system account,
# usermod -L <user name>
# usermod -s /sbin/nologin <user name>
15
Set Default Group for root Account
Description:
The usermod command can be used to specify which group the root user belongs to. This affects
permissions of files that are created by the root user.
Rationale:
Using GID 0 for the root account helps prevent root-owned files from accidentally becoming accessible to
non-privileged users.
Verification: Remediation:
# grep "^root:" /etc/passwd | cut -f4 –d: # usermod -g 0 root
If the command returns “0”, then the system is
correctly configured.
Alternatively, you can run:
# grep “^root:” /etc/passwd
Check that the four field is a value of “0”
16
How is umask value set?
Open 2 terminals and in the first terminal run # vi /etc/profile while in the second terminal run # vi /etc/bashrc
In the first terminal where /etc/profile is shown, look for the line umask=002 and change the value to 077.
Save the file.
17
How is umask value set?
Login again using student and launch the terminal window again.
Type # umask
What value is returned?
https://bencane.com/2013/09/16/understanding-a-little-more-about-etcprofile-and-etcbashrc/
18
Set Default umask for Users
Description:
The default umask determines the permissions of files created by users. The user creating the file has
the discretion of making their files and directories readable by others via the chmod command. Users
who wish to allow their files and directories to be readable by others by default may choose a different
default umask by inserting the umask command into the standard shell configuration files (.profile, .cshrc,
etc.) in their home directories.
Rationale:
Setting a very secure default value for umask ensures that users make a conscious choice about their
file permissions. A default umask setting of 077 causes files and directories created by users to not be
readable by any other user on the system. A umask of 027 would make files and directories readable by
users in the same Unix group, while a umask of 022 would make files readable by every user on the
system.
Verification: Remediation:
# grep "^umask 077" /etc/bashrc Edit the /etc/bashrc and /etc/profile.d/cis.sh files
umask 077 (and the appropriate files for any other shell
supported on your system) and add the
# grep "^umask 077" /etc/profile.d/* following the UMASK parameter as shown:
umask 077 umask 077
19
Ensure Password Fields are Not Empty
Description:
An account with an empty password field means that anybody may log in as that user without providing a
password.
Rationale:
All accounts must have passwords or be locked to prevent the account from being used by an
unauthorized user.
Verification: Remediation:
Run the following command and verify that no If any accounts in the /etc/shadow file do not
output is returned: have a password, run the following command to
# cat /etc/shadow | awk -F: '($2 == "" ) { print $1 " lock the account until it can be determined why
does not have a password "}‘ it does not have a password:
20
Verify No UID 0 Accounts Exist Other Than root
Description:
Any account with UID 0 has superuser privileges on the system.
Rationale:
This access must be limited to only the default root account and only from the system console.
Administrative access must be through an unprivileged account using an approved mechanism such as
su command.
Verification: Remediation:
Run the following command and verify that only the Delete any other entries that are displayed.
word "root" is returned:
# /bin/cat /etc/passwd | /bin/awk -F: '($3 == 0) { print
$1 }‘
root
Alternatively, view the /etc/passwd file and check
that the only “root” has uid “0” [uid is the third field]
21