def __init__(self, project): ProjectAgent.__init__(self, project, "aggressivity") # Options for state machine self.aggressivity_min = 0.01 self.aggressivity_max = 1.00 self.add_after = 5 # steps self.faster_after = 10 # steps self.slower_after = 5 # steps self.state_increment = { "+": 0.01, "++": 0.04, "-": -0.01, "--": -0.04, } # Variables of state machine self.state = "init" self.state_age = 1 self.min_score = None self.max_score = None # Attributes for graph.dat file self.graph_data = None self.last_session_index = None # Set default value of aggressivity self.setValue(self.aggressivity_min)
def __init__(self, process, exitcode_score=0.50, signal_score=1.0, default_score=0.0, timeout_score=1.0): self.process = weakref_ref(process) project = process.project() ProjectAgent.__init__(self, project, "watch:%s" % process.name) if RUNNING_LINUX: self.cpu = CpuProbe(project, "%s:cpu" % self.name) else: self.warning("CpuProbe is not available") self.cpu = None # Score if process exited normally self.default_score = default_score # Score if process exit code is not nul self.exitcode_score = exitcode_score # Score if process has been killed by signal self.signal_score = signal_score # Score if process timeout has been reached self.timeout_score = timeout_score
def __init__(self, project, arguments=None, stdout="file", stdin=None, timeout=10.0, name=None): if not name: name = "process:%s" % basename(arguments[0]) ProjectAgent.__init__(self, project, name) self.env = Environment(self) if arguments is None: arguments = [] self.cmdline = CommandLine(self, arguments) self.timeout = timeout self.max_memory = 100 * 1024 * 1024 self.stdout = stdout self.popen_args = { 'stderr': STDOUT, } if stdin is not None: if stdin == "null": self.popen_args['stdin'] = open('/dev/null', 'r') else: raise ValueError("Invalid stdin value: %r" % stdin)
def __init__(self, project, arguments=None, stdout="file", stdin=False, timeout=DEFAULT_TIMEOUT, name=None): if isinstance(arguments, (str, unicode)): arguments = splitCommand(arguments) config = project.config if not name: name = "process:%s" % basename(arguments[0]) ProjectAgent.__init__(self, project, name) self.env = Environment(self) if arguments is None: arguments = [] self.cmdline = CommandLine(self, arguments) self.timeout = timeout self.max_memory = config.process_max_memory self.max_user_process = config.process_max_user_process self.core_dump = config.process_core_dump self.stdout = stdout self.debugger = project.debugger self.use_x11 = False self.popen_args = { 'stderr': STDOUT, } if not RUNNING_WINDOWS: self.popen_args['close_fds'] = True self.stdin = stdin
def __init__(self, process, exitcode_score=DEFAULT_EXITCODE_SCORE, signal_score=DEFAULT_SIGNAL_SCORE, default_score=0.0, timeout_score=DEFAULT_TIMEOUT_SCORE): self.process = weakref_ref(process) project = process.project() ProjectAgent.__init__(self, project, "watch:%s" % process.name) if RUNNING_LINUX and project.config.use_cpu_probe: self.cpu = CpuProbe(project, "%s:cpu" % self.name) else: self.cpu = None # Score if process exited normally self.default_score = default_score # Score if process exit code is not nul self.exitcode_score = exitcode_score # Score if process has been killed by signal self.signal_score = signal_score # Score if process timeout has been reached self.timeout_score = timeout_score
def __init__(self, project): ProjectAgent.__init__(self, project, "syslog") self.logs = [] for filename in FILENAMES: agent = self.create(project, '/var/log/' + filename) if not agent: continue self.logs.append(agent)
def __init__(self, project, name): ProjectAgent.__init__(self, project, name) self.log_data_exchange = False self.backlog = 5 self.client_class = self.CLIENT_CLASS self.socket = None self.family = None self.clients = []
def __init__(self, session, name, project=None): if project: mta = project.mta() else: mta = session.mta() project = session.project() self.session = weakref_ref(session) ProjectAgent.__init__(self, project, name, mta=mta) self.activate()
def __init__(self, project, program): ProjectAgent.__init__(self, project, "unix") self.program = program self.process = CreateProcess(project, name=basename(program)) self.watch = WatchProcess(self.process) self.states = ("help", "stop") self.state = 0 self.help_arguments = ("--help", "-help", "-h") self.state_data = None
def __init__(self, project): # Create $PWD/run-0001 directory name Directory.__init__(self, getcwd()) self.directory = self.uniqueFilename('run', count=1, save=False) # Initialize the agent and create the directory ProjectAgent.__init__(self, project, "directory:%s" % basename(self.directory)) self.warning("Create directory: %s" % self.directory) self.mkdir()
def __init__(self, project, file_obj, name, start='zero'): if start not in VALID_POS: raise ValueError('start position (%r) have to be in %s' % (start, VALID_POS)) ProjectAgent.__init__(self, project, name) self.file_obj = file_obj self.ignore = [] self.start = start self.patterns = {} self.regexs = [] # Minimum number of lines: # eg. (10, -0.2) to add -20% to score if there is fewer than 10 lines self.min_nb_line = None self.max_nb_line = (100, 1.0) self.last_seed = None self.log_not_matching = False self.show_matching = False self.show_not_matching = project.application().options.debug self.read_size = 4096 self.cleanup_func = None self.max_process_time = 0.250 # second self.words = { # Notice and warning "too large": 0.10, "unknown": 0.10, "can't": 0.10, "could not": 0.10, "not allowed": 0.10, 'invalid': 0.10, 'not valid': 0.10, 'failed': 0.10, 'failure': 0.10, 'warning': 0.10, # Non fatal errors 'oops': 0.30, # Linux kernel Oops: "Oops: 0000" 'bug': 0.30, 'pointer': 0.30, 'error': 0.30, 'allocate': 0.40, 'memory': 0.40, 'permission': 0.40, 'overflow': 0.40, # Fatal errors 'fatal': 1.0, 'assert': 1.0, 'assertion': 1.0, 'critical': 1.0, 'exception': 1.0, 'panic': 1.0, 'glibc detected': 1.0, 'segfault': 1.0, 'segmentation fault': 1.0, }
def __init__(self, project): ProjectAgent.__init__(self, project, "syslog") self.syslog = FileWatch(project, open('/var/log/syslog'), 'syslog:syslog', start='end') self.messages = FileWatch(project, open('/var/log/messages'), 'syslog:messages', start='end')
def __init__(self, project): # Create $PWD/run-0001 directory name Directory.__init__(self, getcwd()) name = project.application().NAME self.directory = self.uniqueFilename(name, save=False) # Initialize the agent and create the directory ProjectAgent.__init__(self, project, "directory:%s" % basename(self.directory)) self.warning("Create the directory: %s" % self.directory) self.mkdir()
def __init__(self, project, options): self.parrot_root = options.parrot_root self.instruction_count = options.instructions self.ignore_blacklist = options.ignore_blacklist self.opfunc_gen = OpfuncGenerator() self.arg_gen = ArgGenerator(self.parrot_root, self.ignore_blacklist) self.opfunc_gen.populateOpfuncList(self.parrot_root, self.ignore_blacklist) ProjectAgent.__init__(self, project, "pir_source") WriteCode.__init__(self)
def __init__(self, project, sources, nb_file=1): ProjectAgent.__init__(self, project, "mangle") if isinstance(sources, (str, unicode)): self.source_filenames = (sources,) else: # Remove duplicates self.source_filenames = tuple(set(sources)) if 1 < len(self.source_filenames): self.error("Sources filenames: %s" % len(self.source_filenames)) self.max_size = None # 10*1024*1024 self.nb_file = nb_file
def __init__(self, project, sources, nb_file=1): ProjectAgent.__init__(self, project, "mangle") if isinstance(sources, (str, unicode)): self.source_filenames = (sources, ) else: # Remove duplicates self.source_filenames = tuple(set(sources)) if 1 < len(self.source_filenames): self.error("Sources filenames: %s" % len(self.source_filenames)) self.max_size = None # 10*1024*1024 self.nb_file = nb_file
def __init__(self, project, process_name): ProjectAgent.__init__(self, project, "attach_process:%s" % process_name) self.process_name = process_name self.death_score = 1.0 self.max_memory = 100 * 1024 * 1024 self.memory_score = 1.0 if RUNNING_LINUX: self.cpu = CpuProbe(project, "%s:cpu" % self.name) else: self.warning("CpuProbe is not available") self.cpu = None
def __init__(self, project): ProjectAgent.__init__(self, project, "gen printf") # --- printf options --- self.min_nb_arg = 1 self.max_nb_arg = 6 self.types = 'aAcCdeEfFgGimnopuxXsS%' self.format_attr = ('#', '0', '-', ' ', '+', "'", 'I', '') self.min_width = 0 self.max_width = 10 * 1000 * 1000 self.max_precision = 10 * 1000 * 1000 self.values = { 'str': quoteString('Hello'), 'wide str': quoteString(HELLO_UTF32), 'char': "'A'", 'wide char': "(wchar_t)322", # 'Å‚' 'double': "(double)3.14", 'short': "(short)7", 'pointer': "(void *)0xDEADBEEF", 'int': "(int)42", 'intmax': "(intmax_t)232", 'size_t': "(size_t)-1", 'long': "(long)1234567890", 'long long': "(long long)10101010", 'ptrdiff_t': "(ptrdiff_t)100", 'write': "&written", 'long double': '(long double)5.92', } int_modifiers = { 'hh': 'char', 'h': 'short', 'l': 'long', 'll': 'long long', 'q': 'long long', 'j': 'intmax', 'z': 'size_t', 't': 'ptrdiff_t', } self.modifiers = { 'int': dict(int_modifiers), 'char': dict(int_modifiers), 'wide char': dict(int_modifiers), 'pointer': dict(int_modifiers), 'str': { 'l': 'wide str' }, 'wide str': { 'l': 'wide str' }, 'double': { 'L': 'long double' }, }
def __init__(self, project): ProjectAgent.__init__(self, project, "dbg") self.debugger = None self.enabled = (HAS_PTRACE and project.config.use_debugger) self.fusil_processes = {} if self.enabled: self.error("Use python-ptrace debugger") self.debugger = PtraceDebugger() if project.config.debugger_trace_forks: try: self.debugger.traceFork() self.warning("Debugger trace process forks") except PtraceDebuggerError, err: self.error("Unable to trace forks: %s" % err)
def __init__(self, project): ProjectAgent.__init__(self, project, "php_source") self.generators = [ Base64Generator(10), LengthGenerator(), NullGenerator(), ReferenceGenerator(), VariableGenerator(), ] self.min_arguments = 0 self.max_arguments = 10 self.min_instr = 1 self.max_instr = 10 self.ignore_functions = set() self.functions = set(PHP_FUNCTIONS) self.indent = ' '
def __init__(self, project, too_fast=None, too_slow=None, too_fast_score=-1.0, too_slow_score=1.0): if too_fast is not None and too_slow is not None: if too_fast > too_slow: raise ValueError("too_fast > too_slow") else: if too_fast is None and too_slow is None: raise ValueError("TimeWatch requires too_fast or too_slow parameters") ProjectAgent.__init__(self, project, "time watch") self.too_fast = too_fast self.too_slow = too_slow self.too_fast_score = too_fast_score self.too_slow_score = too_slow_score self.time0 = None self.duration = None
def __init__(self, project, arguments=None, stdout="file", stdin=None, timeout=10.0, name=None): if not name: name = "process:%s" % basename(arguments[0]) ProjectAgent.__init__(self, project, name) self.env = Environment(self) if arguments is None: arguments = [] self.cmdline = CommandLine(self, arguments) self.timeout = timeout self.max_memory = 100*1024*1024 self.stdout = stdout self.popen_args = { 'stderr': STDOUT, } if stdin is not None: if stdin == "null": self.popen_args['stdin'] = open('/dev/null', 'r') else: raise ValueError("Invalid stdin value: %r" % stdin)
def __init__(self, application): ProjectAgent.__init__(self, self, "project", mta=application.mta()) self.application = weakref_ref(application) self.agents = AgentList() if RUNNING_LINUX: if application.options.fast: self.system_calm = SystemCalm(0.75, 0.2) elif not application.options.slow: self.system_calm = SystemCalm(0.50, 0.5) else: self.system_calm = SystemCalm(0.30, 3.0) else: self.warning("SystemCalm class is not available") self.system_calm = None # Configuration self.max_session = application.options.session self.success_score = 0.50 # minimum score for a successful session self.error_score = -0.50 # maximum score for a session failure self.max_success = application.options.success # Session self.session = None self.session_index = 0 self.session_timeout = None # in second # Statistics self.session_executed = 0 self.session_total_duration = 0 self.total_duration = None # Add Application agents, order is important: MTA have to be the first agent for agent in application.agents: self.registerAgent(agent) self.registerAgent(self) # Create aggressivity agent self.aggressivity = AggressivityAgent(self) # Initial aggresssivity value if application.options.aggressivity is not None: self.aggressivity.setValue(application.options.aggressivity / 100) self.error("Initial aggressivity: %s" % self.aggressivity)
def __init__(self, project, too_fast=None, too_slow=None, too_fast_score=-1.0, too_slow_score=1.0): if too_fast is not None and too_slow is not None: if too_fast > too_slow: raise ValueError("too_fast > too_slow") else: if too_fast is None and too_slow is None: raise ValueError( "TimeWatch requires too_fast or too_slow parameters") ProjectAgent.__init__(self, project, "time watch") self.too_fast = too_fast self.too_slow = too_slow self.too_fast_score = too_fast_score self.too_slow_score = too_slow_score self.time0 = None self.duration = None
def __init__(self, project, pid, name=None): if not name: name = "pid:%s" % pid ProjectAgent.__init__(self, project, name) if RUNNING_WINDOWS: raise NotImplementedError( "AttachProcessPID is not supported on Windows") self.death_score = 1.0 self.show_exit = True # needed by the debugger self.max_memory = 100*1024*1024 self.memory_score = 1.0 self.debugger = project.debugger self.dbg_process = None if HAS_PROC and project.config.use_cpu_probe: self.cpu = CpuProbe(project, "%s:cpu" % self.name) else: self.warning("CpuProbe is not available on your OS") self.cpu = None if pid: self.setPid(pid) else: self.pid = None
def __init__(self, project): ProjectAgent.__init__(self, project, "syscall") # Syscall parameters self.syscalls = xrange(0, 255+1) self.fixed_arguments = {}
def __init__(self, application): ProjectAgent.__init__(self, self, "project", mta=application.mta(), application=application) self.config = application.config options = application.options self.agents = AgentList() if RUNNING_LINUX: if options.fast: self.system_calm = None elif not options.slow: self.system_calm = SystemCalm( self.config.fusil_normal_calm_load, self.config.fusil_normal_calm_sleep) else: self.system_calm = SystemCalm( self.config.fusil_slow_calm_load, self.config.fusil_slow_calm_sleep) else: self.warning("SystemCalm class is not available") self.system_calm = None # Configuration self.max_session = options.sessions self.success_score = self.config.fusil_success_score self.error_score = self.config.fusil_error_score self.max_success = options.success # Session self.step = None self.nb_success = 0 self.session = None self.session_index = 0 self.session_timeout = None # in second # Statistics self.session_executed = 0 self.session_total_duration = 0 self.total_duration = None self._destroyed = False # Add Application agents, order is important: # MTA have to be the first agent for agent in application.agents: self.registerAgent(agent) self.registerAgent(self) # Create aggressivity agent self.aggressivity = AggressivityAgent(self) # Initial aggresssivity value if options.aggressivity is not None: self.aggressivity.setValue(options.aggressivity / 100) self.error("Initial aggressivity: %s" % self.aggressivity) # Create the debugger self.debugger = Debugger(self) # Create the working directory self.directory = ProjectDirectory(self) self.directory.activate() self.error("Use directory: %s" % self.directory.directory) # Initilize project logging self.initLog()
def __init__(self, project, name, max_load=0.75, max_duration=3.0, max_score=1.0): ProjectAgent.__init__(self, project, name) self.max_load = max_load self.max_duration = max_duration self.max_score = max_score
def unregister(self, destroy=True): ProjectAgent.unregister(self, destroy) self.session().unregisterAgent(self, destroy)
def __init__(self, project): ProjectAgent.__init__(self, project, "firefox_window") self.display = getDisplay() self.root_window = self.display.screen().root self.F5_keycode = self.display.keysym_to_keycode(XK_F5) self.window = None
def __init__(self, process, arguments): ProjectAgent.__init__(self, process.project(), "%s:cmdline" % process.name) self.arguments = arguments
def __init__(self, process): ProjectAgent.__init__(self, process.project(), "%s:env" % process.name) self.copies = [] self.variables = [] if RUNNING_WINDOWS: self.copies.append('SYSTEMROOT')
def __init__(self, project, file_obj, name, start=None): if not start: start = 'zero' if start not in VALID_POS: raise ValueError('start position (%r) have to be in %s' % (start, VALID_POS)) ProjectAgent.__init__(self, project, name) self.file_obj = file_obj self.ignore = [] self.start = start self.regexs = [] self.compiled_patterns = None self._need_compile = True # Minimum number of lines: # eg. (10, -0.2) to add -20% to score if there is fewer than 10 lines self.min_nb_line = None self.max_nb_line = (100, 1.0) self.last_seed = None self.log_not_matching = False self.show_matching = False self.show_not_matching = self.application().options.debug self.read_size = 4096 self.cleanup_func = None self.max_process_time = 0.250 # second # FIXME: write methods instead of direct access to self.words # to be able to update self._need_compile self.words = { # Notice and warning u"too large": 0.10, u"unknown": 0.10, u"can't": 0.10, u"could not": 0.10, u"not allowed": 0.10, u'invalid': 0.10, u'not valid': 0.10, u'failed': 0.10, u'failure': 0.10, u'warning': 0.10, # Non fatal errors u'oops': 0.30, # Linux kernel Oops: "Oops: 0000" u'bug': 0.30, u'pointer': 0.30, u'error': 0.30, u'allocate': 0.40, u'memory': 0.40, u'permission': 0.40, u'overflow': 0.40, # Fatal errors u'fatal': 1.0, u'assert': 1.0, u'assertion': 1.0, u'critical': 1.0, u'exception': 1.0, u'panic': 1.0, u'glibc detected': 1.0, u'segfault': 1.0, u'segmentation fault': 1.0, }
def __init__(self, project, name): ProjectAgent.__init__(self, project, name) self.smart_string_generator = BytesGenerator(0, 10, LETTERS | DECIMAL_DIGITS | set(' ')) self.string_generator = BytesGenerator(0, 40, LETTERS | DECIMAL_DIGITS | PUNCTUATION) self.random_string_generator = BytesGenerator(0, 200) self.character_generator = BytesGenerator(1, 1) self.digit_generator = BytesGenerator(1, 30, DECIMAL_DIGITS) self.integer_generator = IntegerGenerator(11) self.printf_set = list(LETTERS | set('%')) self.long_string = LengthGenerator(10000) self.functions = list(set(( # Tests 'COALESCE', 'GREATEST', 'ISNULL', 'INTERVAL', 'LEAST', 'IF', 'IFNULL', 'NULLIF', 'STRCMP', # Math 'ABS', 'ACOS', 'ASIN', 'ATAN', 'ATAN2', 'CEILING', 'CEIL', 'COS', 'COT', 'CRC32', 'DEGREES', 'EXP', 'FLOOR', 'LN', 'LOG', 'LOG2', 'LOG10', 'MOD', 'PI', 'POW', 'POWER', 'RADIANS', 'RAND', 'ROUND', 'SIGN', 'SQRT', 'TAN', 'TRUNCATE', # String 'ASCII', 'BIN', 'BIT_LENGTH', 'CHAR', 'CHAR_LENGTH', 'COMPRESS', 'CONCAT', 'CONCAT_WS', 'CONV', 'ELT', 'EXPORT_SET', 'FIELD', 'FIND_IN_SET', 'HEX', 'INSERT', 'INSTR', 'LCASE', 'LEFT', 'LENGTH', 'LOAD_FILE', 'LOCATE', 'LOWER', 'LPAD', 'LTRIM', 'MAKE_SET', 'MID', 'OCTET_LENGTH', 'ORD', 'QUOTE', 'REPEAT', 'REPLACE', 'REVERSE', 'RIGHT', 'RPAD', 'RTRIM', 'SOUNDEX', 'SPACE', 'SUBSTRING', 'SUBSTRING_INDEX', 'TRIM', 'UCASE', 'UNCOMPRESS', 'UNCOMPRESSED_LENGTH', 'UNHEX', 'UPPER', # Date 'ADDDATE', 'ADDTIME', 'CURDATE', 'CURRENT_DATE', 'CURTIME', 'CURRENT_TIME', 'CURRENT_TIMESTAMP', 'DATE', 'DATEDIFF', 'DATE_FORMAT', 'DAY', 'DAYNAME', 'DAYOFMONTH', 'DAYOFWEEK', 'DAYOFYEAR', 'EXTRACT', 'FROM_DAYS', 'FROM_UNIXTIME', 'GET_FORMAT', 'HOUR', 'LAST_DAY', 'LOCALTIME', 'LOCALTIMESTAMP', 'MAKEDATE', 'MAKETIME', 'MICROSECOND', 'MINUTE', 'MONTH', 'MONTHNAME', 'NOW', 'PERIOD_ADD', 'PERIOD_DIFF', 'QUARTER', 'SECOND', 'SEC_TO_TIME', 'STR_TO_DATE', 'SUBDATE', 'SUBTIME', 'SYSDATE', 'TIME', 'TIMEDIFF', 'TIMESTAMP', 'TIMESTAMPADD', 'TIMESTAMPDIFF', 'TIME_FORMAT', 'TIME_TO_SEC', 'TO_DAYS', 'UNIX_TIMESTAMP', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'WEEK', 'WEEKDAY', 'WEEKOFYEAR', 'YEAR', 'YEARWEEK', # Encryption 'AES_DECRYPT', 'AES_ENCRYPT', 'DECODE', 'ENCODE', 'DES_DECRYPT', 'DES_ENCRYPT', 'ENCRYPT', 'MD5', 'OLD_PASSWORD', 'PASSWORD', 'SHA', 'SHA1', # Information 'BENCHMARK', 'CHARSET', 'COERCIBILITY', 'COLLATION', 'CONNECTION_ID', 'CURRENT_USER', 'DATABASE', 'FOUND_ROWS', 'LAST_INSERT_ID', 'SESSION_USER', 'SYSTEM_USER', 'USER', 'VERSION', # Autres 'BIT_COUNT', 'FORMAT', 'GET_LOCK', 'INET_ATON', 'INET_NTOA', 'IS_FREE_LOCK', 'IS_USED_LOCK', 'MASTER_POS_WAIT', 'RELEASE_LOCK', 'UUID', ))) self.min_nb_arg = 0 self.max_nb_arg = 4 self.min_nb_instr = 1 self.max_nb_instr = 3 self.booleans = ('true', 'false') self.create_value = ( self.createCharacter, self.createString, self.createSmartString, self.createRandomString, self.createInteger, self.createFloat, self.createNull, self.createBoolean, self.createPrintf, # self.createLength, )
def __init__(self, project, module_name): ProjectAgent.__init__(self, project, "python_source") if module_name != "ALL": self.modules = [module_name] else: self.modules = list(MODULES)
def __init__(self, project): ProjectAgent.__init__(self, project, "proc") self.generator = BytesGenerator(1, 256)
def __init__(self, project): ProjectAgent.__init__(self, project, "terminal")
def register(self): ProjectAgent.register(self) self.session().registerAgent(self)
def __init__(self, project, name): ProjectAgent.__init__(self, project, name) self.log_data_exchange = False