网站防篡改脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了网站防篡改脚本相关的知识,希望对你有一定的参考价值。
这是我生产中所用的防篡改脚本需要的拿走点赞.
扫描定义的数组目录的所有文件的MD5值,然后在用下面个脚本对比
1.2.2.4 扫描deploy目录的md5值脚本
[[email protected] scripts]# cat md5sum_check.sh
#!/bin/sh
path=(
/deploy/factory/tomcat/webapps
/deploy/passport/tomcat/webapps
/deploy/uniring/tomcat/webapps
/deploy/oms/tomcat/webapps
/deploy/rad/tomcat/webapps
/deploy/dubbo/tomcat/webapps
/deploy/nginx
)
[ -d /md5 ] || mkdir /md5 -p
md5_log=/md5/md5_$(date +%F).log
num_log=/md5/num_$(date +%F).log
LANG=en
for n in ${path[*]}
do
if [ ! -z $n ];then
find ${path[*]} -type f |xargs md5sum >$md5_log
find ${path[*]} -type f >$num_log
else
exit 1
fi
done
下面这个脚本放到定时任务每天晚上检测如果有异常就邮件报警
对比deploy下指定的目录如果异常发送邮件
[[email protected] scripts]# cat md5_detection.sh
#!/bin/sh
path=(
/deploy/factory/tomcat/webapps
/deploy/passport/tomcat/webapps
/deploy/uniring/tomcat/webapps
/deploy/oms/tomcat/webapps
/deploy/rad/tomcat/webapps
/deploy/dubbo/tomcat/webapps
/deploy/nginx
)
[ -d /md5 ] || mkdir -p /md5
md5_log=/md5/md5_$(date +%F).log
num_log=/md5/num_$(date +%F).log
num=$(cat $num_log|wc -l)
LANG=EN
while true
do
log=/md5/check.log
[ ! -f $log ] && touch $log
md5_count=$(md5sum -c $md5_log 2>/dev/null |grep FAILED|wc -l)
md5_FAILED=$(md5sum -c $md5_log 2>/dev/null |grep FAILED)
echo $md5_FAILED >>$log
for n in ${path[*]}
do
if [ ! -z $n ];then
num_count=$(find ${path[*]} -type f |wc -l)
find ${path[*]} -type f >/md5/new.log
fi
done
if [ $md5_count -ne 0 ] || [ $num_count -ne $num ];then
#if [ $md5_count -ne 0 ];then
diff $num_log /md5/new.log >>$log
mail -s "web site is misrepresented in $(date +%F %T)" QQ邮箱[email protected] <$log
exit 0
else
exit 3
fi
done
以上是关于网站防篡改脚本的主要内容,如果未能解决你的问题,请参考以下文章
精彩回顾 | Web安全防护实践探讨: ——如何预防SQL注入跨站脚本web页面防篡改等攻击技术?