Final exam Summer 2025 Q-and-A#

Number of exercises: 4. 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.

All the exercises should be done on the virtual desktop (VD).

1. Code compilation and Makefile (max score 6)#


In directory FINAL, download a tar ball archive, containing two source codes with a header file in it, from http://linuxcourse.rutgers.edu/Files/linpack_bench.tgz

A) Compile the two source codes together. Run the executable.

B) In the same directory, create a Makefile with targets:

  • to build library libtimel.a from timel.c

  • compile linpack_bench.c with the above library into executable linpack.x

  • target ‘install’ to install the binary into directory /usr/linpack/bin

  • target ‘clean’ to remove compilation artifacts.

C) run

make
sudo make install

Check if the binary file exists in the installation directory.

  • Answers:

A)

gcc -o linpack.x linpack_bench.c time.c -lm
./linpack.x

B)

linpack.x: linpack_bench.c libtimel.a timel.h
        gcc -o linpack.x linpack_bench.c -ltimel -lm -L.

libtimel.a: timel.c timel.h
        gcc -c timel.c
        ar -cr libtimel.a timel.o
        ranlib libtimel.a

clean:
        -rm -f *.x *.o *.a

install:
        -mkdir -p /usr/linpack/bin
        -cp linpack.x /usr/linpack/bin

uninstall:
        -rm -rf /usr/linpack

C)

make 
sudo make install
ls -l /usr/linpack/bin

2. Shell scripting (max score 6)#

In directory FINAL on the desktop, create a shell script, replace.sh,

A) to replace value of N 1000 by N 200 in file linpack_bench.c.

Hint: use command sed to replace text patern define N followed by any integer number.

B) Modify the script to read the new value of N from the keyboard input.

C) Add a command in end of the script to recompile linpack_bench.c.

  • Answer:

The script that covers A, B, and C:

#!/bin/bash

echo 'input N'
read N

cp linpack_bench.c test.c
sed -e "s/define *N *[0-9]*/define N $N/" test.c > linpack_bench.c

make

3. Python scripting (max score 6)#

Implement parts A, B, and C from the exercise #2 in Python.

  • Answer:

#!/usr/bin/python3

import re, os, shutil

s = input('input new  N: ')

string = f'define N {s}'


f = open('linpack_bench.c','r')
w = open('new_linpack.c','w')

for line in f:
    newline = re.sub(r'define\s+N\s+[0-9]*',  string, line)
    w.write(newline)

f.close()
w.close()

shutil.copy('new_linpack.c', 'linpack_bench.c')

os.system('make')

4. Password cracking (max score 6)#

Download file http://linuxcourse.rutgers.edu/Files/user_passwords.txt

Crack the password hashes of the 3 users in the file. Show the user passwords.

  • Answers:

wget http://linuxcourse.rutgers.edu/Files/user_passwords.txt

Install John the Ripper on the VD:

apt install john

Crack the descrypt hashes:

john user_passwords.txt

Crack the md5crypt hashes:

john --format=md5crypt user_passwords.txt

Show the cracked passwords:

john --show user_passwords.txt
user1:this1
user2:general2
user3:last5