Esempio n. 1
0
 public function run($config, $client)
 {
     $startTime = Common::click();
     // 脚本开始执行时间
     $startRAM = Common::RAMclick();
     // 脚本结束执行时间
     $this->config = $config;
     $this->client = $client;
     $this->wafPHP = WAFPHP::getInstance();
     // 检测是否存在有效的白名单标识
     if ($this->checkWhiteFlag()) {
         Common::Log()->info(__METHOD__, sprintf('Session[%s] was in white list', $this->client['session']));
         return true;
     }
     // 若关闭ajax类型请求的挑战则当请求为ajax类型时直接返回
     if (Common::getConfig('challenge_ajax', $this->config) && Common::isAjax(Common::getConfig('ajax_flag', $this->config))) {
         // 避免验证码模式的Ajax请求被绕过
         if (!isset($this->client['post'][Challenge\VerifyCodeChallenge::CODE_CHALLENGE_FLAG])) {
             Common::Log()->info(__METHOD__, sprintf('The client was ajax request'));
             return true;
         }
     }
     // 当前IP达到指定开启挑战访问次数前直接返回
     $visitTimes = intval(Common::M()->get($this->client['ip'], self::IP_VISIT_TIMES_FLAG));
     $startChallengeTimes = Common::getConfig('ip_start_challenge_times', $this->config);
     if ($visitTimes < $startChallengeTimes) {
         $visitTimes++;
         Common::M()->set($this->client['ip'], $visitTimes, Common::getConfig('ip_start_challenge_lifetime', $this->config), self::IP_VISIT_TIMES_FLAG);
         Common::Log()->info(__METHOD__, sprintf('The client ip[%s] was overlook', $this->client['ip']));
         return true;
     }
     // 根据配置启用相应挑战模块
     $challengeType = Common::getConfig('challenge_model', $this->config);
     switch ($challengeType) {
         case 'js':
             $this->jsChallenge();
             break;
         case 'code':
             $this->CodeChallenge();
             break;
         case 'code-cn':
             $this->CodeChallenge(true);
             break;
         case 'proof-of-work':
             $this->ProofOfWorkChallenge();
             break;
         default:
             die('Undefined challenge model');
     }
     $startRAM = Common::click();
     // 脚本开始执行内存
     $endRAM = Common::RAMclick();
     // 脚本结束执行内存
     Common::Log()->debug(__METHOD__, sprintf('Running robot detection with type %s use time %fs,RAM %s', $challengeType, $endRAM - $startTime, $endRAM - $startRAM));
     return true;
 }
Esempio n. 2
0
 public static function Log()
 {
     $wafPHP = WAFPHP::getInstance();
     return $wafPHP->Log;
 }