#!/bin/bash # Ensuring the output file is empty > cspout.txt # Using curl to follow redirects and capture all headers curl -sIL --user-agent 'moz' -k "$1" | \ awk -v url="$1" -F': ' ' BEGIN { RED="\033[31m"; MAGENTA="\033[35m"; YELLOW="\033[93m"; CYAN="\033[36m"; BLUE="\033[34m"; RESET="\033[0m"; print RED "Starting curl request..." RESET; header_count=0; } { if ($0 ~ /^HTTP/) { header_count++; if (header_count > 1) { printf RED "---------------\n" RESET; } print RED $0 RESET; print $0 >> "cspout.txt"; next; } if (tolower($1) ~ /content-security-policy(-report-only)?/) { gsub(/; /, "\n\t", $2); printf MAGENTA "%s\033[0m:\n\t" RED "%s\033[0m\n", $1, $2; printf "%s: %s\n", $1, $2 >> "cspout.txt"; } else if (tolower($1) ~ /report-to|nel/) { gsub(/,/, ",\n\t", $2); printf YELLOW "%s\033[0m:\n\t" CYAN "%s\033[0m\n", $1, $2; printf "%s: %s\n", $1, $2 >> "cspout.txt"; } else { printf BLUE "%s\033[0m: " BLUE "%s\033[0m\n", $1, $2; printf "%s: %s\n", $1, $2 >> "cspout.txt"; } }' | perl -MURI::Escape -nle 'print uri_unescape($_)' # Summarizing the header information at the end echo -e "\nSummary of Response Codes and URLs:" >> cspout.txt awk '/^HTTP/ {print $2, $3}' cspout.txt | sort | uniq -c | awk '{print $3, $2, "[" $1 "]"}' | \ while read line; do echo -e "$line" done >> cspout.txt # Displaying the summary on stdout cat cspout.txt