ShareWiz Ultra Secure Server Setup

User Security

user

Root Account

Disable the root account

User management is a critical part of maintaining a secure system. Ineffective user and privilege management often lead many systems into being compromised. Therefore, it is important that you understand how you can protect your server through simple and effective user account management techniques.

top

Disable the root account

The root account should be disabled by default, but if not issue the following command:

sudo usermod -p ‘!’ root

By default, the root account is disabled on Ubuntu. To run anything as the root user one needs to place the command sudo before the issued command.

The root account has superuser permissions. The superuser can do almost anything on the system, which could be dangerous, as an incorrectly typed command could destroy the system.

Ideally, when a user logs onto the system they should only have sufficient privileges needed for the task at hand.

By the way, if you want to enable the root account (which is not recommended) enter the following command:

sudo passwd root

An alternative approach to disable root is to lock the account using the command:

sudo passwd –l root

top

Root notification

Edit .bashrc under /root to get notified by email when someone logs in as root.

Issue the following command:

sudo vi /root/.bashrc

and add the following to the bottom of the file:

echo 'ALERT - Root Shell Access ('`hostname`') on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 |

cut -d")" -f1`" sysadmin@sharewiz.net

echo -e "Root Shell Access on `tty` \n `w`" | mail -s "Alert: Root Access" sysadmin@sharewiz.net

top

Only allow admin users to use "su"

This helps prevent privilege escalation. By default, Ubuntu does not have an admin group.

Issue the following command to create an admin group:

sudo usermod -a -G admin peter

Add additional users to the admin group, by repeating the above command for each user.

Restrict access to /bin/su to admin group members:

sudo dpkg-statoverride --update --add root admin 4750 /bin/su

This only allows members of the admin group to run su.

This can also be achieved with:

sudo chown root:admin /bin/su

sudo chmod 4750 /bin/su

Check permissions for /bin/su with:

sudo ls -lh /bin/su

…should show something like the following:

-rwsr-xr-x 1 root root 36K Apr 9 02:32 /bin/su

top

Set sudo permissions

Issue the following command:

sudo visudo

and populate the file as follows:

Defaults env_reset

Defaults timestamp_timeout=0

Defaults logfile=/var/log/sudo

 

# Host alias specification

 

# User alias specification

User_Alias SYSADMIN = %SHAREWIZ\\SWAdmin

User_Alias SEC_ADMIN = SHAREWIZ\\peter

 

# Cmnd alias specification

Cmnd_Alias KILL = /bin/kill

Cmnd_Alias PRINTING = /usr/sbin/lpc, /usr/bin/lprm

#Cmnd_Alias SHUTDOWN = /sbin/shutdown

#Cmnd_Alias HALT = /sbin/halt

Cmnd_Alias REBOOT = /sbin/reboot

Cmnd_Alias SHELLS = /bin/bash, /bin/sh, /bin/csh, /bin/ksh, \

/bin/tcsh, /bin/rsh, /bin/zsh, /bin/dash

Cmnd_Alias SU = /bin/su

Cmnd_Alias SUDOERS = /usr/sbin/visudo

Cmnd_Alias PAGERS = /bin/more, /bin/pg, /bin/less

Cmnd_Alias ADMIN = /etc/init.d/, /usr/bin/, /bin/, /usr/sbin/, /sbin/, /sharewiz/

 

# User privilege specification

# root ALL = (ALL) ALL

 

# Members of the admin group may gain root privileges

%admin ALL = (ALL) ADMIN, !SHELLS, !SU, SUDOERS, KILL, REBOOT, PAGERS, PRINTING

 

# Members of the SHAREWIZ domain that may gain root privileges

SYSADMIN ALL = (ALL) ADMIN, !SHELLS, !SU, !SUDOERS, KILL, REBOOT, PAGERS, PRINTING

SEC_ADMIN ALL = SUDOERS

The above settings remove super access from the root user. It also sets that the only users allowed to edit the sudoers file are members of the admin account, and the Active Directory user peter.

If Active Directory is not going to be used as part of the network, then remove those lines from the above file.

visudo is used to edit the sudoers file in a safe fashion. visudo locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks for parse errors.

The line Defaults timestamp_timeout=0 states that sudo will always ask for a password, and will no longer remember it for 15 minutes.

top

Check that only Root has UID 0

Issue the following command:

sudo awk -F':' '{if($3=="0") print $1}' /etc/passwd

which should show any accounts that have UID of 0.

Deactivate any account besides root by issuing the following command:

sudo usermod -s /bin/false -L --expiredate 1 <account>

Replace <account> with the actual account name.

Only root should have the UID 0. Any other account with that UID is often synonymous with a backdoor.

top

User Accounts

Secure the default user profile

When a new user is created, using a command such as sudo adduser username the users's profile is modeled after the contents found in the directory of /etc/skel.

Modify the contents of the /etc/skel directory as required to ensure consistant security for all users.

top

Allow colour prompts for standard users

Issue the following command:

sudo vi /etc/skel/.bashrc

and remove the hash from the begin of the force_color_prompt line:

force_color_prompt=yes

This follows on from the previous setting of securing the default user profile.

When a new user is created, using a command such as sudo adduser username the users's profile is modeled after the contents found in the directory of /etc/skel.

Modifying the /etc/skel/.bashrc file as indicated will result in all future users being added to the system having colour prompts enabled.

top

Secure bash history

Issue the following commands within every user’s home directory:

sudo chattr +a .bash_history

sudo chattr +i .bash_history

These commands prevent the .bash_history file being deleted or renamed. It also appends all commands issued by the user to the file, allowing full auditing to take place.

Let your users know that their history is being logged and they will have to agree before they use your services.

top

Check for empty passwords

Issue the following command:

sudo awk -F':' '{if($2=="") print $1}' /etc/shadow

which should show any accounts with no password set.

Deactivate these accounts by issuing the following command:

sudo usermod -s /bin/false -L --expiredate 1 <account>

Replace <account> with the actual account name.

Having the option --expiredate 1 sets the account´s expiry date to Jan 2, 1970.

top

Create the PAM configuration file for passwdqc

Create a PAM configuration file for passwdqc by issuing the following command:

sudo vi /usr/share/pam-configs/passwdqc

and populate it with the following:

Name: passwdqc password strength checking

Default: yes

Priority: 1024

Conflicts: cracklib [maybe?]

Password-Type: Primary

Password:

  requisite pam_passwdqc.so min=disabled,10,8,8,8 similar=deny enforce=users ask_oldauthtok check_oldauthtok

Now issue the command:

sudo pam-auth-update

and ensure that the passwdqc password strength checking is enabled.

passwdqc is a PAM password quality control module that checks the strength of the password.

Warning: Enabling the PAM passwdqc module will disable the PAM cracklib module.

top

Set the password strength policy

Issue the following command:

sudo vi /etc/pam.d/common-password

and populate it with the following:

password   requisite pam_passwdqc.so min=disabled,10,8,8,8 max=40 similar=deny enforce=users ask_oldauthtok check_oldauthtok

password   [success=1 default=ignore]   pam_unix.so obscure use_authtok try_first_pass sha512

# here's the fallback if no module succeeds

password   requisite   pam_deny.so

# prime the stack with a positive return value if there isn't one already;

# this avoids us returning an error just because nothing sets a success code

# since the modules above will each just jump around

password   required   pam_permit.so

libpam_ passwdqc is a PAM module that tests passwords to make sure they are not too weak during password change. It adds additional password entropy assistance to the standard security system.

By default, Ubuntu requires a minimum password length of 4 characters, as well as some basic entropy checks. These values are controlled in the file /etc/pam.d/common-password.

The pam_passwdqc manpage provides a lot of information, but the above essentially disallows passwords from any single character class, enforces a minimum length of 10 characters for a password from any two character classes, a minimum length of 8 characters for a passphrase, a minimum length of 8 characters for a password from any three character classes, and a minimum length of 8 characters from four character classes. The four character classes are made up of, digits, lower-case letters, upper-case letters, and other characters (such as '!' and '_') respectively. The above also enforces no passwords longer than 40 characters. The other options are clearly outlined in the pam_passwdqc man pages.

Each option can be customized to suit your environment. The above is actually less strict than the recommended default setting of "min=disabled,24,12,8,7" which can create some extremely difficult-to-crack passwords.

pam_passwdqc has no strange requirements, so even if your distribution does not provide it in packaged form, installing and compiling from source should cause no problems whatsoever.

The hashed passwords use a randomly generated salt.

top

Set the password aging policy

Issue the following command:

sudo vi /etc/login.defs

and modify as follows:

PASS_MAX_DAYS 90

PASS_MIN_DAYS 1

PASS_WARN_AGE 7

LOGIN_RETRIES 5

These options specifiy the maximum number of days that a password may be used, the minimum number of days between password changes, the number of days warning given before a password expires, and the maximum number of login retries if a password is bad.

The LOGIN_RETRIES setting will probably be overwritten by PAM, so check the PAM settings as well.

To disable password aging for system and shared accounts, you can run the following chage command:

sudo chage -M 99999 administrator

To get password expiration information:

sudo chage -l administrator

top

Set the user account lockout policy

Issue the following command:

sudo vi /etc/default/useradd

and modify as follows:

INACTIVE=90

This specifies the number of days after password expiration that the account will be disabled.

top

Set default permissions for home directories

Issue the following command:

sudo vi /etc/adduser.conf

and modify as follows:

DIR_MODE=0750

By default, user home directories in Ubuntu are created with world read/execute permissions. This means that all users can browse and access the contents of other users’ home directories.

This change results in world readable permissions being removed.

top

Secure user’s home directories

Issue the following command:

sudo chmod 0750 /home/username

Replace <username> with the actual login name to the computer.

Restricts access by other users to another user’s home directory.

When a new user is created, the adduser utility creates a brand new home directory named /home/username, respectively. The default profile is modeled after the contents found in the directory of /etc/skel, which includes all profile basics.

If your server will be home to multiple users, you should pay close attention to the user home directory permissions to ensure confidentiality. By default, user home directories in Ubuntu are created with world read/execute permissions. This means that all users can browse and access the contents of other users’ home directories.

To verify your current users home directory permissions, use the following syntax:

sudo ls -ld /home/username

The following output shows that the directory /home/username has world readable permissions:

drwxr-xr-x 2 username username 4096 2007-10-02 20:03 username

NOTE: Some people tend to use the recursive option (-R) indiscriminately which modifies all child folders and files, but this is not necessary, and may yield other undesirable results. The parent directory alone is sufficient for preventing unauthorized access to anything below the parent.

A much more efficient approach to the matter would be to modify the adduser global default permissions when creating user home folders. Simply edit the file /etc/adduser.conf and modify the DIR_MODE variable to something appropriate, so that all new home directories will receive the correct permissions.

DIR_MODE=0750

After correcting the directory permissions using any of the previously mentioned techniques, verify the results using the following syntax:

sudo ls -ld /home/username

The results below show that world readable permissions have been removed:

drwxr-x--- 2 username username 4096 2007-10-02 20:03 username

top

Install Jailkit (Optional)

Issue the following command:

sudo aptitude install build-essential autoconf automake1.9 libtool flex bison

…and issue the following commands:

cd /tmp

wget http://olivier.sessink.nl/jailkit/jailkit-2.15.tar.gz

tar xvfz jailkit-2.15.tar.gz

cd jailkit-2.15

./configure

make

make install

cd ..

rm -rf jailkit-2.15*

Jailkit is a set of utilities to limit user accounts to specific files using chroot() and or specific commands. Setting up a chroot shell, a shell limited to some specific command, or a daemon inside a chroot jail is a lot easier and can be automated using these utilities.

Jailkit is known to be used in network security appliances from several leading IT security firms, internet servers from several large enterprise organizations, internet servers from internet service providers, as well as many smaller companies and private users that need to secure cvs, sftp, shell or daemon processes.

This is optional but recommended.

Jailkit is needed only if you want to chroot SSH users.

top

System Accounts

System accounts are non-human accounts. They are often used to run daemons (like servers).

Modify System Accounts Shell Access

Issue the following commands:

sudo vi /sharewiz/set_system_accounts_to_false.sh

and modify as follows:

#!/bin/bash

#

# Sets all system accounts to have /bin/false as their shell.

#

UID_MIN=`cat /etc/login.defs | grep -E ^UID_MIN | sed -r 's/ +/ /g' | cut -d " " -f 2`

for account in `awk -F':' '{if(($7=="/bin/bash"||$7=="/bin/sh" )&&($3>0&&$3<'$UID_MIN')) print $1}' /etc/passwd`

do

usermod --shell /bin/false "$account"

#echo "$account"

done

unset UID_MIN

Then change the permissions of this file, by issuing the following command:

sudo chmod 755 /sharewiz/set_system_accounts_to_false.sh

Now run the script, by issuing the following command:

sudo /sharewiz/set_system_accounts_to_false.sh

A lot of system accounts have the default shell of /bin/sh but as they will not be used for login purposes, we secure them further to prevent potential logins using these accounts if the system ever became compromised.

The following command can be used to determine the UID range for system accounts:

sudo cat /etc/login.defs | grep -E ^UID_MIN | sed -r 's/ +/ /g' | cut -d " " -f 2

which should probably return 1000. Different Linux distributions use different UID numbers for system accounts. Debian and Ubuntu systems have system users using UIDs between 0 and 1000.

Other users accounts settings can be found in the file /etc/login.defs.

top

Continue to the Anti-Hacking Security...