Skip to content

Commit

Permalink
Merge pull request #1 from rsf92/master
Browse files Browse the repository at this point in the history
Refactor script.
  • Loading branch information
v4d1 authored Jan 9, 2022
2 parents eab0b42 + 856c076 commit b5233eb
Showing 1 changed file with 73 additions and 59 deletions.
132 changes: 73 additions & 59 deletions SpoofThatMail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,74 @@ GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

help () {
echo "Accepted parameters:\n"
echo "Use -d along with a domain name, example sh SpoofThatMail.sh -d domain.com"
echo "Null string will be detected and ignored\n"
echo "Use -f along with a file containing domain names, example sh SpoofThatMail.sh -f domains.txt"
echo "Note that the path provided for the file must be a valid one\n"
}

check_url () {
domain=$1

retval=0
output=$(nslookup -type=txt _dmarc."$domain")
case "$output" in
*p=reject*)
echo "$domain is ${GREEN}NOT vulnerable${NC}"
;;
*p=quarantine*)
echo "$domain ${YELLOW}can be vulnerable${NC} (email will be sent to spam)"
;;
*p=none*)
echo "$domain is ${RED}vulnerable${NC}"
retval=1
;;
*)
echo "$domain is ${RED}vulnerable${NC} (No DMARC record found)"
retval=1
;;
esac
return $retval
}

check_file () {

input=$1

COUNTER=0
VULNERABLES=0
while IFS= read -r line
do
COUNTER=$((COUNTER=COUNTER+1))
check_url $line
VULNERABLES=$((VULNERABLES=VULNERABLES+$?))
done < $input
echo "\n$VULNERABLES out of $COUNTER domains are ${RED}vulnerable ${NC}"

}

main () {

while getopts d:f: flag
do
case "${flag}" in
f) file=${OPTARG};;
d) domain=${OPTARG};;
esac
done

if [ -n "$domain" ]; then
check_url $domain
elif [ -f "$file" ]; then
check_file $file
else
help
fi

}

echo "
███████╗██████╗ ██████╗ ██████╗ ███████╗
██╔════╝██╔══██╗██╔═══██╗██╔═══██╗██╔════╝
Expand All @@ -21,64 +89,10 @@ echo "
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚══════╝ by securihub.com
"


while getopts vd:f: flag
do
case "${flag}" in
f) file=${OPTARG};;
d) domain=${OPTARG};;
esac
done

if [ -z "$domain" ]
then
if [ -z "$file" ]
then
echo "Missing params"
else
COUNTER=0
VULNERABLES=0
input=$file
while IFS= read -r line
do

COUNTER=$((COUNTER=COUNTER+1))
output=$(nslookup -type=txt _dmarc."$line")
case "$output" in
*p=reject*)
echo "$line is ${GREEN}NOT vulnerable${NC}"
;;
*p=quarantine*)
echo "$line ${YELLOW}can be vulnerable${NC} (email will be sent to spam)"
;;
*p=none*)
echo "$line is ${RED}vulnerable${NC}"
VULNERABLES=$((VULNERABLES=VULNERABLES+1))
;;
*)
echo "$line is ${RED}vulnerable${NC} (No DMARC record found)"
VULNERABLES=$((VULNERABLES=VULNERABLES+1))
;;
esac
done < $file
echo "\n$VULNERABLES out of $COUNTER domains are ${RED}vulnerable ${NC}"
fi
else
output=$(nslookup -type=txt _dmarc."$domain")
case "$output" in
*p=reject*)
echo "$domain is ${GREEN}NOT vulnerable${NC}"
;;
*p=quarantine*)
echo "$domain ${YELLOW}can be vulnerable${NC} (email will be sent to spam)"
;;
*p=none*)
echo "$domain is ${RED}vulnerable${NC}"
;;
*)
echo "$domain is ${RED}vulnerable${NC} (No DMARC record found)"
;;
esac
if [ $# != 2 ];then
echo "Wrong execution\n"
help
exit 0
fi

main $@

0 comments on commit b5233eb

Please sign in to comment.