#!/usr/bin/env python import re, os, sys, locale from xml.sax import * # Need PyXML [http://pyxml.sourceforge.net/] """ Regular Expression Filter Fuzzer (CC) by nEUrOO http://rgaucher.info/beta/RegFuzzer v0.1: First version, only HTML/JavaScript filters """ html_header = """
""" html_footer = """ """ html_stream = None # list of patterns patterns = {} type_listOfType = ['client','sql','file','server', 'all'] type_AllType = 'all' type_ErrorType = 'error' def encodeHTML(s): s = s.replace("&", "&") s = s.replace("<", "<") s = s.replace(">", ">") s = s.replace("\"",""") return s def normalize_whitespace(text): return ' '.join(text.split()) def clear_whitespace(text): return text.replace(' ','') # Handle the XML file with a SAX Parser class InputHandler(ContentHandler): def __init__(self): self.inConf = False self.inInput = False self.inRegex = False self.inType = False self.inName = False self.string = "" self.curName = "" self.curReg = "" self.curType= "" def startElement(self, name, attrs): localName = name.lower() self.string = "" if name == 'reg-fuzzer': self.inConf = True elif name == 'input' and self.inConf: self.inInput = True self.curName = "" self.curReg = "" self.curType= "" elif name == 'name' and self.inInput: self.inName = True elif name == 'regex' and self.inInput: self.inRegex = True elif name == 'type' and self.inInput: self.inType = True def characters(self, ch): if self.inInput: self.string = self.string + ch def endElement(self, name): global patterns if name == 'input' and self.inInput: self.inInput = False # Include in the patterns if self.curName == '': import time self.curName = "test_date_" + str(time.clock()) else: if self.curType not in type_listOfType: self.curType = type_AllType if self.curName not in patterns: patterns[self.curName] = [self.curReg, self.curType] else: raise NameError, "The name of the input [%s] is already defined, this defintion will be skipped" % self.curName if name == 'name' and self.inName: self.inName = False self.curName = normalize_whitespace(self.string) if name == 'regex' and self.inRegex: self.inRegex = False self.curReg = normalize_whitespace(self.string) if name == 'type' and self.inType: self.inType = False self.curType = normalize_whitespace(self.string).lower() possibleCharsets_Client=["Hex-Url","Hex-Html","Latin1","UTF-8","UTF-7","UTF-16"] quotes = ["'", '"'] bracket_e = ">" bracket_s = "<" scripts = ['script', 'script','\0script','scri\0pt','scri\npt','*script'] dicoAttack = { 'client' : [ '_QUOTE__BRACKET_E__BRACKET_S__SCRIPT__BRACKET_E_alert(1);_BRACKET_S_/_SCRIPT__BRACKET_E_', '_QUOTE_ onmouseover=_QUOTE_alert(1)_QUOTE_', '_QUOTE_ style=_QUOTE_-moz-binding:url(http://tinyurl/fake)_QUOTE_' ] } """ def launchEncodings(iStr): import textencoder for c in possibleCharsets_Client: iStr = unicode(iStr) oStr = textencoder.convert(iStr, 'Latin1', c) language, output_encoding = locale.getdefaultlocale() print oStr.encode(output_encoding) """ def testRegExp(injStr, compRegExp): if not compRegExp.match(injStr): return injStr else: return None def fuzz_ClientSide(name, compRegExp): # print "\n# Pattern Name: ", name html_stream.write (("