koenbuyens / securityheaders

Check any website (or set of websites) for insecure security headers.
Apache License 2.0
232 stars 47 forks source link

mulit-site functionality #14

Open BustedSec opened 1 year ago

BustedSec commented 1 year ago

I created the following bash script so your program can process multiple sites and output them all as text files and compress them.

#!/bin/bash

# Ask the user for the filename
echo "Please enter the filename:"
read filename

# Check if the file exists
if [ ! -f "$filename" ]; then
    echo "File not found!"
    exit 1
fi

# Create a results directory
mkdir -p results

# Read each line from the file
while IFS= read -r line
do
    # Split the line by ':' and get the first part
    host=${line%%:*}

    # Inform the user of the current progress
    echo "Processing $host"

    # Run the program with the host, remove ANSI colors and redirect output to a temporary file
    # The timeout command will terminate the python command if it runs for more than 30 seconds
    timeout 30 python3 ./securityheaders.py "$host" | sed 's/\x1b\[[0-9;]*m//g' > "${host}.tmp" 2>>errors.log

    # If the python command was terminated by the timeout command, print an error message
    if [ $? -eq 124 ]; then
        echo "Command timed out for host: $host" | tee -a errors.log
    fi

    # Check if the output file is zero size
    if [ ! -s "${host}.tmp" ]; then
        echo "$host file is zero size" >> logs.txt
        rm "${host}.tmp"
    else
        mv "${host}.tmp" "results/${host}.txt"
    fi
done < "$filename"

# Wait for all background processes to finish
wait

# Compress the results directory
zip -r results.zip results/

# Print a completion message
echo "Script completed successfully!"