Ejemplo n.º 1
0
def test_get_response_with_error_status_codes(monkeypatch):
    class TestResponse:
        status_code = 504

        def json(self):
            return {"description": "error 100"}

    monkeypatch.setattr(requests, "get", lambda v: TestResponse())
    monkeypatch.setattr(requests, "post", lambda v: v)
    monkeypatch.setattr(detectem.utils, "SETUP_SPLASH", False)

    with pytest.raises(SplashError):
        get_response("http://domain.tld", PluginCollection())
Ejemplo n.º 2
0
def test_get_response_with_error_status_codes(monkeypatch):
    class TestResponse():
        status_code = 504

        def json(self):
            return {'description': 'error 100'}

    monkeypatch.setattr(requests, 'get', lambda v: TestResponse())
    monkeypatch.setattr(requests, 'post', lambda v: v)
    monkeypatch.setattr(detectem.utils, 'SETUP_SPLASH', False)

    with pytest.raises(SplashError):
        get_response('http://domain.tld', PluginCollection())
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def test_get_response(monkeypatch):
    class TestResponse():
        status_code = 200

        def json(self):
            return {'har': {}, 'softwares': [], 'scripts': {}}

    monkeypatch.setattr(requests, 'get', lambda v: TestResponse())
    monkeypatch.setattr(requests, 'post', lambda v: v)
    monkeypatch.setattr(detectem.utils, 'SETUP_SPLASH', False)

    response = get_response('http://domain.tld', PluginCollection())
    assert response
    assert 'har' in response
    assert 'softwares' in response
Ejemplo n.º 5
0
def test_get_response(monkeypatch):
    class TestResponse:
        status_code = 200

        def json(self):
            return {"har": {}, "softwares": [], "scripts": {}}

    monkeypatch.setattr(requests, "get", lambda v: TestResponse())
    monkeypatch.setattr(requests, "post", lambda v: v)
    monkeypatch.setattr(detectem.utils, "SETUP_SPLASH", False)

    response = get_response("http://domain.tld", PluginCollection())
    assert response
    assert "har" in response
    assert "softwares" in response
Ejemplo n.º 6
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
Ejemplo n.º 7
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