<s> '''<STR_LIT>''' <EOL> import logging <EOL> import os <EOL> import sys <EOL> import string <EOL> try : <EOL> from certfuzz import debuggers <EOL> from certfuzz . fuzztools import filetools , text <EOL> from certfuzz . file_handlers . basicfile import BasicFile <EOL> from certfuzz . minimizer import WindowsMinimizer as Minimizer <EOL> from certfuzz . campaign . config . foe_config import Config , get_command_args_list <EOL> from certfuzz . crash import FoeCrash <EOL> from certfuzz . debuggers import msec <EOL> except ImportError : <EOL> import sys <EOL> mydir = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> parentdir = os . path . abspath ( os . path . join ( mydir , '<STR_LIT:..>' ) ) <EOL> sys . path . append ( parentdir ) <EOL> from certfuzz import debuggers <EOL> from certfuzz . fuzztools import filetools , text <EOL> from certfuzz . file_handlers . basicfile import BasicFile <EOL> from certfuzz . minimizer import WindowsMinimizer as Minimizer <EOL> from certfuzz . campaign . config . foe_config import Config , get_command_args_list <EOL> from certfuzz . crash import FoeCrash <EOL> from certfuzz . debuggers import msec <EOL> logger = logging . getLogger ( ) <EOL> logger . setLevel ( logging . WARNING ) <EOL> def _create_minimizer_cfg ( cfg ) : <EOL> class DummyCfg ( object ) : <EOL> pass <EOL> config = DummyCfg ( ) <EOL> config . backtracelevels = <NUM_LIT:5> <EOL> config . debugger_timeout = cfg [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> template = string . Template ( cfg [ '<STR_LIT:target>' ] [ '<STR_LIT>' ] ) <EOL> config . get_command_args_list = lambda x : get_command_args_list ( template , x ) [ <NUM_LIT:1> ] <EOL> config . program = cfg [ '<STR_LIT:target>' ] [ '<STR_LIT>' ] <EOL> config . killprocname = None <EOL> config . exclude_unmapped_frames = False <EOL> config . watchdogfile = os . devnull <EOL> return config <EOL> def main ( ) : <EOL> debuggers . verify_supported_platform ( ) <EOL> from optparse import OptionParser <EOL> hdlr = logging . StreamHandler ( ) <EOL> logger . addHandler ( hdlr ) <EOL> usage = "<STR_LIT>" <EOL> parser = OptionParser ( usage ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:target>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT:-c>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> metavar = '<STR_LIT:N>' , type = '<STR_LIT:int>' , default = <NUM_LIT:0> , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> if options . debug : <EOL> logger . setLevel ( logging . DEBUG ) <EOL> else : <EOL> logger . setLevel ( logging . INFO ) <EOL> if options . config : <EOL> cfg_file = options . config <EOL> else : <EOL> cfg_file = "<STR_LIT>" <EOL> logger . debug ( '<STR_LIT>' , cfg_file ) <EOL> if options . stringmode and options . target : <EOL> parser . error ( '<STR_LIT>' ) <EOL> if not options . confidence : <EOL> if options . stringmode : <EOL> options . confidence = <NUM_LIT:0.5> <EOL> else : <EOL> options . confidence = <NUM_LIT> <EOL> if not options . initial_target_size : <EOL> if options . stringmode : <EOL> options . initial_target_size = <NUM_LIT:100> <EOL> else : <EOL> options . initial_target_size = <NUM_LIT:1> <EOL> if options . confidence : <EOL> try : <EOL> options . confidence = float ( options . confidence ) <EOL> except : <EOL> parser . error ( '<STR_LIT>' ) <EOL> if not <NUM_LIT:0.0> < options . confidence < <NUM_LIT:1.0> : <EOL> parser . error ( '<STR_LIT>' ) <EOL> confidence = options . confidence <EOL> if options . outdir : <EOL> outdir = options . outdir <EOL> else : <EOL> mydir = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> parentdir = os . path . abspath ( os . path . join ( mydir , '<STR_LIT:..>' ) ) <EOL> outdir = os . path . abspath ( os . path . join ( parentdir , '<STR_LIT>' ) ) <EOL> filetools . make_directories ( outdir ) <EOL> if len ( args ) and os . path . exists ( args [ <NUM_LIT:0> ] ) : <EOL> fuzzed_file = BasicFile ( args [ <NUM_LIT:0> ] ) <EOL> logger . info ( '<STR_LIT>' , fuzzed_file ) <EOL> else : <EOL> parser . error ( '<STR_LIT>' ) <EOL> config = Config ( cfg_file ) . config <EOL> cfg = _create_minimizer_cfg ( config ) <EOL> if options . target : <EOL> seedfile = BasicFile ( options . target ) <EOL> else : <EOL> seedfile = None <EOL> min2seed = not options . stringmode <EOL> filename_modifier = '<STR_LIT>' <EOL> retries = <NUM_LIT:0> <EOL> debugger_class = msec . MsecDebugger <EOL> template = string . Template ( config [ '<STR_LIT:target>' ] [ '<STR_LIT>' ] ) <EOL> cmd_as_args = get_command_args_list ( template , fuzzed_file . path ) [ <NUM_LIT:1> ] <EOL> with FoeCrash ( template , seedfile , fuzzed_file , cmd_as_args , None , debugger_class , <EOL> config [ '<STR_LIT>' ] , outdir , options . keep_uniq_faddr , config [ '<STR_LIT:target>' ] [ '<STR_LIT>' ] , <EOL> retries ) as crash : <EOL> filetools . make_directories ( crash . tempdir ) <EOL> logger . info ( '<STR_LIT>' , fuzzed_file . path , crash . tempdir ) <EOL> filetools . copy_file ( fuzzed_file . path , crash . tempdir ) <EOL> minlog = os . path . join ( outdir , '<STR_LIT>' ) <EOL> with Minimizer ( cfg = cfg , crash = crash , crash_dst_dir = outdir , <EOL> seedfile_as_target = min2seed , bitwise = options . bitwise , <EOL> confidence = confidence , tempdir = outdir , <EOL> logfile = minlog , maxtime = options . timeout , <EOL> preferx = options . prefer_x_target ) as minimize : <EOL> minimize . save_others = options . keep_other_crashes <EOL> minimize . target_size_guess = int ( options . initial_target_size ) <EOL> minimize . go ( ) <EOL> if options . stringmode : <EOL> logger . debug ( '<STR_LIT>' ) <EOL> length = len ( minimize . fuzzed ) <EOL> if options . prefer_x_target : <EOL> targetstring = list ( text . metasploit_pattern_orig ( length ) ) <EOL> filename_modifier = '<STR_LIT>' <EOL> else : <EOL> targetstring = list ( '<STR_LIT:x>' * length ) <EOL> filename_modifier = '<STR_LIT>' <EOL> fuzzed = list ( minimize . fuzzed ) <EOL> for idx in minimize . bytemap : <EOL> logger . debug ( '<STR_LIT>' , idx ) <EOL> targetstring [ idx ] = fuzzed [ idx ] <EOL> filename = '<STR_LIT>' . join ( ( crash . fuzzedfile . root , filename_modifier , crash . fuzzedfile . ext ) ) <EOL> metasploit_file = os . path . join ( crash . tempdir , filename ) <EOL> f = open ( metasploit_file , '<STR_LIT:wb>' ) <EOL> try : <EOL> f . writelines ( targetstring ) <EOL> finally : <EOL> f . close ( ) <EOL> crash . copy_files ( outdir ) <EOL> crash . clean_tmpdir ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
