Exemple #1
0
def network_info(ip):
    global _failure, _cache

    # first, check the cache
    if _cache.get(ip) is not None:
        return _cache[ip]

    # now, make sure we haven't turn this off due to errors
    if _failure:
        return "Network Information disabled due to prior failure"

    try:
        info, code = network.http_json("https://api.iptoasn.com/v1/as/ip/%s" % ip)

        if code == 200:
            ret = "%s - %s" % (info["as_country_code"], info["as_description"])
            _cache[ip] = ret

            return ret
        else:
            _failure = True

            return "IP To ASN Service returned code: %s" % code
    except (ValueError, KeyError) as error:
        output.debug_exception()
        _failure = True
        return "IP To ASN Service error: %s" % str(error)
Exemple #2
0
def _analyze(domain: str, new=False) -> Dict[str, Any]:
    new_path = "host={target}&publish=off&startNew=on&all=done&ignoreMismatch=on".format(
        target=domain
    )
    status_path = "host={target}&publish=off&all=done&ignoreMismatch=on".format(
        target=domain
    )

    if new:
        path = new_path
    else:
        path = status_path

    try:
        body, code = network.http_json(API_SERVER + "/api/v3/analyze?" + path)
    except Exception:
        output.debug_exception()
        raise

    # check for error messages
    if body.get("errors") is not None:
        raise ValueError(
            "SSL Labs returned the following error(s): {errors}".format(
                errors=str(body["errors"])
            )
        )

    # next up, check to see what error code we have
    if code != 200:
        # if we got anything but 200, it's a problem
        raise ValueError("SSL Labs returned error code: {code}".format(code=code))

    return body
Exemple #3
0
def _get_version_info() -> str:
    try:
        data, code = network.http_json("https://pypi.org/pypi/yawast/json")
    except Exception:
        output.debug_exception()

        return "Supported Version: (Unable to get version information)"

    if code != 200:
        ret = "Supported Version: (PyPi returned an error code while fetching current version)"
    else:
        if "info" in data and "version" in data["info"]:
            ver = cast(version.Version, version.parse(get_version()))
            curr_version = cast(version.Version,
                                version.parse(data["info"]["version"]))

            ret = f"Supported Version: {curr_version} - "

            if ver == curr_version:
                ret += "You are on the latest version."
            elif ver > curr_version or "dev" in get_version():
                ret += "You are on a pre-release version. Take care."
            else:
                ret += "Please update to the current version."
        else:
            ret = "Supported Version: (PyPi returned invalid data while fetching current version)"

    return ret
Exemple #4
0
def _get_version_data() -> None:
    global _versions
    data: Union[Dict[str, Dict[str, Dict[str, str]]], None] = None
    data_url = "https://raw.githubusercontent.com/adamcaudill/current_versions/master/current_versions.json"

    try:
        data, _ = network.http_json(data_url)
    except Exception as error:
        output.debug(f"Failed to get version data: {error}")
        output.debug_exception()

    if data is not None and "software" in data:
        _versions = data["software"]
    else:
        _versions = None
Exemple #5
0
def _get_ct_log_data():
    ct_log_info: Dict[str, str] = {}

    data, _ = network.http_json(
        "https://www.gstatic.com/ct/log_list/all_logs_list.json")

    for log in data["logs"]:
        digest = hashes.Hash(hashes.SHA256(), backend=default_backend())
        digest.update(base64.b64decode(log["key"]))
        final = digest.finalize()
        value = bytes.hex(final)

        ct_log_info[value] = log["description"]

    return ct_log_info
Exemple #6
0
def get_info_message() -> List[str]:
    path = "/api/v3/info"
    messages: List[str] = []

    try:
        body, code = network.http_json(API_SERVER + path)

        if len(body["messages"]) > 0:
            for msg in body["messages"]:
                messages.append(msg)
    except Exception:
        output.debug_exception()
        raise

    return messages
Exemple #7
0
def check_hsts_preload(url: str) -> List[dict]:
    hsts_service = "https://hstspreload.com/api/v1/status/"
    results: List[dict] = []

    domain = utils.get_domain(url)

    if not checkers.is_ip_address(domain):
        while domain.count(".") > 0:
            # get the HSTS preload status for the domain
            res, _ = network.http_json(f"{hsts_service}{domain}")
            results.append(res)

            domain = domain.split(".", 1)[-1]
            if PublicSuffixList().is_public(domain):
                break

    return results