Пример #1
0
 /**
  * @param $row
  * @return array|bool|mixed|object
  */
 private function unserializeRow($row)
 {
     if ($row) {
         $json = wfWAFUtils::json_decode($row, true);
         if (is_array($json)) {
             foreach ($this->rowsToB64 as $index) {
                 if (array_key_exists($index, $json)) {
                     $json[$index] = base64_decode($json[$index]);
                 }
             }
             return $json;
         }
     }
     return false;
 }
Пример #2
0
 public function fire()
 {
     $waf = $this->getWaf();
     if (!$waf) {
         return;
     }
     $guessSiteURL = sprintf('%s://%s/', $waf->getRequest()->getProtocol(), $waf->getRequest()->getHost());
     try {
         $request = new wfWAFHTTP();
         $request->setHeaders(array('Content-Type' => 'application/json'));
         $response = wfWAFHTTP::post(WFWAF_API_URL_SEC . "?" . http_build_query(array('action' => 'send_waf_attack_data', 'k' => $waf->getStorageEngine()->getConfig('apiKey'), 's' => $waf->getStorageEngine()->getConfig('siteURL') ? $waf->getStorageEngine()->getConfig('siteURL') : $guessSiteURL, 't' => microtime(true)), null, '&'), '[]', $request);
         if ($response instanceof wfWAFHTTPResponse && $response->getBody()) {
             $jsonData = wfWAFUtils::json_decode($response->getBody(), true);
             if (array_key_exists('data', $jsonData) && array_key_exists('watchedIPList', $jsonData['data'])) {
                 $waf->getStorageEngine()->setConfig('watchedIPs', $jsonData['data']['watchedIPList']);
             }
         }
     } catch (wfWAFHTTPTransportException $e) {
         error_log($e->getMessage());
     }
 }
Пример #3
0
 public function fire()
 {
     $waf = $this->getWaf();
     if (!$waf) {
         return;
     }
     $guessSiteURL = sprintf('%s://%s/', $waf->getRequest()->getProtocol(), $waf->getRequest()->getHost());
     try {
         $this->response = wfWAFHTTP::get(WFWAF_API_URL_SEC . "?" . http_build_query(array('action' => 'get_waf_rules', 'k' => $waf->getStorageEngine()->getConfig('apiKey'), 's' => $waf->getStorageEngine()->getConfig('siteURL') ? $waf->getStorageEngine()->getConfig('siteURL') : $guessSiteURL, 'h' => $waf->getStorageEngine()->getConfig('homeURL') ? $waf->getStorageEngine()->getConfig('homeURL') : $guessSiteURL, 'openssl' => $waf->hasOpenSSL() ? 1 : 0, 'betaFeed' => (int) $waf->getStorageEngine()->getConfig('betaThreatDefenseFeed')), null, '&'));
         if ($this->response) {
             $jsonData = wfWAFUtils::json_decode($this->response->getBody(), true);
             if (is_array($jsonData)) {
                 if ($waf->hasOpenSSL() && isset($jsonData['data']['signature']) && isset($jsonData['data']['rules']) && $waf->verifySignedRequest(base64_decode($jsonData['data']['signature']), $jsonData['data']['rules'])) {
                     $waf->updateRuleSet(base64_decode($jsonData['data']['rules']), isset($jsonData['data']['timestamp']) ? $jsonData['data']['timestamp'] : true);
                     if (array_key_exists('premiumCount', $jsonData['data'])) {
                         $waf->getStorageEngine()->setConfig('premiumCount', $jsonData['data']['premiumCount']);
                     }
                 } else {
                     if (!$waf->hasOpenSSL() && isset($jsonData['data']['hash']) && isset($jsonData['data']['rules']) && $waf->verifyHashedRequest($jsonData['data']['hash'], $jsonData['data']['rules'])) {
                         $waf->updateRuleSet(base64_decode($jsonData['data']['rules']), isset($jsonData['data']['timestamp']) ? $jsonData['data']['timestamp'] : true);
                         if (array_key_exists('premiumCount', $jsonData['data'])) {
                             $waf->getStorageEngine()->setConfig('premiumCount', $jsonData['data']['premiumCount']);
                         }
                     }
                 }
             }
         }
     } catch (wfWAFHTTPTransportException $e) {
         error_log($e->getMessage());
     } catch (wfWAFBuildRulesException $e) {
         error_log($e->getMessage());
     }
 }
 public function countryBypassRedirURL($countryBlocks = null)
 {
     if (!isset($countryBlocks)) {
         try {
             $countryBlocksJSON = wfWAF::getInstance()->getStorageEngine()->getConfig('countryBlocks');
         } catch (Exception $e) {
             return false;
         }
     }
     $countryBlocks = @wfWAFUtils::json_decode($countryBlocksJSON, true);
     if (is_array($countryBlocks)) {
         return $countryBlocks['bypassRedirDest'];
     }
     return false;
 }