示例#1
0
文件: cli.py 项目: GTrunSec/detectem
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
示例#2
0
 def test_add_inline_scripts_to_har(self, scripts, n_entries):
     d = Detector({
         "har": [],
         "softwares": [],
         "scripts": scripts
     }, None, self.URL)
     assert len(d.har) == n_entries
示例#3
0
 def test_add_inline_scripts_to_har(self, scripts, n_entries):
     d = Detector({
         'har': [],
         'softwares': [],
         'scripts': scripts
     }, None, self.URL)
     assert len(d.har) == n_entries
示例#4
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
示例#5
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
示例#6
0
    def test_convert_inline_script_to_har_entry(self):
        script = "Inline script"

        d = Detector({
            "har": [],
            "softwares": [],
            "scripts": [script]
        }, None, self.URL)
        e = d.har[0]

        assert e["request"]["url"] == self.URL
        assert e["response"]["content"]["text"] == script
示例#7
0
    def test_convert_inline_script_to_har_entry(self):
        script = 'Inline script'

        d = Detector({
            'har': [],
            'softwares': [],
            'scripts': [script]
        }, None, self.URL)
        e = d.har[0]

        assert e['request']['url'] == self.URL
        assert e['response']['content']['text'] == script
示例#8
0
 def _create_detector(self, har, plugins):
     pc = PluginCollection()
     for p in plugins:
         pc.add(p)
     return Detector({"har": har, "softwares": []}, pc, self.URL)