HomeBlogWebsite malware scanner script

my random thoughts

take 'em or leave 'em

Website malware scanner script

HomePrintE-mailPdf

Do you want a way to scan your websites for malware?  Sucuri.net has a free website malware scanner.  You can subscribe to their service which will monitor your sites for you and they will even clean up the site if it becomes infected.  But I can do the cleanup myself and thus just wanted something to monitor a group of websites for me and notify me of any compromises.

So, I threw together this little bash script that uses their website to tell me if any of my sites have been compromised.  I'm not a bash expert so it is pretty rudimentary but does the job.  I set up a cron job to run every 4 hours and it emails me if Sucuri has detected any malware on my sites.  

#!/bin/bash
EMAIL="
 This email address is being protected from spambots. You need JavaScript enabled to view it.
 "

#add your websites here sites[0]="google.com" sites[1]="bing.com" sites[2]="yahoo.com" #sites[3]="" #sites[4]="" #... SENDEMAIL=0 for s in "${sites[@]}" do WARNING=0 > /tmp/malwarecheck.txt lynx --dump http://sitecheck.sucuri.net/results/$s | sed -n "/Security report/,/Spam/p" >> /tmp/malwarecheck.txt while read line; do if [[ "$line" == *error* ]] then WARNING=1 fi done < /tmp/malwarecheck.txt if [ $WARNING -eq 1 ] then SENDEMAIL=1 echo "http://sitecheck.sucuri.net/results/$s:" >> /tmp/malwarecheckemail.txt cat /tmp/malwarecheck.txt >> /tmp/malwarecheckemail.txt echo "" >> /tmp/malwarecheckemail.txt echo "" >> /tmp/malwarecheckemail.txt fi done if [ $SENDEMAIL -eq 1 ] then mail -s "URGENT: Malware detected!" $EMAIL < /tmp/malwarecheckemail.txt fi rm /tmp/malwarecheck.txt 2> /dev/null rm /tmp/malwarecheckemail.txt 2> /dev/null