Пример #1
0
    def pytest_generate_tests(self, metafunc):
        fname = metafunc.function.__name__
        cases = []
        all_plugins = load_plugins()

        for plugin_package in PLUGIN_PACKAGES:
            package = plugin_package.split(".")[0]
            package_dir = find_spec(package).submodule_search_locations[0]
            test_dir = os.path.join(package_dir, os.pardir, "tests")

            plugin = metafunc.config.getoption("plugin", None)
            data = load_from_yaml(test_dir, "plugins/fixtures/")

            only_dom_matches = fname == "test_dom_matches"

            # Entry is the full plugin test file evaluated as a dictionary
            for entry in data:
                # Each yaml_dict is an entry in matches
                for yaml_dict in entry["matches"]:
                    # Filter valid matchers if dom matchers are expected
                    if (only_dom_matches and "dom" not in yaml_dict) or (
                            not only_dom_matches and "dom" in yaml_dict):
                        continue

                    if plugin:
                        # Case if plugin was provided by developer
                        if plugin == entry["plugin"]:
                            p = all_plugins.get(entry["plugin"])
                            cases.append([p, yaml_dict])
                    else:
                        p = all_plugins.get(entry["plugin"])
                        cases.append([p, yaml_dict])

        metafunc.parametrize("plugin,yaml_dict", cases)
Пример #2
0
def get_detection_results(url, timeout, metadata=False, save_har=False):
    """ Return results from detector.

    This function prepares the environment loading the plugins,
    getting the response and passing it to the detector.

    In case of errors, it raises exceptions to be handled externally.

    """
    plugins = load_plugins()
    if not plugins:
        raise NoPluginsError("No plugins found")

    logger.debug("[+] Starting detection with %(n)d plugins",
                 {"n": len(plugins)})

    response = get_response(url, plugins, timeout)

    # Save HAR
    if save_har:
        fd, path = tempfile.mkstemp(suffix=".har")
        logger.info(f"Saving HAR file to {path}")

        with open(fd, "w") as f:
            json.dump(response["har"], f)

    det = Detector(response, plugins, url)
    softwares = det.get_results(metadata=metadata)

    output = {"url": url, "softwares": softwares}

    return output
Пример #3
0
def get_detection_results(url, format, metadata):
    plugins = load_plugins()
    logger.debug('[+] Starting detection with %(n)d plugins', {'n': len(plugins)})

    try:
        response = get_response(url, plugins)
    except SplashError as e:
        error_dict = {'error': 'Splash error: {}'.format(e)}
        print_error_message(error_dict, format=format)
        sys.exit(0)

    det = Detector(response, plugins, url)
    results = det.get_results(metadata=metadata)

    if format == JSON_OUTPUT:
        return json.dumps(results)
    else:
        return results
Пример #4
0
def get_plugins(metadata):
    """ Return the registered plugins.

    Load and return all registered plugins.
    """
    plugins = load_plugins()
    if not plugins:
        raise NoPluginsError('No plugins found')

    results = []
    for p in sorted(plugins.get_all(), key=attrgetter('name')):
        if metadata:
            data = {'name': p.name, 'homepage': p.homepage}
            hints = getattr(p, 'hints', [])
            if hints:
                data['hints'] = hints
            results.append(data)
        else:
            results.append(p.name)
    return results
Пример #5
0
def get_plugins(metadata):
    """ Return the registered plugins.

    Load and return all registered plugins.
    """
    plugins = load_plugins()
    if not plugins:
        raise NoPluginsError("No plugins found")

    results = []
    for p in sorted(plugins.get_all(), key=attrgetter("name")):
        if metadata:
            data = {"name": p.name, "homepage": p.homepage}
            hints = getattr(p, "hints", [])
            if hints:
                data["hints"] = hints
            results.append(data)
        else:
            results.append(p.name)
    return results
Пример #6
0
def get_detection_results(url, timeout, metadata):
    """ Return results from detector.

    This function prepares the environment loading the plugins,
    getting the response and passing it to the detector.

    In case of errors, it raises exceptions to be handled externally.

    """
    plugins = load_plugins()
    if not plugins:
        raise NoPluginsError('No plugins found')

    logger.debug('[+] Starting detection with %(n)d plugins', {'n': len(plugins)})

    response = get_response(url, plugins, timeout)
    det = Detector(response, plugins, url)
    results = det.get_results(metadata=metadata)

    return results
Пример #7
0
    def pytest_generate_tests(self, metafunc):
        fname = metafunc.function.__name__
        cases = []
        all_plugins = load_plugins()

        for plugin_package in PLUGIN_PACKAGES:
            package = plugin_package.split('.')[0]
            package_dir = find_spec(package).submodule_search_locations[0]
            test_dir = os.path.join(package_dir, os.pardir, 'tests')

            plugin = pytest.config.getoption('plugin', None)
            if plugin:
                plugin = plugin.replace('.', '')
                try:
                    fixture_file = 'plugins/fixtures/{}.yml'.format(plugin)
                    data = load_from_yaml(test_dir, fixture_file)
                except FileNotFoundError:
                    continue
            else:
                data = load_from_yaml(test_dir, 'plugins/fixtures/')

            if fname == 'test_version_matches':
                entry_name = 'matches'
            elif fname == 'test_js_matches':
                entry_name = 'js_matches'
            elif fname == 'test_modular_matches':
                entry_name = 'modular_matches'
            elif fname == 'test_indicators':
                entry_name = 'indicators'

            for entry in data:
                for yaml_dict in entry.get(entry_name, []):
                    plugin = all_plugins.get(entry['plugin'])
                    cases.append([plugin, yaml_dict])

        metafunc.parametrize('plugin,yaml_dict', cases)
Пример #8
0
 def plugins(self):
     return load_plugins()
Пример #9
0
 def plugin_list(self):
     return load_plugins()