From 53a04dccd579ef7159241a9eb064111a8cf2db44 Mon Sep 17 00:00:00 2001 From: Lukas Koenen <lukas.koenen@h-da.de> Date: Mon, 20 Feb 2023 11:21:39 +0100 Subject: [PATCH] refactor: cleanup up run script --- run.sh | 65 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/run.sh b/run.sh index 9936387..d4d8965 100755 --- a/run.sh +++ b/run.sh @@ -4,14 +4,6 @@ ip6_regex="(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|( ip4_regex="((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" current_time=$(date "+%Y.%m.%d-%H.%M") -if [[ -z $upload ]] -then - root_dir=/shared/ -else - root_dir=/ - mkdir /xml_files - mkdir /reports -fi report_extension="tex" @@ -20,26 +12,34 @@ then report_extension=$format fi -xml_dir=xml_files/$current_time -report_file=reports/report_$current_time.$report_extension +root_dir=/shared +xml_dir=xml_files +report_dir=reports +report_file=report_$current_time.$report_extension +xml_subdir=$xml_dir/$current_time if [[ ! -z $project ]] then - xml_dir=xml_files/$current_time/$project - report_file=reports/report_$project\_$current_time.$report_extension + xml_subdir=$xml_dir/$project/$current_time + report_file=report_$project\_$current_time.$report_extension fi function upload { if [[ -z $upload ]] then return - elif [ $upload = "aws" ] - then - python /aws_push.py $1 - elif [ $upload = "gcp" ] - then - python /gcp_push.py $1 + else + cp -r $root_dir/$xml_dir / + cp -r $root_dir/$report_dir / + + if [ $upload = "aws" ] + then + python /aws_push.py $1 + elif [ $upload = "gcp" ] + then + python /gcp_push.py $1 + fi fi } @@ -47,10 +47,13 @@ function get_filename(){ echo $1 | tr / - } -mkdir -p $root_dir$xml_dir +mkdir -p $root_dir/$report_dir +mkdir -p $root_dir/$xml_dir + +rm -rf $root_dir/$xml_dir/* +rm -rf $root_dir/$report_dir/* -rm -rf $root_dir/xml_files/* -rm -rf $root_dir/report_files/* +mkdir -p $root_dir/$xml_subdir while IFS= read -r line do @@ -58,22 +61,22 @@ do filename=$(get_filename $line)".xml" if [[ $line =~ $ip6_regex ]] then - nmap -Pn -sV -oX $root_dir$xml_dir/$filename -oN - -v1 -6 $@ --script=vulners/vulners.nse,ssh-auth-methods.nse $line + nmap -Pn -sV -oX $root_dir/$xml_subdir/$filename -oN - -v1 -6 $@ --script=vulners/vulners.nse,ssh-auth-methods.nse $line elif [[ $line =~ $ip4_regex ]] then - nmap -Pn -sV -oX $root_dir$xml_dir/$filename -oN - -v1 $@ --script=vulners/vulners.nse,ssh-auth-methods.nse $line + nmap -Pn -sV -oX $root_dir/$xml_subdir/$filename -oN - -v1 $@ --script=vulners/vulners.nse,ssh-auth-methods.nse $line else return -1 fi - upload $xml_dir/$filename -done < /shared/ips.txt + upload $xml_subdir/$filename +done < $root_dir/ips.txt -python /output_report.py $root_dir$xml_dir $root_dir$report_file /shared/ips.txt +python /output_report.py $root_dir/$xml_subdir $root_dir/$report_dir/$report_file $root_dir/ips.txt if [[ $report_extension = "tex" ]] then - sed -i 's/_/\\_/g' $root_dir$report_file - sed -i 's/\$/\\\$/g' $root_dir$report_file - sed -i 's/#/\\#/g' $root_dir$report_file - sed -i 's/%/\\%/g' $root_dir$report_file + sed -i 's/_/\\_/g' $root_dir/$report_dir/$report_file + sed -i 's/\$/\\\$/g' $root_dir/$report_dir/$report_file + sed -i 's/#/\\#/g' $root_dir/$report_dir/$report_file + sed -i 's/%/\\%/g' $root_dir/$report_dir/$report_file fi -upload $report_file +upload $report_dir/$report_file -- GitLab