Exemple #1
0
def _getinfos_ssh_hostkey(spec):
    """Parse SSH host keys."""
    infos = {}
    data = utils.nmap_decode_data(spec['value'])
    for hashtype in ['md5', 'sha1', 'sha256']:
        infos[hashtype] = hashlib.new(hashtype, data).hexdigest()
    data = utils.parse_ssh_key(data)
    keytype = infos["algo"] = next(data).decode()
    if keytype == "ssh-rsa":
        try:
            infos["exponent"], infos["modulus"] = (long(
                utils.encode_hex(elt), 16) for elt in data)
        except Exception:
            utils.LOGGER.info("Cannot parse SSH host key for record %r",
                              spec,
                              exc_info=True)
        else:
            infos["bits"] = math.ceil(math.log(infos["modulus"], 2))
            # convert integer to strings to prevent overflow errors
            # (e.g., "MongoDB can only handle up to 8-byte ints")
            for val in ["exponent", "modulus"]:
                infos[val] = str(infos[val])
    elif keytype == 'ecdsa-sha2-nistp256':
        infos['bits'] = 256
    elif keytype == 'ssh-ed25519':
        infos['bits'] = len(next(data)) * 8
    return {'infos': infos}
Exemple #2
0
 def data2key(data):
     data = utils.parse_ssh_key(data)
     _, exp, mod = (
         next(data),  # noqa: F841 (_)
         long(utils.encode_hex(next(data)), 16),
         long(utils.encode_hex(next(data)), 16))
     return RSA.construct((mod, exp))
Exemple #3
0
def _getinfos_ssh_hostkey(spec):
    """Parse SSH host keys."""
    infos = {}
    data = utils.nmap_decode_data(spec.get('fullvalue', spec['value']))
    infos["md5hash"] = hashlib.md5(data).hexdigest()
    infos["sha1hash"] = hashlib.sha1(data).hexdigest()
    infos["sha256hash"] = hashlib.sha256(data).hexdigest()
    data = utils.parse_ssh_key(data)
    keytype = infos["algo"] = next(data).decode()
    if keytype == "ssh-rsa":
        try:
            infos["exponent"], infos["modulus"] = (long(
                utils.encode_hex(elt), 16) for elt in data)
        except Exception:
            utils.LOGGER.info("Cannot parse SSH host key for record %r",
                              spec,
                              exc_info=True)
        else:
            infos["bits"] = math.ceil(math.log(infos["modulus"], 2))
            # convert integer to strings to prevent overflow errors
            # (e.g., "MongoDB can only handle up to 8-byte ints")
            for val in ["exponent", "modulus"]:
                infos[val] = str(infos[val])
    res = {'infos': infos}
    _fix_infos_size(res)
    return res
Exemple #4
0
def _getinfos_ssh_hostkey(spec):
    """Parse SSH host keys."""
    infos = {}
    data = utils.nmap_decode_data(spec['value'])
    for hashtype in ['md5', 'sha1', 'sha256']:
        infos[hashtype] = hashlib.new(hashtype, data).hexdigest()
    data = utils.parse_ssh_key(data)
    keytype = infos["algo"] = next(data).decode()
    if keytype == "ssh-rsa":
        try:
            infos["exponent"], infos["modulus"] = (
                long(utils.encode_hex(elt), 16) for elt in data
            )
        except Exception:
            utils.LOGGER.info("Cannot parse SSH host key for record %r", spec,
                              exc_info=True)
        else:
            infos["bits"] = math.ceil(math.log(infos["modulus"], 2))
            # convert integer to strings to prevent overflow errors
            # (e.g., "MongoDB can only handle up to 8-byte ints")
            for val in ["exponent", "modulus"]:
                infos[val] = str(infos[val])
    elif keytype == 'ecdsa-sha2-nistp256':
        infos['bits'] = 256
    elif keytype == 'ssh-ed25519':
        infos['bits'] = len(next(data)) * 8
    return {'infos': infos}
Exemple #5
0
def _getinfos_ssh_hostkey(spec):
    """Parse SSH host keys."""
    infos = {}
    data = utils.nmap_decode_data(spec['value'])
    for hashtype in ['md5', 'sha1', 'sha256']:
        infos[hashtype] = hashlib.new(hashtype, data).hexdigest()
    info = utils.parse_ssh_key(data)
    return {'infos': info}
Exemple #6
0
def _getinfos_ssh_hostkey(spec):
    """Parse SSH host keys."""
    infos = {}
    data = utils.nmap_decode_data(spec["value"])
    for hashtype in ["md5", "sha1", "sha256"]:
        infos[hashtype] = hashlib.new(hashtype, data).hexdigest()
    info = utils.parse_ssh_key(data)
    return {"infos": info}
Exemple #7
0
 def data2key(data):
     data = utils.parse_ssh_key(data)
     _, exp, mod = (next(data),  # noqa: F841 (_)
                    long(utils.encode_hex(next(data)), 16),
                    long(utils.encode_hex(next(data)), 16))
     return RSA.construct((mod, exp))