Changes

Jump to: navigation, search

OPS235 Lab 7 - CentOS7 - HD2

9,013 bytes removed, 16:19, 24 October 2016
no edit summary
|}
=INVESTIGATION 1: INSTALLING, CONFIGURING AND MAINTAINING AN SSH SERVER=
So far, you have learned to use the '''ssh''' utility to establish a secure connection to a remote server to perform tasks, administer the server. For these common operations, you have issued the ''ssh'' command, which is actually the '''client''' application for ssh. In order to connect to a remote server (like your VMs, Matrix, etc) they need to be running the SSH service (i.e. the ssh daemon).
'''Answer INVESTIGATION 1 observations / questions in your lab log book.'''
 
 
=INVESTIGATION 2: ADDITIONAL METHODS TO SECURE YOUR SSH SERVER =
{|width="40%" align="right" cellpadding="10"
|}
=== Part 31: Generating Private and Public Keys (Public Key Infrastructure) ===
As a system administrator, you have the ability to generate or create '''public''' and '''private''' keys to ensure safe and secure ssh connections. This will require a user to prove who they say they are in order to access a Linux server via SSH (i.e. Authentication). The system administer can generate these keys for the first time, or if the system administrator suspects that a hacker has compromised or trying to penetrate the server, they can remove the existing keys and generate new keys.
</ol>
 
 
'''Answer INVESTIGATION 1 observations / questions in your lab log book.'''
 
 
=INVESTIGATION 2: USING SSH AND OTHER SECURE SHELL UTILITIES=
 
=== Part 1: How do you use scp and sftp. ===
 
When the SSH service is running, users can then take advantage of secure shell tools (including the '''scp''' and '''sftp''' utilities).
 
The ssh client utility also contains many options to provide useful features or options when establishing secure connections between servers. One of these features is referred to as '''tunnelling''' - this term refers to running programs on remote servers (i.e. running the program on a remote server, yet interacting and viewing program on your local server. Since '''X-windows''' in Linux is a support <u>layer</u> to transmit graphical information efficiently between servers, ssh tunnelling becomes more useful and important to allow organizations to work efficiently and securely in a user-friendly environment.
 
:'''Perform the following steps:'''
 
# Switch to your '''centos1''' VM.
# Open a terminal, and remain logged in as a regular user.
# Establish an sftp session with your centos3 VM by issuing the following command:<br /><b><code><span style="color:#3366CC;font-size:1.2em;">sftp ops235@centos3</span></code></b>
# Type <b><code><span style="color:#3366CC;font-size:1.2em;">help</span></code></b> to see the list of sftp commands at any time.<br><br>'''Remote Server''' (eg. '''centos3''') commands: '''pwd''', '''ls''', '''cd'''<br>'''Local Machine''' (eg. '''centos1''') commands: '''!pwd''', '''!ls''', '''lcd'''<br><br>
# The basic commands to upload and download files between servers are <b><code><span style="color:#3366CC;font-size:1.2em;">put</span></code></b> and <b><code><span style="color:#3366CC;font-size:1.2em;">get</span></code></b> respectively.
# Try using '''sftp''' to transfer files back and forth between hosts.
# Confirm that the files were transfer and then enter the command '''exit''' to quit your sftp session.
<ol>
<li value="8">You can also use the '''scp''' command to copy files to and from remote hosts and even from one remote host to another.</li>
<li>Use '''scp''' to copy your services file to the centos3 host into the /tmp directory. (The path on a remote host follows the ''':''') using the command: <br /><b><code><span style="color:#3366CC;font-size:1.2em;">scp /etc/services ops235@centos3:/tmp</span></code></b></li>
<li>Here is a neat trick: You can run commands remotely using ssh by typing the command as an argument after the ssh command. Issue the following command in your '''centos2''' VM:<br><b><code><span style="color:#3366CC;font-size:1.2em;">ssh ops235@centos3 ls /tmp</span></code></b></li>
<li>What happened when you issued that command? Where you able to successfully using scp to copy the '''/etc/services''' file to '''centos3's /tmp''' directory? <br>This neat trick allow your lab checking scripts to run commands from remote VMs to verify your work!</li>
<li>Experiment with '''scp''' to copy a file from '''centos3''' directly to '''centos1'''.</li>
</ol>
|}
=== Part 2: Tunneling to Run Securely Running Graphical Applications on Remote VMs Remotely (via Tunnelling) . ===
You can also use ssh to '''tunnel window and bitmap information''', allowing us to login to a remote desktop host and '''run a Xwindows application''' such as <b>gedit</b> or <b>firefox</b> and the application will run on the remote host but be displayed on the local host.
=INVESTIGATION 3: SECURING THE SSH CONNECTION= To help '''harden''' (i.e. protect a server from attack or "penetration"), system or security administrators have the ability to "trick" or "mislead" a potential hacker in order to prevent system penetration.Just like in the movies, "spying" is not just about collecting information about the adversary, but also to deceive the adversary into making incorrect decisions. [[Image:tunnel-trick.png|thumb|right|550px|You can also use an ssh connection to '''tunnel other types of traffic'''. There could be different reasons for doing this. For example tunneling traffic for an unencrypted application/protocol through ssh can '''increase the security of that application''' (i.e. deceive potential hackers).<br><br>Alternatively you could use it to '''circumvent a firewall that is blocking traffic''' you wish to use but allows ssh traffic to pass through.]]=== Part 1: Deceiving Penetration Testers (Hackers) === In this section, you will learn a common technique that organization use to help harden their servers: Use a combination of '''SSH server configuration''' and''' iptables rules''' in order to trick a hacker into thinking that the SSH port is not working, when in fact, it is running quietly (tunneled) via another port... '''Sneaky, but effective'''...''' >;)''' :'''Perform the following steps:''' # Make certain that your '''c7host''' and '''centos1''' VMs are running.# Switch to your '''c7host''' VM. This will be your web-server.# Make sure that the Apache web server is installed by typing the command:<br /><b><code><span style="color:#3366CC;font-size:1.2em;">rpm -q httpd</span></code></b><br>(If this is not installed, make sure to install '''httpd''').# Issue the following commands to <u>start</u> and <u>enable</u> the '''httpd''' service:<br><b><code><span style="color:#3366CC;font-size:1.2em;">systemctl start httpd</span></code></b><br><b><code><span style="color:#3366CC;font-size:1.2em;">systemctl enable httpd</span></code></b># Issue a command to verify that the '''httpd''' service has been started and has been enabled.# Confirm that httpd is LISTENING to '''tcp''' (port '''80''') using the '''netstat''' command.# Create a small html document called '''/var/www/html/index.html''' that displays a short message. If you do not know how to use HTML markup language, just type a simple <u>text</u> message...# <u>Restart</u> your '''c7host''' VM. # Switch to your '''centos1''' VM and click on the following link to open a web-browser view your html or text message: '''http://localhost'''<br><br># '''IMPORTANT:''' Before proceeding, '''flush the iptables rules''' for '''INPUT''', '''OUTPUT''', and '''FORWARD''' chains for both your '''c7host''' and '''centos1''' VMs.# Issue an iptables command to verify that both the the iptables rules have no rules for those chains for your '''c7host''' and '''centos1''' VM's<br><br># On your '''c7host''' VM, add (append) an iptables rule to '''REJECT''' <u>incoming</u> requests to http ( via TCP, port:80) by issuing the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">iptables -A INPUT -p tcp --dport 80 -j REJECT</span></code></b># Switch to your '''centos1''' VM, and cLick on the following link to launch your message in a web-browser: '''http://localhost'''<br>What happenned? If your message didn't load, why do you think it didn't load?# Return to your c7host VM, and issue the following itables rules to add (append) an exception to view incoming web requests on your local machine (interface card: lo - loopback address): <br><b><code><span style="color:#3366CC;font-size:1.2em;">iptables -A INPUT -i lo -j ACCEPT</span></code></b> # On '''centos1''' confirm that you still cannot connect to c7host web-server by clicking on the following link: '''http://centos1/'''<br><br>The next step is to establish a <u>tunnel</u>. When you establish a tunnel you make an ssh connection to a remote host and open a new port on the local host.<br>That local host port is then connected to a port on the remote host through the established tunnel. When you send requests to the local port it is forwarded through the tunnel to the remote port.<br><br><ol><li value="16">Switch to your '''c7host''' VM, and make certain you are logged in as a regular user (i.e. '''NOT root!'''),</li><li>We are going to establish a tunnel using a <u>local port</u> (port number: '''20808''') on our '''centos1''' VM that will connect to the <u>remote</u> port: 80 on the '''c7host''' VM.<br>Issue the following command (from c7host): <b><code><span style="color:#3366CC;font-size:1.2em;">ssh -L 20808:centos1:80 yourUserID@centos1</span></code></b><br><br> '''Note:'''<br>The '''-L''' option (which means Local port) takes one argument:<br><span style="courier">&lt;local-port&gt;:&lt;connect-to-host&gt;:&lt;connect-to-portMANAGING FIREWALLS FOR PROTECTION &gtamp;</span><br><br> The command basically connects your local port of 20808 to the remote port of 80 on '''c7host'''.<br>This means all requests to 20808 on the <u>localhost</u> ('''centos1''') are actually tunneled through your ssh connection<br>to port 22 on '''c7host''' and then delivered to port 80 on '''c7host''', bypassing the firewall.<br><br></li><li>Open another terminal in your c7host machine, and verify that the port 20808 is listening on '''centos1''' by issuing the command:<br> <b><code><span style="color:#3366CC;font-size:1.2em;">netstat -aunpt | grep 20808</span></code></b></li><li>Now switch to your '''centos1''' VM and click on the link to see if this tunneling trick works:'''http://localhost:20808'''</li><li>You should see the '''index.html''' page on '''c7host'''.</li><li>Close the ssh connection and verify that the port 20808 is no longer listening.</li></ol>  {|width="40%" align="right" cellpadding="10"|- valignTROUBLESHOOTING ="top" |{{Admon/tip |Troubleshooting Tips for SSH|Cannot connect via SSH? To fix issues with the ability to ssh, on both machines:<ul><li>Ensure ssh is '''running'''.</li><li>Disable '''SELinux'''</li><li>'''Flush iptables''' (iptables -F)</li><li>For '''scp''', use the access the option (eg. '''scp -P 2200''' )</li></ul> }} |}  
13,420
edits

Navigation menu