Exemplo n.º 1
0
  def get_mutator_plugin(self):
    """Downloads and unpacks a usable mutator plugin for this job and fuzz
    target if one is available in GCS"""
    mutator_plugins = _get_mutator_plugins_from_bucket()
    if not mutator_plugins:
      # No plugins found or plugin url is not set.
      return None

    usable_mutator_plugins = [
        plugin_archive for plugin_archive in mutator_plugins
        if self._is_plugin_usable(plugin_archive)
    ]

    # Quit if no usable plugins are available.
    if not usable_mutator_plugins:
      return None

    plugin_archive_name = utils.random_element_from_list(usable_mutator_plugins)

    # Handle a failed download.
    plugin_archive_path = _download_mutator_plugin_archive(plugin_archive_name)
    if not plugin_archive_path:
      return None

    _unpack_mutator_plugin(plugin_archive_path)
    mutator_plugin_path = find_mutator_plugin()
    if mutator_plugin_path is None:
      logs.log_error('Could not find plugin in %s' % plugin_archive_path)

    return mutator_plugin_path
Exemplo n.º 2
0
def get_random_gestures(gesture_count):
    """Return list of random gesture command strings."""
    gesture_types = [
        'click --repeat TIMES,mbutton',
        'drag',
        'key,ctrl+minus',
        'key,ctrl+plus',
        'key,Function',
        'key,Letter',
        'key,Letters',
        'key,Modifier+Letter',
        'keydown,Letter',
        'keyup,Letter',
        'type,Chars',
        'type,Chars',
        'mousedown,mbutton',
        'mousemove --sync,x y',
        'mousemove_relative --sync,nx ny',
        'mouseup,mbutton',
    ]

    if not random.randint(0, 3):
        gesture_types.append('windowsize,P P')

    gestures = []
    for _ in range(gesture_count):
        random_gesture = utils.random_element_from_list(gesture_types)
        if random_gesture == 'drag':
            gestures.append('mousemove,%d %d' % (random.randint(
                0, SCREEN_WIDTH), random.randint(0, SCREEN_HEIGHT)))
            gestures.append('mousedown,1')
            gestures.append('mousemove_relative,0 1')
            gestures.append('mousemove_relative,0 -')
            gestures.append('mousemove,%d %d' % (random.randint(
                0, SCREEN_WIDTH), random.randint(0, SCREEN_HEIGHT)))
            gestures.append('mouseup,1')
            continue

        elif 'Function' in random_gesture:
            random_gesture = (random_gesture.replace(
                'Function', 'F%d' % random.randint(1, 12)))

        elif 'mbutton' in random_gesture:
            random_gesture = random_gesture.replace('TIMES',
                                                    str(random.randint(1, 3)))

            picked_button = 1 if random.randint(0, 4) else random.randint(2, 5)
            random_gesture = random_gesture.replace('mbutton',
                                                    str(picked_button))

        elif ',x y' in random_gesture:
            random_gesture = random_gesture.replace(
                ',x y', ',%d %d' % (random.randint(
                    0, SCREEN_WIDTH), random.randint(0, SCREEN_HEIGHT)))

        elif ',nx ny' in random_gesture:
            random_gesture = random_gesture.replace(
                ',nx ny', ',%d %d' %
                (random.randint(COORDINATE_DELTA_MIN, COORDINATE_DELTA_MAX),
                 random.randint(COORDINATE_DELTA_MIN, COORDINATE_DELTA_MAX)))

        elif ',P P' in random_gesture:
            random_gesture = random_gesture.replace(
                ',P P', ',%d%% %d%%' %
                (random.randint(10, 100), random.randint(10, 100)))

        elif 'Chars' in random_gesture:
            random_gesture = random_gesture.replace(
                'Chars', "'%s'" % get_text_to_type())

        else:
            if 'Modifier' in random_gesture:
                random_gesture = random_gesture.replace(
                    'Modifier',
                    utils.random_element_from_list([
                        'alt', 'ctrl', 'control', 'meta', 'super', 'shift',
                        'ctrl+shift'
                    ]))

            if 'Letters' in random_gesture:
                num_letters = random.randint(1, 10)
                letters = []
                for _ in range(num_letters):
                    letters.append(
                        utils.random_element_from_list([
                            'Escape', 'BackSpace', 'Delete', 'Tab', 'space',
                            'Down', 'Return', 'Up', 'Down', 'Left', 'Right',
                            chr(random.randint(48, 57)),
                            chr(random.randint(65, 90)),
                            chr(random.randint(97, 122))
                        ]))
                random_gesture = random_gesture.replace(
                    'Letters', ' '.join(letters))

            elif 'Letter' in random_gesture:
                random_gesture = random_gesture.replace(
                    'Letter',
                    utils.random_element_from_list([
                        'space',
                        chr(random.randint(48, 57)),
                        chr(random.randint(65, 90)),
                        chr(random.randint(97, 122))
                    ]))

                if 'ctrl+c' in random_gesture.lower():
                    continue

        gestures.append(random_gesture)

    return gestures
Exemplo n.º 3
0
def get_random_gestures(gesture_count):
    """Return list of random gesture command strings."""
    gestures_types = [
        'key,Letters', 'key,Letters', 'key,Letters', 'key,Letters', 'mouse,MA',
        'mousedrag,MB', 'mousemove,MC'
    ]

    gestures = []
    for _ in range(gesture_count):
        random_gesture = utils.random_element_from_list(gestures_types)
        if 'Letters' in random_gesture:
            num_letters = random.randint(1, 10)
            letters = []
            for _ in range(num_letters):
                if not random.randint(0, 7):
                    letters.append(
                        utils.random_element_from_list([
                            '{BACK}', '{BACKSPACE}', '{BKSP}', '{CAP}',
                            '{DEL}', '{DELETE}', '{DOWN}', '{DOWN}', '{END}',
                            '{ENTER}', '{ENTER}', '{ENTER}', 'A{ESC}', '{F1}',
                            '{F2}', '{F3}', 'A{F4}', '{F5}', '{F6}', '{F7}',
                            '{F8}', '{F9}', '{F10}', '{F11}', '{F12}',
                            '{HOME}', '{INSERT}', '{LEFT}', '{PGDN}', '{PGUP}',
                            '{RIGHT}', '{SPACE}', '{TAB}', '{TAB}', '{TAB}',
                            '{TAB}', '{UP}', '{UP}', '+', '^'
                        ]))
                else:
                    letters.append(
                        utils.random_element_from_list([
                            '{TAB}', '^=', '^-',
                            '{%s}' % chr(random.randint(32, 126))
                        ]))
            random_gesture = random_gesture.replace('Letters',
                                                    ''.join(letters))
            if ('^c' in random_gesture.lower()
                    or '^d' in random_gesture.lower()
                    or '^z' in random_gesture.lower()):
                continue

        if ',MA' in random_gesture:
            button = utils.random_element_from_list(
                ['left', 'right', 'middle'])
            coords = '(%d,%d)' % (random.randint(
                0, 1000), random.randint(0, 1000))
            double = utils.random_element_from_list(['True', 'False'])
            random_gesture = random_gesture.replace(
                'MA', '%s;%s;%s' % (button, coords, double))

        if ',MB' in random_gesture:
            button = utils.random_element_from_list(
                ['left', 'right', 'middle'])
            coords1 = '(%d,%d)' % (random.randint(
                0, 1000), random.randint(0, 1000))
            coords2 = '(%d,%d)' % (random.randint(
                0, 1000), random.randint(0, 1000))
            random_gesture = random_gesture.replace(
                'MB', '%s;%s;%s' % (button, coords1, coords2))

        if ',MC' in random_gesture:
            button = utils.random_element_from_list(
                ['left', 'right', 'middle'])
            coords = '(%d,%d)' % (random.randint(
                0, 1000), random.randint(0, 1000))
            random_gesture = random_gesture.replace('MC',
                                                    '%s;%s' % (button, coords))

        gestures.append(random_gesture)

    return gestures