提供免费教程下载和网站搭建技术教程,主要分享和发布网站源码,致力创造一个高质量网络资源教程的分享平台

EMLOG程序简易防CC攻击代码的教程

发布:dxs7788002020-3-31 11:22分类: 技术教程 标签: emlog

EMLOG程序没有自己的防护措施,找了一款PHP代码修改成EMLOG的。也就凑活用吧。本教程;来源em论坛,至于有没有用,舍力表示不清楚、不知道,因为舍力本身就不懂CC是什么东西(本博只为收藏,万一你正好需要呢).....不吓BB了,下面的代码(将下面代码插入在module.php文件内): 
代码一
<?php
function sheli_cc(){
       session_start();
$timestampcc = time();
$cc_nowtime = $timestampcc;
if(isset($_SESSION['cc_lasttime'])){$cc_lasttime = $_SESSION['cc_lasttime'];$cc_times = $_SESSION['cc_times']+1;$_SESSION['cc_times'] = $cc_times;
}else{$cc_lasttime = $cc_nowtime;$cc_times = 1;$_SESSION['cc_times'] = $cc_times;$_SESSION['cc_lasttime'] = $cc_lasttime;} 
if(($cc_nowtime-$cc_lasttime)<60){if($cc_times>=3){header(sprintf('Location:%s', 'http://127.0.0.1'));exit;}//60秒内刷新3次以上可能为cc攻击
}else{$cc_times = 0;$_SESSION['cc_lasttime'] = $cc_nowtime;$_SESSION['cc_times'] = $cc_times;}
}
?>
代码二
<?php
function sheli_cc(){
        //代理IP直接退出
        empty($_SERVER['HTTP_VIA']) or exit('Access Denied');
        //防止快速刷新
        session_start();
        $seconds = '60'; //时间段[秒]
        $refresh = '3'; //刷新次数
        //设置监控变量
        $cur_time = time();
        if(isset($_SESSION['last_time'])){
                $_SESSION['refresh_times'] += 1;
        }else{
                $_SESSION['refresh_times'] = 1;
                $_SESSION['last_time'] = $cur_time;
        }
        //处理监控结果
        if($cur_time - $_SESSION['last_time'] < $seconds){
                if($_SESSION['refresh_times'] >= $refresh){
                        //跳转至攻击者服务器地址
                        header(sprintf('Location:%s', 'http://127.0.0.1'));
                        exit('Access Denied');
                }
        }else{
                $_SESSION['refresh_times'] = 0;
                $_SESSION['last_time'] = $cur_time;
        }
}
?>
然后在head.php文件的require_once View::getView('module');后面插入echo sheli_cc();
  您阅读这篇文章共花了: 
温馨提示如有转载或引用以上内容之必要,敬请将本文链接作为出处标注,谢谢合作!

发表评论: