예제 #1
0
파일: FilterTest.php 프로젝트: steph/PHPIDS
 public function testFilterSetFilterSet()
 {
     $this->init->config['General']['filter_type'] = IDS_FILTER_TYPE;
     $this->init->config['General']['filter_path'] = IDS_FILTER_SET;
     $storage = new Storage($this->init);
     $filter = array(new Filter(1, 'test', 'test2', array(), 1));
     $this->assertTrue($storage->setFilterSet($filter) instanceof Storage);
 }
예제 #2
0
 private function getFilterSet($type)
 {
     $init = Init::init(IDS_CONFIG);
     $init->config['General']['filter_type'] = strtolower($type);
     $init->config['General']['filter_path'] = constant('IDS_FILTER_SET_' . strtoupper($type));
     $init->config['Caching']['caching'] = 'none';
     $storage = new Storage($init);
     return $storage->getFilterSet();
 }
예제 #3
0
파일: Monitor.php 프로젝트: steph/PHPIDS
 /**
  * Checks whether given value matches any of the supplied filter patterns
  *
  * @param mixed $key   the key of the value to scan
  * @param mixed $value the value to scan
  *
  * @return Filter[] array of filter(s) that matched the value
  */
 private function detect($key, $value)
 {
     // define the pre-filter
     $preFilter = '([^\\w\\s/@!?\\.]+|(?:\\./)|(?:@@\\w+)|(?:\\+ADw)|(?:union\\s+select))i';
     // to increase performance, only start detection if value isn't alphanumeric
     if ((!$this->scanKeys || !$key || !preg_match($preFilter, $key)) && (!$value || !preg_match($preFilter, $value))) {
         return array();
     }
     // check if this field is part of the exceptions
     foreach ($this->exceptions as $exception) {
         $matches = array();
         if ($exception === $key || preg_match('((/.*/[^eE]*)$)', $exception, $matches) && isset($matches[1]) && preg_match($matches[1], $key)) {
             return array();
         }
     }
     // check for magic quotes and remove them if necessary
     if (function_exists('get_magic_quotes_gpc') && !get_magic_quotes_gpc()) {
         $value = preg_replace('(\\\\(["\'/]))im', '$1', $value);
     }
     // if html monitoring is enabled for this field - then do it!
     if (is_array($this->html) && in_array($key, $this->html, true)) {
         list($key, $value) = $this->purifyValues($key, $value);
     }
     // check if json monitoring is enabled for this field
     if (is_array($this->json) && in_array($key, $this->json, true)) {
         list($key, $value) = $this->jsonDecodeValues($key, $value);
     }
     // use the converter
     $value = Converter::runAll($value);
     $value = Converter::runCentrifuge($value, $this);
     // scan keys if activated via config
     $key = $this->scanKeys ? Converter::runAll($key) : $key;
     $key = $this->scanKeys ? Converter::runCentrifuge($key, $this) : $key;
     $filterSet = $this->storage->getFilterSet();
     if ($tags = $this->tags) {
         $filterSet = array_filter($filterSet, function (Filter $filter) use($tags) {
             return (bool) array_intersect($tags, $filter->getTags());
         });
     }
     $scanKeys = $this->scanKeys;
     $filterSet = array_filter($filterSet, function (Filter $filter) use($key, $value, $scanKeys) {
         return $filter->match($value) || $scanKeys && $filter->match($key);
     });
     return $filterSet;
 }