Skip to content

Commit c7b48e1

Browse files
committed
Merge pull request PHPIDS#62 from Awnage/master
Add converter and filter to fix sqli bypass
2 parents 849e5c5 + 0046a59 commit c7b48e1

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

lib/IDS/Converter.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,26 @@ public static function convertFromProprietaryEncodings($value)
662662
return $value;
663663
}
664664

665+
/**
666+
* This method removes encoded sql # comments
667+
*
668+
* @param string $value the value to convert
669+
*
670+
* @static
671+
* @return string
672+
*/
673+
public static function convertFromUrlencodeSqlComment($value)
674+
{
675+
if (preg_match_all('/(?:\%23.*?\%0a)/im',$value,$matches)){
676+
$converted = $value;
677+
foreach($matches[0] as $match){
678+
$converted = str_replace($match,' ',$converted);
679+
}
680+
$value .= "\n" . $converted;
681+
}
682+
return $value;
683+
}
684+
665685
/**
666686
* This method is the centrifuge prototype
667687
*

lib/IDS/default_filter.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,17 @@
916916
]
917917
},
918918
"impact":"3"
919+
},
920+
{
921+
"id":"78",
922+
"rule":"(?:%23.*?%0a)",
923+
"description":"Detects SQL comment filter evasion",
924+
"tags":{
925+
"tag":[
926+
"format string"
927+
]
928+
},
929+
"impact":"4"
919930
}
920931
]
921932
}

lib/IDS/default_filter.xml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<filter>
33
<id>1</id>
44
<rule><![CDATA[(?:"[^"]*[^-]?>)|(?:[^\w\s]\s*\/>)|(?:>")]]></rule>
5-
<description>finds html breaking injections including whitespace attacks</description>
5+
<description>Finds html breaking injections including whitespace attacks</description>
66
<tags>
77
<tag>xss</tag>
88
<tag>csrf</tag>
@@ -12,7 +12,7 @@
1212
<filter>
1313
<id>2</id>
1414
<rule><![CDATA[(?:"+.*[<=]\s*"[^"]+")|(?:"\s*\w+\s*=)|(?:>\w=\/)|(?:#.+\)["\s]*>)|(?:"\s*(?:src|style|on\w+)\s*=\s*")|(?:[^"]?"[,;\s]+\w*[\[\(])]]></rule>
15-
<description>finds attribute breaking injections including whitespace attacks</description>
15+
<description>Finds attribute breaking injections including whitespace attacks</description>
1616
<tags>
1717
<tag>xss</tag>
1818
<tag>csrf</tag>
@@ -22,7 +22,7 @@
2222
<filter>
2323
<id>3</id>
2424
<rule><![CDATA[(?:^>[\w\s]*<\/?\w{2,}>)]]></rule>
25-
<description>finds unquoted attribute breaking injections</description>
25+
<description>Finds unquoted attribute breaking injections</description>
2626
<tags>
2727
<tag>xss</tag>
2828
<tag>csrf</tag>
@@ -719,7 +719,7 @@
719719
<filter>
720720
<id>71</id>
721721
<rule><![CDATA[(?:[\s\d\/"]+(?:on\w+|style|poster|background)=[$"\w])|(?:-type\s*:\s*multipart)]]></rule>
722-
<description>finds malicious attribute injection attempts and MHTML attacks</description>
722+
<description>Finds malicious attribute injection attempts and MHTML attacks</description>
723723
<tags>
724724
<tag>xss</tag>
725725
<tag>csrf</tag>
@@ -768,11 +768,20 @@
768768
<filter>
769769
<id>77</id>
770770
<rule><![CDATA[(?:^(-0000023456|4294967295|4294967296|2147483648|2147483647|0000012345|-2147483648|-2147483649|0000023456|2.2250738585072007e-308|1e309)$)]]></rule>
771-
<description>Looking for intiger overflow attacks, these are taken from skipfish, except 2.2250738585072007e-308 is the "magic number" crash</description>
771+
<description>Looking for integer overflow attacks, these are taken from skipfish, except 2.2250738585072007e-308 is the "magic number" crash</description>
772772
<tags>
773773
<tag>sqli</tag>
774774
<tag>id</tag>
775775
</tags>
776776
<impact>3</impact>
777777
</filter>
778+
<filter>
779+
<id>78</id>
780+
<rule><![CDATA[(?:%23.*?%0a)]]></rule>
781+
<description>Detects SQL comment filter evasion</description>
782+
<tags>
783+
<tag>format string</tag>
784+
</tags>
785+
<impact>4</impact>
786+
</filter>
778787
</filters>

tests/IDS/Tests/MonitorTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,14 +1041,15 @@ public function testSQLIList6()
10411041
select (select `user` from#
10421042
#cc
10431043
mysql.user limit 1)\'';
1044+
$exploits[] = 'id=(1 )and(0)union%23xDxD%0%23xDxD%0%23xDxD%0%23xDxD%0Aselect 1,database%23xDxD%0%23xDxD%0%23xDxD%0%23xDxD%0A(),3';
10441045

10451046
$this->_testForPlainEvent($exploits);
10461047

10471048
$test = new Monitor(
10481049
$this->init
10491050
);
10501051
$result = $test->run($exploits);
1051-
$this->assertEquals(876, $result->getImpact());
1052+
$this->assertEquals(899, $result->getImpact());
10521053
}
10531054

10541055
public function testDTList()
@@ -1257,7 +1258,12 @@ public function testOctalCCConverter()
12571258
$this->init
12581259
);
12591260
$result = $test->run($exploits);
1260-
$this->assertEquals(48, $result->getImpact());
1261+
if (function_exists('get_magic_quotes_gpc') and @get_magic_quotes_gpc()) {
1262+
$this->assertEquals(62, $result->getImpact());
1263+
}
1264+
else {
1265+
$this->assertEquals(48, $result->getImpact());
1266+
}
12611267
}
12621268

12631269
public function testHexCCConverter()

0 commit comments

Comments
 (0)