Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3197fad

Browse files
committed
update of IDS checking method
1 parent 952c280 commit 3197fad

2 files changed

Lines changed: 747 additions & 10 deletions

File tree

lib/utils/detection.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,40 @@
2121
with sqlmap; if not, write to the Free Software Foundation, Inc., 51
2222
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
"""
24-
import re
25-
import urllib2
24+
import re, sre_constants
2625
from xml.dom import minidom
2726

27+
from lib.core.data import conf
28+
from lib.core.data import paths
2829
from lib.core.data import logger
2930

3031
rules = None
3132

33+
def __adjustGrammar(string):
34+
string = re.sub('\ADetects', 'Detected', string)
35+
string = re.sub('\Afinds', 'Found', string)
36+
string = re.sub('attempts\Z', 'attempt', string)
37+
string = re.sub('injections\Z', 'injection', string)
38+
string = re.sub('attacks\Z', 'attack', string)
39+
return string
40+
3241
def checkPayload(string):
3342
"""
3443
This method checks if the generated payload is detectable by the PHPIDS filter rules
3544
"""
3645
global rules
3746

3847
if not rules:
39-
url = 'https://svn.phpids.org/svn/trunk/lib/IDS/default_filter.xml'
40-
request = urllib2.Request(url)
41-
response = urllib2.urlopen(request)
42-
xmlrules = minidom.parse(response).documentElement
43-
response.close()
48+
file = open(paths.DETECTION_RULES_XML, 'r')
49+
xmlrules = minidom.parse(file).documentElement
50+
file.close()
4451
rules = []
4552
for xmlrule in xmlrules.getElementsByTagName("filter"):
4653
try:
4754
rule = re.compile(xmlrule.getElementsByTagName('rule')[0].childNodes[0].nodeValue)
48-
desc = xmlrule.getElementsByTagName('description')[0].childNodes[0].nodeValue
49-
desc = desc.replace('Detects', 'Detected').replace('finds', 'Found').replace('attempts', 'attempt').replace('injections', 'injection').replace('attacks', 'attack')
55+
desc = __adjustGrammar(xmlrule.getElementsByTagName('description')[0].childNodes[0].nodeValue)
5056
rules.append((rule, desc))
51-
except:
57+
except sre_constants.error: #some issues with some regex expressions in Python 2.5
5258
pass
5359

5460
for rule, desc in rules:

0 commit comments

Comments
 (0)