Øvelse 11 - Forstå bash script + tilrette script
Forfatter: Mathias Greisen
Dato: 2026-10-05
Fag/modul: Introduktion til IT-Sikkerhed
Status: Færdig
1. Beskrivelse af øvelsen
At kunne læse, forstå, tilrette og oprette bash scripts.
2. Reproduktion trin for trin
Forudsætninger
- linux med nmap installeret
Trin
-
Opret nmapScans.sh
-
Indtast script
#!/bin/bash #Add color to the shell output https://techstop.github.io/bash-script-colors/ RED='\033[0;31m' WHITE='\033[0;37m' NC='\033[0m' # no color echo -e "${RED}RUN THIS SCRIPT AS SUDO USER${WHITE}" if [ $# -eq 1 ]; then echo -e "Target ${RED}IP:$1${WHITE}" else echo "Your command line is incorrect" echo -e "Usage example: ${RED} sudo ./nmapScans.sh 10.10.10.121 ${WHITE}" exit 1 fi #Get the date, will be used in filename DATE=`date +%Y-%m-%d` filename=$1_$DATE echo -e "Running a ${RED} quick scan ${WHITE}..." nmap -T4 -F $1 > quick_nmapscan_$filename.txt echo -e "Results -> ${RED}quick_nmapscan_$filename.txt${WHITE}" exit 0 -
Rediger script til output af åbne porte til konsollen
#!/bin/bash #Add color to the shell output https://techstop.github.io/bash-script-colors/ RED='\033[0;31m' WHITE='\033[0;37m' NC='\033[0m' # no color echo -e "${RED}RUN THIS SCRIPT AS SUDO USER${WHITE}" if [ $# -eq 1 ]; then echo -e "Target ${RED}IP:$1${WHITE}" else echo "Your command line is incorrect" echo -e "Usage example: ${RED} sudo ./nmapScans.sh 10.10.10.121 ${WHITE}" exit 1 fi #Get the date, will be used in filename echo -e "Running a ${RED} quick scan ${WHITE}..." echo "" nmap -T4 -F $1 | grep open exit 0 -
Gem og afslut nano
- Gem
- CTRL + S
- Afslut
- CTRL + X
- Gem
-
Give tilladelse til at eksekvere
-
Kør script
3. Problemer og løsninger
Jeg oplevede ikke problemer under denne øvelse.
4. Anvendte ressourcer
5. Opsummering af erfaringer
Jeg har fået praktisk erfaring med at læse, forstå, tilrette og oprette bash scripts, samt at kunne formatere output via pipeline og grep.