[CRT08]

UNIVERSITY OF BOLTON CREATIVE TECHNOLOGIES BSc (Hons) COMPUTER NETWORKS AND SECURITY SEMESTER ONE EXAMINATION 2015/2016 UNIX MODULE NO: CPU5003 Date: Wednesday 13th January 2016

Time: 10:00 – 12:00

INSTRUCTIONS TO CANDIDATES:

There are SIX questions. Answer ANY FOUR questions. All questions carry equal marks. Marks for parts of questions are shown in brackets. Unless otherwise stated all symbols take their usual meaning. Silent electronic calculators may be used provided that data and program storage memory is cleared prior to the examination.

Page 2 of 8 Creative Technologies BSc (Hons) Computer Networks and Security Semester One Examination 2015/2016 UNIX Module No. CPU5003 Question 1 Q1 a) Describe the primary function of the following UNIX directories:        

/home /tmp /var /root /sbin /dev /etc /mnt

(8 marks)

Q1 b) A root user issues the following sequence of commands in the order shown. After each command, what would be the full pathname of the user’s present working directory? You should assume that the directory /etc/var does not exist but that all others do. cd /etc cd . cd var cd .. cd cd ../var cd /var/spool/cron cd .. cd lpd cd ../.. cd ~/pictures cd / cd ~

(13 marks)

Q1 c) Compare and contrast the functionality of the following UNIX commands: cp mv rm rmdir

(4 marks)

PLEASE TURN THE PAGE….

Page 3 of 8 Creative Technologies BSc (Hons) Computer Networks and Security Semester One Examination 2015/2016 UNIX Module No. CPU5003 Question 2 Q2 a) Write a command that will extract the broadcast address from the output of the /sbin/ifconfig command. An example of the /sbin/ifconfig output can be found below. In this case the broadcast address 10.10.0.255. (4 marks) [root@pascal cron]# /sbin/ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:0C:29:D0:2E:53 inet addr:10.10.0.49 Bcast:10.10.0.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fed0:2e53/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2456 errors:0 dropped:0 overruns:0 frame:0 TX packets:1604 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:165598 (161.7 KiB) TX bytes:150680 (147.1 KiB)

Q2 b) Write a command that would extract the hardware address from the output of the /sbin/ifconfig command and save it in a variable named hardware. In the example above the hardware address is 00:0C:29:D0:2E:53 (4 marks) Q2 c) What would the effect of the following command be and what is the purpose of the pipe ? (4 marks) cat /etc/passwd | grep n$ To assist you an example of a UNIX password file (/etc/passwd) is below: root@gem-gateway ~]# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin … information taken out … ra4bct:x:303:500::/home/ra4bct:/bin/bash ad3ect:x:304:500::/home/ad3ect:/bin/bash rc2ect:x:305:500::/home/rc2ect:/bin/bash lb1bct:x:306:500::/home/lb1bct:/bin/bash ai1ect:x:309:500::/home/ai1ect:/bin/bash tut1mon:x:310:501::/home/tut1mon:/bin/bash tut1tue:x:311:501::/home/tut1tue:/bin/bash tut2wed:x:312:501::/home/tut2wed:/bin/bash … information taken out …

Question 2 continues over the page…. PLEASE TURN THE PAGE….

Page 4 of 8 Creative Technologies BSc (Hons) Computer Networks and Security Semester One Examination 2015/2016 UNIX Module No. CPU5003 Question 2 continued…. Q2 d) Below is the output of the command ‘cat /etc/hosts’ executed on a machine in the University of Bolton called ‘ruby’. While examining this /etc/hosts file, an administrator notices that the domain names are all incorrect. All machines refer to bct where as they should refer to cet. For example sapphire.bct.bolton.ac.uk should be sapphire.cet.bolton.ac.uk. Write a series of commands that would facilitate this change without the need for the file to be edited manually. 5 marks

[root@ruby ~]# cat /etc/hosts # # Hosts on the Gem network 127.0.0.1

ruby.bct.bolton.ac.uk ruby

10.10.0.130 10.10.0.121 10.10.0.122 10.10.0.123 10.10.0.124 10.10.0.125 10.10.0.126 20.10.1.1 20.10.1.2 30.10.1.1 30.10.1.1

garnet.bct.bolton.ac.uk garnet pearl.bct.bolton.ac.uk pearl sapphire.bct.bolton.ac.uk sapphire ruby.bct.bolton.ac.uk ruby jet.bct.bolton.ac.uk jet onyx.bct.bolton.ac.uk onyx emerald.bct.bolton.ac.uk emerald kirk.bct.bolton.ac.uk kirk spock.bct.bolton.ac.uk spock mars.bct.bolton.ac.uk mars twix.bct.bolton.ac.uk twix

… information taken out ….

Q2 e) Write a command that will extract from the /etc/hosts file, all lines that refer to machines with an IP address in the range 10.0.0.0 to 100.255.255.255. (8 marks)

Question 3 Q3 a) Compare and contrast three forms of conditional statement used in UNIX bash scripting. You should explain in detail how each type of conditional statement operates and illustrate your answer with example algorithms. (25 marks)

PLEASE TURN THE PAGE….

Page 5 of 8 Creative Technologies BSc (Hons) Computer Networks and Security Semester One Examination 2015/2016 UNIX Module No. CPU5003

Question 4 Q4 a) Examine the following output.. [rhc1@central ~]$ ls -l total 8 -rwxr-xr-- 1 rhc1 secgroup 2716 Oct 30 12:37 syschange [rhc1@central ~]$

The user ‘rhc1’ would like to change the permissions on the file ‘syschange’ so that other members of his group can read the script but cannot execute it. What command might he issue to make this change? No other permissions on the file should be changed. What would be the effect of the following two commands:  

chmod 666 syschange chmod 755 syschange

(4 marks)

Q4 b) Examine the following output and provide an interpretation of the permissions listed that explains who has permission to do what. (11 marks) [root@central ~]$ ls -l total 16 -rwxr-x--x 1 root secgroup Apr 20 22:10 3526 datafile drwxr-xr-- 1 root secgroup Mar 20 20:08 387 systemdata [root@central ~]$

Q4 c) Provide a brief overview of the “sticky bit”. Ensure that you cover its affect, how it is assigned and how you can tell if it is present. (4 marks)

Q4 d) Explain the concept of an SUID script. How do you create such a script, how do its permissions appear and why are they often viewed as a security risk? (6 marks)

PLEASE TURN THE PAGE….

Page 6 of 8 Creative Technologies BSc (Hons) Computer Networks and Security Semester One Examination 2015/2016 UNIX Module No. CPU5003

Question 5 Q5 a) A UNIX system provides a service that must be available between 8 am and 11 pm each day. The service does not run from 11 pm each evening until 8 am the next morning. The following two requests have been made of the UNIX administrator: 

that the system should be re-booted every Sunday and Wednesday;



that a backup script (/usr/local/bin/backup) should be executed every day. This script can take up to 4 hours to run.

Both of these activates need to be completed during the hours that the service does not run (between 11 pm and 8 am). Provide a detailed explanation of how cron can be used to achieve this inclusive of the configuration changes that need to be made and the commands that will be used. To assist you, an extract from the output of the command “man cron” can be found in below. (15 marks) [rhc1@cet-apache-02 ~]$ man cron …. information taken out …. The time and date fields are: field allowed values ----------------------minute 0-59 hour 0-23 day of month 1-31 month 1-12 (or names, see below) day of week 0-7 (0 or 7 is Sun, or use names) A field may be an asterisk (*), which always stands for ‘‘first-last’’. …. information taken out ….

Question 5 continues over the page…. PLEASE TURN THE PAGE….

Page 7 of 8 Creative Technologies BSc (Hons) Computer Networks and Security Semester One Examination 2015/2016 UNIX Module No. CPU5003

Question 5 continued…. Q5 b) All users are to be prevented from logging into a UNIX system from 5 pm on Friday until 9 am on Monday. The UNIX system is then to be rebooted on Saturday morning and again on Sunday morning. Assuming that it is now 1 pm on Friday afternoon, write a series of commands as root that will schedule the following events: 

at 2 pm this afternoon, send a message to all users informing them that no one will be able to use the system from 5 pm on Friday until 9 am on Monday;



send a follow up at 4 pm stating that they have an hour remaining;



at 5 pm create a file called /etc/nologin; (the existence of this file will stop users from logging in);



at 10 am on Saturday and Sunday morning reboot the system;



at 2 am on Monday morning, delete the /etc/nologin file.

(10 marks)

Question 6 Q6 a) What do the following variables represent in a UNIX shell script  $0  $1  $2  $#  $@  $?  $$

(7 marks)

Q6 b) Write a script that will continuously ping the IP address 10.10.5.5 until it gets a response. Each ping should send only a single ICMP request and they should be sent one second apart. After each ping the user should be informed in simple language as to whether or not the system (10.10.5.5) can be contacted. (8 marks) Q6 c) On a UNIX box in /var/spool/mail there are series of small text files. Write a script that will present the contents of each text file to the screen (using cat) one at a time, 10 seconds apart. Your script should work regardless of how many files there are in /var/spool/mail and using absolute pathnames it should be able to run form any directory on the system. (10 marks)

Page 8 of 8 Creative Technologies BSc (Hons) Computer Networks and Security Semester One Examination 2015/2016 UNIX Module No. CPU5003 END OF QUESTIONS