Final exam Fall 2024 Q and A.#

Date: 12/17/2024, time: 6:40 pm - 9 pm

Number of exercises: 5. Each exercise has a maximum score.

In home directory of user hostadm, you need to create a new subdirectory, FINAL and a file within it, answers.txt, where you will be writing answers to the exam exercises.

In the file, first, put your name, then proceed with answering to the questions below. Please report all the commands and options used in each exercise.

All the exercises should be done on the VDI desktop solely.

1. Compilation and Makefiles (max score 8)#

  • On your desktop, download a tar archive from https://linuxcourse.rutgers.edu/Files/blas.tgz It contains source code files. Untar the archive.

  • A) Compile the source code files into one executable file blas.x. Make sure the executable, blas.x, can run and produce output.

  • B) Create static library libblas.a from blas0.c file.

  • C) Develop makefile Makefile, that includes targets for building library libblas.a and compilation for blas.x,as well as target clean for removing the compilation products.


Ansswer:

wget https://linuxcourse.rutgers.edu/Files/blas.tgz
tar -zxvf blas.tgz

A)

gcc -o blas.x blas0_test.c blas0.c -lm
./blas.x

C)

gcc -c blas0.c
ar -cr libblas.a blas0.o
ranlib libblas.a

D) Makefile:

blas.x: blas0_test.c  blas0.h libblas.a
        gcc -o blas.x blas0_test.c -L. -lblas -lm

libblas.a: blas0.c blas0.h
        gcc -c blas0.c
        ar -cr libblas.a blas0.o
        ranlib libblas.a

clean:
        -rm blas.x blas0.o libblas.a

2. Shell scripting (max score 6)#

By using shell scripting tools

  • A) Print out all the lines in file blas0.c that assign a value to i4_huge.

  • B) Assign value 2e9 to i4_huge everywhere in file blas0.c.


A)

grep "i4_huge ="  blas0.c

B) Replacing i4_huge = followed by any alpha-numeric string by i4_huge = 2e9 in all the lines:

sed -i 's/i4_huge = [0-9A-Za-z]*/i4_huge = 2e9/g' blas0.c

3. Python scripting (max score 8)#

  • A) Create python script exam1.py that accomplishes part A in Exercise 2. Run the script.

  • B) Create python script exam2.py that accomplishes part B in Exercise 2. Run the script.


Answer:

A)

#!/usr/bin/python3

search_str = "i4_huge ="

with open("blas0.c", "r") as f:
  for line in f:
    if search_str in line:
      print(line.strip("\n"))

B)

#!/usr/bin/python3

import re

search_str = "i4_huge ="

new_content = []

with open("blas0.c", "r") as f:
  for line in f:
    if search_str in line:
      new_line = re.sub(r'i4_huge = [0-9A-Za-z]*', 'i4_huge = 2e9', line)
    else:
      new_line = line
    new_content.append(new_line)

with open("blas0.c", "w") as f:
  for line in new_content:
    f.write(line)

4. Deploying VM appliance (max score 4)#


Answer:

cd KVM
wget  http://capone.rutgers.edu/coursefiles/final2024.tgz
tar -zxvf  http://capone.rutgers.edu/coursefiles/final2024.tgz

sudo cp final2024.xml /etc/libvirt/qemu/final2024.xml
sudo virsh define  /etc/libvirt/qemu/final2024.xml

virsh start final2024
virsh domifaddr final2024

5. Port scans (max score 4)#

From your desktop, scan final2024 VM for open TCP ports. Post the command and the output in your report, answers.txt.


Answer:

nmap -sT 192.168.122.92
PORT   STATE SERVICE
21/tcp open  ftp
22/tcp open  ssh
80/tcp open  http