Skip to content

Commit 4b60c41

Browse files
committed
Merge pull request #1 from PHPIDS/master
Merge
2 parents 24af393 + 849e5c5 commit 4b60c41

File tree

5 files changed

+118
-78
lines changed

5 files changed

+118
-78
lines changed

docs/examples/example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* GNU General Public License for more details.
1717
*/
1818

19-
require_once __DIR__.'/../../autoload.php';
19+
require_once __DIR__.'/../../vendor/autoload.php';
2020

2121
use IDS\Init;
2222
use IDS\Monitor;

lib/IDS/Caching/DatabaseCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ private function write($handle, $data)
261261
)'
262262
);
263263

264-
$statement->bindParam(
264+
$statement->bindValue(
265265
'type',
266266
$handle->quote($this->type)
267267
);
268-
$statement->bindParam('data', serialize($data));
268+
$statement->bindValue('data', serialize($data));
269269

270270
if (!$statement->execute()) {
271271
throw new \PDOException($statement->errorCode());

lib/IDS/Config/Config.ini.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
[Caching]
3838

39-
; caching: session|file|database|memcached|none
39+
; caching: session|file|database|memcached|apc|none
4040
caching = file
4141
expiration_time = 600
4242

@@ -53,3 +53,6 @@
5353
;host = localhost
5454
;port = 11211
5555
;key_prefix = PHPIDS
56+
57+
; apc
58+
;key_prefix = PHPIDS

lib/IDS/Filter/Storage.php

Lines changed: 106 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -225,47 +225,51 @@ public function getFilterFromXML()
225225
/*
226226
* Now the storage will be filled with IDS_Filter objects
227227
*/
228-
$data = array();
229228
$nocache = $filters instanceof \SimpleXMLElement;
230-
$filters = $nocache ? $filters->filter : $filters;
231-
232-
foreach ($filters as $filter) {
233-
$id = $nocache ? (string) $filter->id :
234-
$filter['id'];
235-
$rule = $nocache ? (string) $filter->rule :
236-
$filter['rule'];
237-
$impact = $nocache ? (string) $filter->impact :
238-
$filter['impact'];
239-
$tags = $nocache ? array_values((array) $filter->tags) :
240-
$filter['tags'];
241-
$description = $nocache ? (string) $filter->description :
242-
$filter['description'];
243-
244-
$this->addFilter(
245-
new \IDS\Filter(
246-
$id,
247-
$rule,
248-
$description,
249-
(array) $tags[0],
250-
(int) $impact
251-
)
252-
);
253-
254-
$data[] = array(
255-
'id' => $id,
256-
'rule' => $rule,
257-
'impact' => $impact,
258-
'tags' => $tags,
259-
'description' => $description
260-
);
261-
}
262-
263-
/*
264-
* If caching is enabled, the fetched data will be cached
265-
*/
266-
if ($this->cacheSettings) {
267-
268-
$this->cache->setCache($data);
229+
230+
if ($nocache)
231+
{
232+
// build filters and cache them for re-use on next run
233+
$data = array();
234+
$filters = $filters->filter;
235+
236+
foreach ($filters as $filter) {
237+
$id = (string) $filter->id;
238+
$rule = (string) $filter->rule;
239+
$impact = (string) $filter->impact;
240+
$tags = array_values((array) $filter->tags);
241+
$description = (string) $filter->description;
242+
243+
$this->addFilter(
244+
new \IDS\Filter(
245+
$id,
246+
$rule,
247+
$description,
248+
(array) $tags[0],
249+
(int) $impact
250+
)
251+
);
252+
253+
$data[] = array(
254+
'id' => $id,
255+
'rule' => $rule,
256+
'impact' => $impact,
257+
'tags' => $tags,
258+
'description' => $description
259+
);
260+
}
261+
262+
/*
263+
* If caching is enabled, the fetched data will be cached
264+
*/
265+
if ($this->cacheSettings) {
266+
$this->cache->setCache($data);
267+
}
268+
269+
} else {
270+
271+
// build filters from cached content
272+
$this->addFiltersFromArray($filters);
269273
}
270274

271275
return $this;
@@ -313,52 +317,85 @@ public function getFilterFromJson()
313317
/*
314318
* Now the storage will be filled with IDS_Filter objects
315319
*/
316-
$data = array();
317320
$nocache = !is_array($filters);
318-
$filters = $nocache ? $filters->filters->filter : $filters;
319-
320-
foreach ($filters as $filter) {
321-
322-
$id = $nocache ? (string) $filter->id :
323-
$filter['id'];
324-
$rule = $nocache ? (string) $filter->rule :
325-
$filter['rule'];
326-
$impact = $nocache ? (string) $filter->impact :
327-
$filter['impact'];
328-
$tags = $nocache ? array_values((array) $filter->tags) :
329-
$filter['tags'];
330-
$description = $nocache ? (string) $filter->description :
331-
$filter['description'];
332-
333-
$this->addFilter(
321+
322+
if ($nocache) {
323+
324+
// build filters and cache them for re-use on next run
325+
$data = array();
326+
$filters = $filters->filters->filter;
327+
328+
foreach ($filters as $filter) {
329+
330+
$id = (string) $filter->id;
331+
$rule = (string) $filter->rule;
332+
$impact = (string) $filter->impact;
333+
$tags = array_values((array) $filter->tags);
334+
$description = (string) $filter->description;
335+
336+
$this->addFilter(
334337
new \IDS\Filter(
335338
$id,
336339
$rule,
337340
$description,
338341
(array) $tags[0],
339342
(int) $impact
340-
)
341-
);
342-
343-
$data[] = array(
343+
)
344+
);
345+
346+
$data[] = array(
344347
'id' => $id,
345348
'rule' => $rule,
346349
'impact' => $impact,
347350
'tags' => $tags,
348351
'description' => $description
349-
);
350-
}
351-
352-
/*
353-
* If caching is enabled, the fetched data will be cached
354-
*/
355-
if ($this->cacheSettings) {
356-
$this->cache->setCache($data);
352+
);
353+
}
354+
355+
/*
356+
* If caching is enabled, the fetched data will be cached
357+
*/
358+
if ($this->cacheSettings) {
359+
$this->cache->setCache($data);
360+
}
361+
362+
} else {
363+
364+
// build filters from cached content
365+
$this->addFiltersFromArray($filters);
357366
}
358367

359368
return $this;
360369
}
361370

362371
throw new \RuntimeException('json extension is not loaded.');
363372
}
373+
374+
/**
375+
* This functions adds an array of filters to the IDS_Storage object.
376+
* Each entry within the array is expected to be an simple array containing all parts of the filter.
377+
*
378+
* @param array $filters
379+
*/
380+
private function addFiltersFromArray(array $filters)
381+
{
382+
foreach ($filters as $filter) {
383+
384+
$id = $filter['id'];
385+
$rule = $filter['rule'];
386+
$impact = $filter['impact'];
387+
$tags = $filter['tags'];
388+
$description = $filter['description'];
389+
390+
$this->addFilter(
391+
new \IDS\Filter(
392+
$id,
393+
$rule,
394+
$description,
395+
(array) $tags[0],
396+
(int) $impact
397+
)
398+
);
399+
}
400+
}
364401
}

lib/IDS/default_filter.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"id":"1",
66
"rule":"(?:\"[^\"]*[^-]?>)|(?:[^\\w\\s]\\s*\\\/>)|(?:>\")",
7-
"description":"finds html breaking injections including whitespace attacks",
7+
"description":"Finds html breaking injections including whitespace attacks",
88
"tags":{
99
"tag":[
1010
"xss",
@@ -16,7 +16,7 @@
1616
{
1717
"id":"2",
1818
"rule":"(?:\"+.*[<=]\\s*\"[^\"]+\")|(?:\"\\s*\\w+\\s*=)|(?:>\\w=\\\/)|(?:#.+\\)[\"\\s]*>)|(?:\"\\s*(?:src|style|on\\w+)\\s*=\\s*\")|(?:[^\"]?\"[,;\\s]+\\w*[\\[\\(])",
19-
"description":"finds attribute breaking injections including whitespace attacks",
19+
"description":"Finds attribute breaking injections including whitespace attacks",
2020
"tags":{
2121
"tag":[
2222
"xss",
@@ -28,7 +28,7 @@
2828
{
2929
"id":"3",
3030
"rule":"(?:^>[\\w\\s]*<\\\/?\\w{2,}>)",
31-
"description":"finds unquoted attribute breaking injections",
31+
"description":"Finds unquoted attribute breaking injections",
3232
"tags":{
3333
"tag":[
3434
"xss",
@@ -851,7 +851,7 @@
851851
{
852852
"id":"71",
853853
"rule":"(?:[\\s\\d\\\/\"]+(?:on\\w+|style|poster|background)=[$\"\\w])|(?:-type\\s*:\\s*multipart)",
854-
"description":"finds malicious attribute injection attempts and MHTML attacks",
854+
"description":"Finds malicious attribute injection attempts and MHTML attacks",
855855
"tags":{
856856
"tag":[
857857
"xss",
@@ -908,7 +908,7 @@
908908
{
909909
"id":"77",
910910
"rule":"(?:^(-0000023456|4294967295|4294967296|2147483648|2147483647|0000012345|-2147483648|-2147483649|0000023456|2.2250738585072007e-308|1e309)$)",
911-
"description":"Looking for intiger overflow attacks, these are taken from skipfish, except 2.2250738585072007e-308 is the \"magic number\" crash",
911+
"description":"Looking for integer overflow attacks, these are taken from skipfish, except 2.2250738585072007e-308 is the \"magic number\" crash",
912912
"tags":{
913913
"tag":[
914914
"sqli",

0 commit comments

Comments
 (0)