<s> import os <EOL> import sys <EOL> runPath = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> sys . path . append ( os . path . join ( runPath , "<STR_LIT:..>" ) ) <EOL> from xml . sax import make_parser <EOL> from xml . sax . handler import ContentHandler <EOL> import argparse <EOL> from lib . ProgressBar import progressbar <EOL> from lib . Config import Configuration <EOL> import lib . DatabaseLayer as db <EOL> argparser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> argparser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = '<STR_LIT>' ) <EOL> args = argparser . parse_args ( ) <EOL> class ExploitHandler ( ContentHandler ) : <EOL> def __init__ ( self ) : <EOL> self . d2sec = [ ] <EOL> self . exploittag = False <EOL> self . elliottag = False <EOL> self . nametag = False <EOL> self . urltag = False <EOL> self . reltag = False <EOL> self . refcvetag = False <EOL> self . tag = False <EOL> self . refl = [ ] <EOL> def startElement ( self , name , attrs ) : <EOL> if name == '<STR_LIT>' : <EOL> self . elliottag = True <EOL> if name == '<STR_LIT>' and self . elliottag : <EOL> self . exploittag = True <EOL> if self . exploittag : <EOL> self . tag = name <EOL> if self . tag == '<STR_LIT:name>' : <EOL> self . nametag = True <EOL> self . name = "<STR_LIT>" <EOL> elif self . tag == '<STR_LIT:url>' : <EOL> self . urltag = True <EOL> self . url = "<STR_LIT>" <EOL> elif self . tag == '<STR_LIT>' : <EOL> self . reftag = True <EOL> self . reftype = attrs . getValue ( '<STR_LIT:type>' ) <EOL> if self . reftype == '<STR_LIT>' : <EOL> self . refcvetag = True <EOL> self . cveref = "<STR_LIT>" <EOL> elif self . reftype != '<STR_LIT>' : <EOL> self . refcvetag = False <EOL> self . cveref = False <EOL> def characters ( self , ch ) : <EOL> if self . nametag : <EOL> self . name += ch <EOL> elif self . urltag : <EOL> self . url += ch <EOL> elif self . refcvetag : <EOL> self . cveref += ch <EOL> def endElement ( self , name ) : <EOL> if name == '<STR_LIT>' : <EOL> if self . cveref != "<STR_LIT>" and self . cveref : <EOL> self . refl . append ( self . cveref . rstrip ( ) ) <EOL> self . reftag = False <EOL> if name == '<STR_LIT:name>' : <EOL> self . nametag = False <EOL> if name == '<STR_LIT:url>' : <EOL> self . urltag = False <EOL> if name == '<STR_LIT>' : <EOL> self . reftag = False <EOL> if name == '<STR_LIT>' : <EOL> for refl in self . refl : <EOL> self . d2sec . append ( { '<STR_LIT:name>' : self . name , '<STR_LIT:url>' : self . url , '<STR_LIT:id>' : refl } ) <EOL> self . exploittag = False <EOL> self . refl = [ ] <EOL> if name == '<STR_LIT>' : <EOL> self . elliottag = False <EOL> d2securl = Configuration . getd2secDict ( ) <EOL> parser = make_parser ( ) <EOL> ch = ExploitHandler ( ) <EOL> parser . setContentHandler ( ch ) <EOL> try : <EOL> f = Configuration . getFile ( d2securl ) <EOL> except : <EOL> sys . exit ( "<STR_LIT>" % ( d2securl ) ) <EOL> i = db . getLastModified ( "<STR_LIT>" ) <EOL> if i is not None : <EOL> if f . headers [ '<STR_LIT>' ] == i : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> parser . parse ( f ) <EOL> exploitList = [ ] <EOL> for exploit in progressbar ( ch . d2sec ) : <EOL> print ( exploit ) <EOL> if args . v : <EOL> print ( exploit ) <EOL> exploitList . append ( exploit ) <EOL> db . bulkUpdate ( "<STR_LIT>" , exploitList ) <EOL> db . setColUpdate ( '<STR_LIT>' , f . headers [ '<STR_LIT>' ] ) </s>
