mStorage=&$storage; $this->mRequest=$request; $this->mTags=$tags; } } /** * Starts the detection mechanism and returns IDSReport * * @access public * @return IDSReport */ function &Run() { $report=&new IDSReport(); if(!empty($this->mRequest)) { foreach ($this->mRequest as $key => $value) { $this->Iterate($key, $value, $report); } } return $report; } /** * Iterates through given data and delegates it * to IDSMonitor::Detect() in order to check for malicious * appearing fragments * * @access private * @param mixed $key * @param mixed $value * @param IDSReport $report */ function Iterate($key, $value, &$report) { if (!is_array($value)) { if (is_string($value)) { $filters=$this->Detect($key, $value); if (!is_null($filters)) { $event=&new IDSEvent($key, $value, $filters); $report->AddEvent($event); } } } else { foreach ($value as $subKey => $subValue) { $this->Iterate($key . '.' . $subKey, $subValue, $report); } } } /** * Checks whether given value matches any of the supplied * filter patterns * * @access private * @param mixed $key * @param mixed $value * @return array */ function Detect($key, $value) { if (preg_match('/[^\w\s\/]+/ims', $value) && !empty($value)) { if (in_array($key, $this->mExceptions, true)) return null; $value=IDSConverter::Convert($value); $value=get_magic_quotes_gpc() ? stripslashes($value) : $value; $key=($this->mScanKeys) ? IDSConverter::Convert($key) : $key; $filters=array(); $filterSet=$this->mStorage->FilterSet(); for ($i=0; $imTags)) { if (array_intersect($this->mTags, $filter->Tags())) { if ($this->Match($key, $value, $filter)) $filters[]=&$filter; } } else { if ($this->Match($key, $value, $filter)) $filters[]=&$filter; } } return empty($filters) ? null : $filters; } } /** * Matches given value and/or key against given filter * * @access private * @param string $value * @param IDSFilter $filter * @return bool */ function Match($key, $value, &$filter) { if ($this->mScanKeys) { if ($filter->Match($key)) return true; } return $filter->Match($value); } /** * Sets exception array * * @access public * @param mixed $exceptions */ function SetExceptions($exceptions) { if (!is_array($exceptions)) $exceptions=array($exceptions); $this->mExceptions=$exceptions; } /** * Returns exception array * * @access public * @return array */ function Exceptions() { return $this->mExceptions; } /** * Sets boolean value for scan keys * * @access public * @param bool $exceptions */ function SetScanKeys($scanKeys) { if (!is_bool($scanKeys)) error('Expected $scanKeys to be a boolen, ' . gettype($scanKeys) . ' given'); $this->mScanKeys=$scanKeys; } /** * Returns value for scan keys * * @access public * @return bool */ function ScanKeys() { return $this->mScanKeys; } } ?>