2019 oplossingen labo tussentest - Lars Lemmens

Met dank aan de Github van Martijn en natuurlijk Lars Lemmens

LABO TEST

Exercise 1:

Copy the content of your it-enabled grandmothers id_rsa.pub file in your ~/.ssh/authorized_keys file"

'user@:~$' • ssh user@leia.uclllabs.be -p 22345 -i "/path/to/your grandmothers identity_file"
'user@:~$' • ssh user@leia.uclllabs.be -p 22345

Exercise 2:

Try to find out which TCP ports are open on leia without using tools like netstat or ss. Execute on leia for increased speed.

'user@:~$' • nc -zv -w 1 leia.uclllabs.be 1-65535 2>&1 | grep succeeded | awk '{print $4}'

'user@:~$'for foo in {1..65535}; do nc -N -w1 leia.uclllabs.be $foo </dev/  null >/dev/null && echo $foo;done

'user@:~$' • nmap -p 1-65535 leia.uclllabs.be | grep -P '\d+/tcp.*open' |cut -d'/' -f1

'user@:~$' • nmap --reason -p 1-65535 leia.uclllabs.be | grep -oP '\d+(?=/tcp.*open)'

Exercise 3:

Create a oneliner which lists all palindromes with exactly 6 letters in a dictionary.

'user@:~$' • cat dutch | grep -P '^(.)(.)(.)\3\2\1$'

Exercise 4:

As a web server administrator you have been asked to give your manager a Linux CLI oneliner to extract the 5 IP addresses that contacted the web server the most

The apache log is located in /home/logs. Create a correct oneliner. The output should look something like this: (count IPs)

'user@:~$' • cat apache_google.log | cut -d ' ' -f1 | sort | uniq -c | sort -rn | head -5

Exercise 5:

What Linux ssh command do you use to bind your local port 3000 to a web server on port 4444 on the network of the ssh server

'user@:~$' • ssh -p 22345 username@leia.uclllabs.be -L 3000:IP_web_server:4444

Exercise 6:

Create an apache vhost (netcat.X.cnw2.uclllabs.be) which displays a single web page (index.html). How can you update/alter this website (index.html) via a Netcat connection from your laptop."

'root@myserver' 1)  mkdir /var/www/html/netcat
'root@myserver' 2)  nano netcat.conf
<VirtualHost *:80>
    ServerAdmin root@netcat.X.cnw2.uclllabs.be
    ServerName netcat.X.cnw2.uclllabs.be
    DocumentRoot /var/www/html/netcat

    LogLevel info
    ErrorLog ${APACHE_LOG_DIR}/netcat-error.log
    CustomLog ${APACHE_LOG_DIR}/netcat-access.log combined
</VirtualHost>
'# root@myserver' 1)  a2ensite netcat
'# root@myserver' 2)  systemctl reload apache2
'# root@myserver' 3)  nc -l -p 10000 >> /var/www/html/netcat/index.html
'user@laptop:~$'  4)  echo test | nc netcat.X.cnw2.uclllabs.be 10000

Exercise 7:

On server Leia, use the list of logged in users to print only the username that has been logged in to the server for the longest time

'user@:~$' • who | awk '{print $3$4 " " $1}' | sort -n | awk '{print $2}' | head -1

Exercise 8:

Some subdirectory of /tmp contains a bunch of movies. However, their extension is wrong.

The extension should be .avi instead of .jpg. Copy these files to your homedirectory and correct their extensions in one line. "

'user@:~$' • ls -1 *.jpg | while read foo; do echo cp $foo ~/$(basename $foo .jpg).avi;done
'user@:~$' • ls -1 *.jpg | while read foo; do echo cp $foo ~/${foo%.jpg}.avi;done

Exercise 9:

Create a Linux CLI oneliner to decode the following string 'SWYgeW91IGNhbiByZWFkIHRoaXMsIHlvdSBmb3VuZCB0aGUgY29ycmVjdCBhbnN3ZXIK'

'user@:~$'echo 'SWYgeW91IGNhbiByZWFkIHRoaXMsIHlvdSBmb3VuZCB0aGUgY29ycmVjdCBhbnN3ZXIK' | openssl enc -a -d

'user@:~$'echo 'SWYgeW91IGNhbiByZWFkIHRoaXMsIHlvdSBmb3VuZCB0aGUgY29ycmVjdCBhbnN3ZXIK' | base64 -d

Exercise 10:

Create a regular expression to match all words in a dictionary with 5 unique letters. "

'user@:~$' • cat /usr/share/dict/dutch | grep -P '^[a-zA-Z]{5}$'| grep -vP '(.).*\1'

Exercise 11:

Create a oneliner to show ‘Time = 15:44:25 (11/10/1901)' or 'Time = 15:44:25 (11-10-1901)’ each time with the current time and date.

'user@:~$'echo "Time = $(date '+%X (%x)')"
'user@:~$' • date '+Time = %X (%x)'
'user@:~$' • date '+Time = %X (%Y/%d/%m)'

Exercise 12:

Create a oneliner which lists the top 3 most used passwords in the ftp brute force attack captured in "ftp_bruteforce.pcap". Use a suitable sniffer filter which only displays whats really needed.

'user@:~$' • tshark -r ftp_bruteforce.pcap -Y 'ftp.request.command==PASS' -T fields -e 'ftp.request.arg' 2>/dev/null| sort | uniq -c | sort -rn | head -3

Revision #1
Created 17 June 2021 14:15:56 by Jasper G.
Updated 3 December 2021 22:13:09 by Jasper G.