Final exam exercises. May 9 2008. Time 12 noon -- 1:20 p.m.

The exercises are supposed to be done by each student solely on his/her desktop station in the Unisys lab in D-112. It is allowed to use lecture notes at http://linuxcourse.rutgers.edu and any printed material. Internet access during the exam will be restricted to the web site only.
Number of exercises: 8. Each exercise has a maximum score.
In directory /root, you need to create a new file answers.txt, where you will be writing answers to the exam exercises. Write your name and the desktop number in the file.

Note: if you happen to need to install a software package, run
apt-get install package_name

1. Regular expressions and metacharacters (max score 4)
Which of the following should be used to find words Jack and Jackson in a file when running grep -E -w command?
A) Jack(son)*
B) Jack[son]
C) Jack|son
D) Jack(son)?

Answer
D
The question mark metacharacter (?) matches zero or one instance of the preceding regular expression, while the asterisk (*) matches any number of them.

2. GPG (max score 5)
Download the following files exam.pub, exam.sig, SA-ex1.tgz, SA-ex2.tgz, SA-ex3.tgz, SA-ex4.tgz
A) Who is the author of exam.pub file?
B) Which of the *.tgz files does the signature belong to?

Answer
A) gpg --import exam.pub; gpg --fingerprint
gives "Lab Admin (Administrator)"
B)
gpg --verify  exam.sig  SA-ex1.tgz
gpg --verify  exam.sig  SA-ex2.tgz
gpg --verify  exam.sig  SA-ex3.tgz
gpg --verify  exam.sig  SA-ex4.tgz
The last one gives Good signature from Lab Admin (Administrator)

3. Shell scripting (max score 4)
Consider the following script
#!/bin/bash

cmmd = /usr/bin/md5sum

for i in $(ls /etc); do

 if [ ! -d  /etc/$i ] then
  $cmmd /etc/$i
 fi

done
It fails to run due to a few syntactic errors.

A) Find the errors in the script.

B) Explain what the script does.

Answer A) No spaces before and after '='
cmmd=/usr/bin/md5sum
Correct usage of if then is the following
if [ ! -d  /etc/$i ]; then
or
if [ ! -d  /etc/$i ]
then

B) The script computes MD5 hashes of the files in directory /etc and skips subdirectories.


4. Command find (max score 5)
Download archive imap.tar.gz. Un-tar the archive. By using command find in the directory tree, find
A) the full path to file shortsym.h
B) the largest file in the archive.

Answer
A)
tar -zxvf imap.tar.gz
cd imap-2006a
find . -name shortsym.h
Result: ./src/osdep/tops-20/shortsym.h
B) Make a sequence of searches:
find . -size +10k
find . -size +100k
find . -size +1000k
find . -size +500k
Result: ./src/charset/cns11643.c


5. Password cracking (max score 4)
You have a list of user names and encrypted passwords, separated by semicolomns:
sam:acBVfRtRSZMeI:
jerry:acfA7TimCMmJs:
sanchez:acXfxA/h3D4H.:
linux:bctgoamjrC/s.:

Figure out the actual passwords. What is the encryption type used here?

Answer
A) Save the list in a file, say pass.txt, and Have John the Ripper to crack it:
john pass.txt
john -show pass.txt

#Result
sam:alpha: 
jerry:newyork:  
sanchez:Mexico:  
linux:pinguin: 

Encryption type is standard DES, as shown by john.

6. Ports and network services (max score 6)
Suppose, someone told you that a TCP port scan revealed an open FTP port on your computer.

A) How can you verify that FTP service is indeed running?

B) How can you disable it?

C) If you want to run it and allow only a specific host to access it, say 192.168.1.2, how would you set tcpwrappers on your computer to restrict access to FTP ?

D) How would you set iptables on your computer to allow access to FTP service from 192.168.1.2 ?
Note, don't worry about the stateful packet inspection in this particular case.
Answer
A) Check if port TCP/21 is open
netstat -na | grep 21
B) Comment out the entry for ftp in /etc/inetd.conf and reset inetd
pkill -HUP inetd
C) Tcpwrappers:
/etc/hosts.allow
in.ftpd: 192.168.1.2
/etc/hosts.deny
in.ftpd: ALL 

D) Iptables:
iptables -A INPUT -p tcp --dport 21 -s 192.168.1.2/32 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 21 -d 192.168.1.2/32 -j ACCEPT
We imply here the default policy DROP for INPUT and OUTPUT chains.

7. MPI computations (max score 7)
Consider the following MPI code:
#include "mpi.h"
#include 

int main(argc,argv)
int argc;
char *argv[];  {
int numtasks, rank, dest, source_1, source_2, rc, tag=1;
double data1, data2, outdata, result;
MPI_Status Stat;

MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

if (rank == 0) {
 source_1 = 1;
 source_2 = 2;
 rc = MPI_Recv(&data1, 1, MPI_DOUBLE, source_1, tag, MPI_COMM_WORLD, &Stat);
 rc = MPI_Recv(&data2, 1, MPI_DOUBLE, source_2, tag, MPI_COMM_WORLD, &Stat);
 result = data1 + data2;
 printf("Total result %lf:  \n", result);
}

else if (rank == 1) {
  dest = 0;
  outdata = 10.0;
  rc = MPI_Send(&outdata, 1, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD);
}

else if (rank == 2) {
   dest = 0;
   outdata = 25.0;
   rc = MPI_Send(&outdata, 1, MPI_DOUBLE, dest, tag, MPI_COMM_WORLD);
}

MPI_Finalize();
}


A) How many CPUs does the code need?

B) What tasks in the code do the CPUs perform?

C) How would you compile the code, and run it through mpiexec

Answer
A) The code needs 3 CPUs since there are rank 0, 1, and 2 processes.

B) CPU1 (rank 1) sends number 10.0 to CPU0 (rank 0); CPU2 (rank 2) sends number 25.0 to CPU0 (rank 0); CPU0 receives the numbers from both CPU1 and CPU2 then computes the total sum.

C) Compilation with MPI:
mpicc -o code.x code.c
Start the process manager daemon on the nodes, smpd -s.
Run the compiled code on three nodes:
 
mpiexec -n 3 code.x

8. E-mail (max score 5)
Email file answers.txt to alexei@capone with subject 'Final exam 2008'. The IP address of capone on the local subnet is 192.168.5.240. Explain what you did to accomplish this task, then e-mail the updated answers.txt with subject 'Final exam 2008 finished.'

Answer
You need to setup an e-mail program such as pine, mozilla, etc, to relay e-mail through some SMTP server located on the local network to capone. There are various ways to do it. If you have done Lesson 12 practical exercises, you already have Postfix server and e-mail program (pine) set and ready to be used. You just need to make sure the IP address of capone is listed in file /etc/hosts and the Postfix is configured not to resolve DNS lookups, disable_dns_lookups=yes since capone is located on the private subnet.
Alternatively, you can configure an e-mail program, pine for example, to relay e-mail directly through capone: smtp-server=192.168.5.240