|
21 | 21 | with sqlmap; if not, write to the Free Software Foundation, Inc., 51 |
22 | 22 | Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
23 | 23 | """ |
24 | | -import re |
25 | | -import urllib2 |
| 24 | +import re, sre_constants |
26 | 25 | from xml.dom import minidom |
27 | 26 |
|
| 27 | +from lib.core.data import conf |
| 28 | +from lib.core.data import paths |
28 | 29 | from lib.core.data import logger |
29 | 30 |
|
30 | 31 | rules = None |
31 | 32 |
|
| 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 | + |
32 | 41 | def checkPayload(string): |
33 | 42 | """ |
34 | 43 | This method checks if the generated payload is detectable by the PHPIDS filter rules |
35 | 44 | """ |
36 | 45 | global rules |
37 | 46 |
|
38 | 47 | 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() |
44 | 51 | rules = [] |
45 | 52 | for xmlrule in xmlrules.getElementsByTagName("filter"): |
46 | 53 | try: |
47 | 54 | 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) |
50 | 56 | rules.append((rule, desc)) |
51 | | - except: |
| 57 | + except sre_constants.error: #some issues with some regex expressions in Python 2.5 |
52 | 58 | pass |
53 | 59 |
|
54 | 60 | for rule, desc in rules: |
|
0 commit comments