<s> """<STR_LIT>""" <EOL> import sys , re , os <EOL> from spider import htmlencode <EOL> from xml . sax import * <EOL> jsAnalyzerBin = None <EOL> jsAnalyzerInputParam = None <EOL> jsAnalyzerOutputParam = None <EOL> jsAnalyzerConfParam = None <EOL> jsAnalyzerConfFile = None <EOL> jsAnalyzerExtension = None <EOL> jsAnalyzerPattern = None <EOL> jsDatabase = { } <EOL> """<STR_LIT>""" <EOL> def normalize_whitespace ( text ) : <EOL> return '<STR_LIT:U+0020>' . join ( text . split ( ) ) <EOL> def clear_whitespace ( text ) : <EOL> return text . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> class JavaScriptConfHandler ( ContentHandler ) : <EOL> def __init__ ( self ) : <EOL> self . inAnalyzer = False <EOL> self . string = "<STR_LIT>" <EOL> def startElement ( self , name , attrs ) : <EOL> global jsAnalyzerInputParam , jsAnalyzerOutputParam , jsAnalyzerConfParam <EOL> self . string = "<STR_LIT>" <EOL> self . currentKeys = [ ] <EOL> if name == '<STR_LIT>' : <EOL> self . inAnalyzer = True <EOL> elif name == '<STR_LIT:path>' and self . inAnalyzer : <EOL> if '<STR_LIT:input>' in attrs . keys ( ) and '<STR_LIT>' in attrs . keys ( ) : <EOL> jsAnalyzerInputParam = attrs . getValue ( '<STR_LIT:input>' ) <EOL> jsAnalyzerOutputParam = attrs . getValue ( '<STR_LIT>' ) <EOL> else : <EOL> raise KeyError ( "<STR_LIT>" ) <EOL> elif name == '<STR_LIT>' and self . inAnalyzer : <EOL> if '<STR_LIT>' in attrs . keys ( ) : <EOL> jsAnalyzerConfParam = attrs . getValue ( '<STR_LIT>' ) <EOL> else : <EOL> raise KeyError ( "<STR_LIT>" ) <EOL> def characters ( self , ch ) : <EOL> self . string = self . string + ch <EOL> def endElement ( self , name ) : <EOL> global jsAnalyzerBin , jsAnalyzerConfFile , jsAnalyzerExtension , jsAnalyzerPattern <EOL> if name == '<STR_LIT>' : <EOL> jsAnalyzerConfFile = normalize_whitespace ( self . string ) <EOL> elif name == '<STR_LIT>' and self . inAnalyzer : <EOL> jsAnalyzerExtension = normalize_whitespace ( self . string ) <EOL> elif name == '<STR_LIT:path>' and self . inAnalyzer : <EOL> jsAnalyzerBin = normalize_whitespace ( self . string ) <EOL> elif name == "<STR_LIT>" : <EOL> self . inAnalyzer = False <EOL> elif name == "<STR_LIT>" : <EOL> jsAnalyzerPattern = normalize_whitespace ( self . string ) <EOL> def execCmd ( program , args ) : <EOL> buff = [ ] <EOL> p = os . popen ( program + "<STR_LIT:U+0020>" + args ) <EOL> buff = p . readlines ( ) <EOL> p . close ( ) <EOL> return buff <EOL> def generateListOfFiles ( localDB , urlGlobal ) : <EOL> global jsDatabase <EOL> """<STR_LIT>""" <EOL> regScripts = re . compile ( r'<STR_LIT>' + jsAnalyzerExtension + '<STR_LIT:$>' , re . I ) <EOL> localRegOutput = jsAnalyzerPattern <EOL> localRegOutput = localRegOutput . replace ( '<STR_LIT:(>' , '<STR_LIT>' ) <EOL> localRegOutput = localRegOutput . replace ( '<STR_LIT:)>' , '<STR_LIT>' ) <EOL> localRegOutput = localRegOutput . replace ( '<STR_LIT:[>' , '<STR_LIT>' ) <EOL> localRegOutput = localRegOutput . replace ( '<STR_LIT:]>' , '<STR_LIT>' ) <EOL> localRegOutput = localRegOutput . replace ( '<STR_LIT::>' , '<STR_LIT>' ) <EOL> localRegOutput = localRegOutput . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> localRegOutput = localRegOutput . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> localRegOutput = localRegOutput . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> regOutput = re . compile ( '<STR_LIT>' + localRegOutput + '<STR_LIT:$>' , re . I ) <EOL> print "<STR_LIT>" <EOL> for file in localDB : <EOL> print file <EOL> file = file . replace ( urlGlobal + '<STR_LIT:/>' , '<STR_LIT>' ) <EOL> fileIn = os . path . abspath ( os . path . join ( '<STR_LIT>' , file ) ) <EOL> cmdLine = jsAnalyzerConfParam + "<STR_LIT:U+0020>" + jsAnalyzerConfFile + "<STR_LIT:U+0020>" + jsAnalyzerInputParam + "<STR_LIT:U+0020>" + fileIn <EOL> if jsAnalyzerOutputParam != "<STR_LIT>" : <EOL> cmdLine += "<STR_LIT:U+0020>" + jsAnalyzerOutputParam + "<STR_LIT:U+0020>" + fileIn + '<STR_LIT>' <EOL> output = execCmd ( jsAnalyzerBin , cmdLine ) <EOL> for o in output : <EOL> lO = o . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) <EOL> if regOutput . match ( lO ) : <EOL> out = regOutput . search ( lO ) <EOL> if file not in jsDatabase : <EOL> jsDatabase [ file ] = { } <EOL> line = clear_whitespace ( out . group ( <NUM_LIT:2> ) ) <EOL> if line not in jsDatabase [ file ] : <EOL> jsDatabase [ file ] [ line ] = [ ] <EOL> jsDatabase [ file ] [ line ] . append ( normalize_whitespace ( out . group ( <NUM_LIT:3> ) ) ) <EOL> def process ( urlGlobal , localDB , attack_list ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" <EOL> try : <EOL> f = open ( "<STR_LIT>" , '<STR_LIT:r>' ) <EOL> f . close ( ) <EOL> except IOError : <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> parser = make_parser ( ) <EOL> js_handler = JavaScriptConfHandler ( ) <EOL> parser . setContentHandler ( js_handler ) <EOL> try : <EOL> parser . parse ( "<STR_LIT>" ) <EOL> except KeyError , e : <EOL> print e <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> generateListOfFiles ( localDB , urlGlobal ) <EOL> plop = open ( '<STR_LIT>' , '<STR_LIT:w>' ) <EOL> plop . write ( "<STR_LIT>" ) <EOL> plop . write ( "<STR_LIT>" ) <EOL> for file in jsDatabase : <EOL> plop . write ( "<STR_LIT>" % file ) <EOL> for line in jsDatabase [ file ] : <EOL> if len ( jsDatabase [ file ] [ line ] ) > <NUM_LIT:1> : <EOL> plop . write ( "<STR_LIT>" % line ) <EOL> for error in jsDatabase [ file ] [ line ] : <EOL> plop . write ( "<STR_LIT>" % htmlencode ( error ) ) <EOL> plop . write ( "<STR_LIT>" ) <EOL> else : <EOL> plop . write ( "<STR_LIT>" % ( line , htmlencode ( jsDatabase [ file ] [ line ] [ <NUM_LIT:0> ] ) ) ) <EOL> plop . write ( "<STR_LIT>" ) <EOL> plop . write ( "<STR_LIT>" ) <EOL> plop . write ( "<STR_LIT>" ) <EOL> plop . close ( ) </s>
