码迷,mamicode.com
首页 > Web开发 > 详细

网站防篡改脚本

时间:2018-09-25 19:38:23      阅读:465      评论:0      收藏:0      [点我收藏+]

标签:目录   qq邮箱   检测   sum   script   定义   dep   count   cto   

这是我生产中所用的防篡改脚本需要的拿走点赞.

扫描定义的数组目录的所有文件的MD5值,然后在用下面个脚本对比
1.2.2.4 扫描deploy目录的md5值脚本
[root@localhost 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下指定的目录如果异常发送邮件
[root@localhost 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邮箱157@qq.com <$log
           exit 0
        else 
           exit 3
    fi
      done

技术分享图片
技术分享图片

网站防篡改脚本

标签:目录   qq邮箱   检测   sum   script   定义   dep   count   cto   

原文地址:http://blog.51cto.com/ygtq666/2285519

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!