Skip to content

Instantly share code, notes, and snippets.

@irrashai
Last active March 29, 2019 14:40
Show Gist options
  • Select an option

  • Save irrashai/b9b2597b18a2f2e4482ca39f1514785b to your computer and use it in GitHub Desktop.

Select an option

Save irrashai/b9b2597b18a2f2e4482ca39f1514785b to your computer and use it in GitHub Desktop.
scan_wp.sh: A script to run WPScan on a list of wordpress sites then mails the new vulnerabilities
#!/bin/bash
# This script runs WPScan on a list of WP sites
# and mails new vulnerabilities to NOC
# List WP sites and other variables
wplist="<list-blogs-here>"
mailfrom="<insert-email-here"
mailto="<insert-email-here>"
path="/<path-to>/wpscan"
logfile="wpscan.log"
now=`date +%d/%m/%Y`
cd $path
if [ -e $logfile ] ; then
truncate -s 0 $logfile
fi
# Iterate through all WP blogs in wplist
for i in $wplist ; do
# Archiving old log
if [ -e $i-log.txt ] ; then
mv $i-log.txt $i-log.txt.old
RESULT1=$(grep -e '^\[\!\]\ Title' $i-log.txt.old)
else
RESULT1=""
fi
# Scanning blog for vulnerabilities
ruby wpscan.rb --url $i --update --enumerate vp,vt --follow-redirection --no-color --no-banner --batch --log
mv log.txt $i-log.txt
RESULT2=$(grep -e '^\[\!\]\ Title' $i-log.txt)
# Diff old and new scan
diff -u <(echo "$RESULT1") <(echo "$RESULT2") | grep '+' | grep -v "^---" | grep -v "^+++" | grep -v "^@" >> $i.diff
# Write results to logfile
if [[ `wc -l $i.diff | cut -d" " -f1` -gt 0 ]] ; then
echo -e "\n[$now] New vulnerabilities for $i:" >> $logfile
cat $i.diff | sed 's/^.\{5\}//' >> $logfile
attachparam="$attachparam -a $i-log.txt"
fi
done
# Send email if log is not empty
if [ -s $logfile ] ; then
/bin/mailx -s "WPScan Alert: New Vulnerabilities Found" $attachparam -r $mailfrom $mailto < $logfile
fi
# Cleanup
rm -f $logfile
rm -f $path/*.diff
rm -f $path/*.old
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment