diff --git a/run.sh b/run.sh index dcbcdf2..40bbd62 100755 --- a/run.sh +++ b/run.sh @@ -1,7 +1,8 @@ -#!/bin/sh +#!/bin/bash -current_time=$(date "+%Y.%m.%d-%H.%M") -if [[ -z $upload ]] +upload="${upload:-}" +current_time="$(date "+%Y.%m.%d-%H.%M")" +if [ -z "$upload" ] then root_dir=/shared/ else @@ -10,48 +11,47 @@ else mkdir /reports fi -report_extension="tex" +report_extension="${format:-tex}" -if [[ ! -z $format ]] -then - report_extension=$format -fi +xml_dir="xml_files/$current_time" +report_file="reports/report_$current_time.$report_extension" +report_file_path="${root_dir}${report_file}" -xml_dir=xml_files/$current_time -report_file=reports/report_$current_time.$report_extension - -function upload { - if [[ -z $upload ]] +upload() { + if [ -z "$upload" ] then return - elif [ $upload = "aws" ] + fi + if [ "$upload" = "aws" ] then - python /aws_push.py $1 - elif [ $upload = "gcp" ] + python /aws_push.py "$1" + elif [ "$upload" = "gcp" ] then - python /gcp_push.py $1 + python /gcp_push.py "$1" fi } -function get_filename(){ - echo $1 | tr / - +get_filename() { + echo "$1" | tr / - } -mkdir $root_dir$xml_dir +mkdir -p "$root_dir$xml_dir" while IFS= read -r line do - current_time=$(date "+%Y.%m.%d-%H.%M.%S") - filename=$(get_filename $line)".xml" - nmap -sV -oX $root_dir$xml_dir/$filename -oN - -v1 $@ --script=vulners/vulners.nse $line - upload $xml_dir/$filename + current_time="$(date "+%Y.%m.%d-%H.%M.%S")" + filename="$(get_filename "$line").xml" + # $@ without quotes required to expand additional options + # shellcheck disable=SC2068 + nmap -sV -oX "$root_dir$xml_dir/$filename" -oN - -v1 $@ --script=vulners/vulners.nse "$line" + upload "$xml_dir/$filename" done < /shared/ips.txt -python /output_report.py $root_dir$xml_dir $root_dir$report_file /shared/ips.txt -if [[ $report_extension = "tex" ]] +python /output_report.py "$root_dir$xml_dir" "$report_file_path" /shared/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' "$report_file_path" + sed -i 's/\$/\\\$/g' "$report_file_path" + sed -i 's/#/\\#/g' "$report_file_path" + sed -i 's/%/\\%/g' "$report_file_path" fi -upload $report_file +upload "$report_file_path"