Difference between revisions of "SEC520/labs/Lab 6"
(Created page with "<h1> <span class="mw-headline">Linux System Hardening (Part 1)</span></h1> <a name="Introduction" id="Introduction"></a><h2> <span class="mw-headline">Introduction</span></h2>...") |
(No difference)
|
Revision as of 09:07, 1 February 2018
Contents
Linux System Hardening (Part 1)
<a name="Introduction" id="Introduction"></a>Introduction
- In this lab, students will learn how to make their Linux servers less vulnerable to attacks (i.e. hardening the Linux system). First, students will prevent users from booting into run level 1 (super-user mode) by creating a grub boot password.
- Students will also identify and close unneccesary ports (running services) on their Linux and Windows Virtual Machines in order to make those servers less vulnerable to attacks.
- Students will then configure SSH to provide a safe "tunnel" for data to prevent from hacking, and to change the port number to help to confuse (discourage) hackers.
- Finally, students will use PAM (Plugable Authentication Modules) to further protect running applications in their VMs.
Objectives
- Setup a grub boot password to prevent users from gaining access to super-user mode during Linux system bootup.
- Close unnecessary running ports (services) to make server(s) less vulnerable to attack.
- Use SSH tunnelling to protect data from being picked up by hackers.
- Use PAM to provide authentication for APIs (application programming interfaces).
Required Materials (Bring to All Labs)
- SATA Hard Disk (in removable disk tray).
- Lab Logbook (Lab4 Reference Sheet) (to make notes and observations).
Prerequisites
- <a href="https://scs.senecac.on.ca/%7Efac/sec520/labs/SEC520_Lab_5.html">SEC520 Lab 5</a>
Online Tools and References
- <a href="http://www.linuxhowtos.org/Network/netstat.htm" target="_new">netstat</a> <a href="" target="_new"> </a>
- <a href="http://www.hscripts.com/tutorials/linux-services/index.php">service</a> or <a href="http://www.linux.com/learn/tutorials/527639-managing-services-on-linux-with-systemd">systemctl</a> (on newer Linux distributions)
- <a href="http://www.ibm.com/developerworks/linux/library/l-pam/index.html" target="_new">PAM</a>
- <a href="http://tommi.org/2008/08/automaticly-blacklisting-password-attempts/" target="_blank">Automatically Blacklist Password Attempts</a>
- <a href="http://www.techcuriosity.com/resources/linux/advanced_file_permissions_in_linux.php" target="_blank">Advanced File Permissions</a>
- <a href="http://www.cyberciti.biz/tips/howot-install-ubuntu-linux-ssh-server.html" target="_new">SSH</a>
- <a href="http://linuxmanpages.com/" target="_new">Online Linux Manpages</a>
Course Notes
- <a href="http://cs.senecac.on.ca/%7Efac/sec520/slides/sec520_w3_l1.odp">odp</a> | <a href="http://cs.senecac.on.ca/%7Efac/sec520/slides/sec520_w3_l1.pdf">pdf</a> | <a href="http://cs.senecac.on.ca/%7Efac/sec520/slides/sec520_w3_l1.ppt">ppt</a> (Slides: Linux Hardening - part 1)
- <a href="http://www.linuxdoc.org/HOWTO/User-Authentication-HOWTO/x115.html" target="_new">Why Use PAM?</a>
- <a href="http://www.ibm.com/developerworks/linux/library/l-pam/index.html" target="_new">Understanding and Configuring PAM</a>
- <a href="http://lcweb.senecac.on.ca:2063/0596003919" target="_new">Linux Security Cookbook (E-book)</a> (Chapter 4)
Performing Lab 6
Task #1: Locking Down Bootup / Performing System Updates
This section will demonstrate how easy it is for a regular users to gain
root user access to a newly-booted Linux system. As a safe-guard,
the student will learn how to set a grub password to make the computer
system less vulnerable.
INSTRUCTIONS:
- Boot your BrackTrack (host) system.
- Open the VirtualBox manager window.</b>
- Prior to running your Vulnerable Linux VM, read the following link on how to enter into single-user mode:
<a href="http://docs.fedoraproject.org/en-US/Fedora/13/html/Installation_Guide/s1-rescuemode-booting-single.html" target="_new">How to Enter Single User Mode (Fedora17 - also applies to Fedora Core 5)</a>. - Boot the Vulnerable Linux VM, press any key, then press the key a to append the word single at the end of the boot command.
- After boot-up is complete, you should notice you are logged in as root (you can issue whoami to confirm.
- Navigate throughout the file system. Check the unpriviledged users in the /home directory.
- What are the consequences by NOT locking down the grub password? Record your observations in your lab log-book.
- Issue the shutdown -h or halt command to shutdown your Vulnerable Linux VM.</b>
</ol>
- Launch the Oracle VM VirtualBox application, click on the New button, and click on Next to proceed.
- Enter the name Hardened Linux for your VM name. Make certain that the OS Type is Linux, and the Version is Fedora, and then click on Next to proceed.
- Accept the defaults (like you did in lab1, including 768 MB RAM and set 10GB for the VM's Hard Disk Size), and eventually click Finish to complete the VM setup.
- Prior to starting your Hardened Linux VM, you will setup a virtual disk in order to boot from your saved Fedora17 install image.
Complete the following steps to prepare for installation:- Right-click on the VM called Hardened Linux in the VirtualBox application window, and select Settings.
- Select Network and set to Host-Only adaptor.
- Select Storage tab on the left-side of the application window.
- Click on IDE Controller near the top of the Storage Tree window, click on the green plus sign to add a new CD/DVD drive. You will be required to specify the location of that Fedora install image (i.e. Choose Disk). The installation process should start (you may need to wait and ignore system errors). Make default install selections as you did with the previous Linux installation. When completed, save your settings.
- After you have changed your settings, double-click on Hardened Linux to start the installation process.
- Make the following selections during the installation process:
- In addition to the defaults, add the Fedora F17 and Fedora F17 - Updates repository.
- Select Create a Grub Boot Password near the end of the installation in the Grub Boot section; Otherwise, accept similar defaults like you did in lab1.
NOTE: If you were unable to set the Grub password during the installation procedure, then as an option, you may search the Internet for a method to manually set the password after the installation process...
- After the installation is complete, shutdown the system, go into Settings and remove the virtual CD/DVD drive that links to your Fedora17 image file. Boot your Hardened Linux VM and try to enter single-user mode. Were you successful?
Record your findings in your lab log-book. - When booting your Hardened Linux system for the first time, fill out a regular user account, and add to administrator's group.
- Finally, perform an update on your system by issuing: yum update.
- Record your observations in your lab log-book.
- Proceed to Task #2.
Answer the Task #1 observations / questions in your lab log book.
<a name="Task2" id="Investigation_1:_How_to_Perform_a_Fedora_DVD_Install_on_Your_Removable_Hard_Drive"></a>
Task #2: Closing Unnecessary Ports / Using SSH
In this section, you will either close or prevent unnecessary ports (services) from running and mask some running services (such as SSH) in order to make your Linux system less vulnerable.
INSTRUCTIONS:- Tighten up your Hardened Linux VM to expose the smallest possible number of services running on your Linux system.
- Verify that the minimum number of (essential) services are running on your Linux system.
- Use the Nessus application and Metasploit framework to confirm that there are no vulnerable services running on your Hardened Linux VM.
- Discuss with another classmate which software is not required to be installed. What is the minimum software configuration that will work? Try to list at least 10 applications in your lab log-book.
- With a classmate, discuss the information visible to users logged in to your system and whether the disclosure of that information presents any real security risk. For example, is it ok for users to view the information in /proc? or in /etc?
- Refer to the following link to OPS235 Lab 7 (SSH): <a href="http://zenit.senecac.on.ca/wiki/index.php/OPS235_Lab_7#Investigation_1:_How_do_you_enable_the_sshd_service." target="_new">SSH Configuration</a>
(Note: newer versions of Fedora Linux use systemctl instead of the system command). - Configure SSH to run for a different port number.
- Use SSH to run the gedit command command from your Linux VM, but displayed on your host.
- Have your group members view the open ports on your VM, and see if they can access this running port.
- How does this technique make your Linux server less vulnerable?
- Proceed to Task #3.
Answer the Task #2 observations / questions in your lab log book.
<a name="Task3" d="Investigation_2:_How_many_file_packages_and_files_are_installed_on_the_system.3F"></a>
Task #3: Using PAM
Fedora uses the Linux Pluggable Authentication Modules (PAM) system to perform authentication (and some related activities, such as account environment initialization). As the name suggests, PAM is modular and permits various modules to be plugged in or removed at the system administrator's discretion.
INSTRUCTIONS:- Ensure that your Hardened Linux VM (i.e. Fedora17) system is running, and log-in as a user with administration priviledges.
- Open a shell terminal in your Hardened Linux VM, and change to the directory /etc/pam.d and review the names of the existing files. What do you think these represent in terms of hardening this system? Record your answer in your lab log-book. Locate the file that contains the PAM configuration for system-config-network.
- Access the PAM System Administrator's Guide in a web-browser (file pathname: /usr/share/doc/pam-1.1.5/html/Linux-PAM_SAG.html
- Make a brief list of line options for the system-config-network PAM configuration file, and record in your lab log-book.
- How could you change this PAM configuration file so that a user logged in on the console would not need to enter the root password? (read the manual or perform a NetSearch to get the answer). Record your answer in your lab log-book.
- Install the pam_abl package by issuing the following command: yum install pam_abl.
- Research on the Internet how to edit the pam_abl configuration file. Documentation for pam_abl (web-browser) is available by using the file pathname:
/usr/share/doc/pam_abl-0.2.3/pam_abl.html - Configure the file /etc/security/pam_abl.conf to use the pam_time module to permit remote ssh access only during the daytime.
- Configure your system to deny access for 1 day to any user or host who has 5 invalid password attempts in an hour, or 12 invalid password attempts in a day using the pam_abl module.
Here is a approximate example: <a href="http://tommi.org/2008/08/automaticly-blacklisting-password-attempts/" target="_blank">Automatically Blacklist Password Attempts</a> - Create a group named development.
- Create the directory /var/devel1 and /var/devel2 and make them accessible to all users. Set the SGID permission bit on /var/devel2 and make that directory owned by the group called development.
Here is a link to setting SGID permissions: <a href="http://www.techcuriosity.com/resources/linux/advanced_file_permissions_in_linux.php" target="_blank">Advanced File Permissions</a> - Create three regular users. Ensure that two users are in the development group and that the third user is not.
- Have each user create a file in /var/devel1 and /var/devel2.
- Record the user and group permission for each file.
- Attempt to access each of the six files using each user's account by reading and then appending (two separate operations). What succeeds and what fails? Why?
- What would the development users have to do to make their files in /var/devel1 accessible to each other?
- Why is Fedora set up so that each user has their own group and the default umask is 0002?
- Record your findings in your lab log-book.
- Proceed to "Completing The Lab".
Answer Task #3 observations / questions in your lab log book.
<a name="Completing_the_Lab" id="Completing_the_Lab"></a>
Completing the Lab
Arrange evidence for each of these items on your screen, then ask your instructor to review them and sign off on the lab's completion:
- All unneccessary services turned-off.
- SSH run on a different port.
- Proof of PAM used to control access to directories.
- Completed Lab 6 notes.
<a name="Preparing_for_Quizzes" id="Preparing_for_Quizzes"></a>
Preparing for Quizzes
- Briefly explain how to access the root account (in run-level 1) from an unprotected Linux system upon boot-up.
- List the steps to setup a grub password to protect a Linux system upon boot-up.
- Explain the consequences of running unneccesary services on a server.
- List the steps to stop a running service, and describe 2 unique methods of confirming that a service is no longer running on the server?
- What is the purpose of using SSH for tunnelling while using a different port number?
- What does PAM stand for? What is the purpose of the PAM modules?
- What is the purpose of the pam_abl modules?