How to use the ivre.utils.encode_b64 function in ivre

To help you get started, we’ve selected a few ivre examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cea-sec / ivre / ivre / web / utils.py View on Github external
def get_anonymized_user():
    """Return the HMAC value of the current user authenticated with
    the HMAC secret.

    """
    return utils.encode_b64(hmac.new(config.WEB_SECRET,
                                     msg=get_user().encode()).digest()[:9])
github cea-sec / ivre / ivre / geoiputils.py View on Github external
lambda line: line[2] == country_code and
        line[4] == utils.encode_b64(
            (city or "").encode('utf-8')
        ).decode('utf-8'),
        **kargs
github cea-sec / ivre / ivre / view.py View on Github external
def _extract_passive_SSH_SERVER_HOSTKEY(rec):
    """Handle SSH host keys."""
    # TODO: should (probably) be merged, sorted by date/time, keep one
    # entry per key type.
    #
    # (MAYBE) we should add a "lastseen" tag to every intel in view.
    value = utils.encode_b64(
        utils.nmap_decode_data(rec['value'])
    ).decode()
    fingerprint = rec['infos']['md5']
    key = {'type': rec['infos']['algo'],
           'key': value,
           'fingerprint': fingerprint}
    if 'bits' in rec['infos']:  # FIXME
        key['bits'] = rec['infos']['bits']
    fingerprint = utils.decode_hex(fingerprint)
    script = {
        'id': 'ssh-hostkey', 'ssh-hostkey': [key],
        'output': '\n  %s %s (%s)\n%s %s' % (
            key.get('bits', '-'),  # FIXME
            ':'.join('%02x' % (
                ord(i) if isinstance(i, (bytes, str)) else i
            ) for i in fingerprint),
github cea-sec / ivre / ivre / db / tiny.py View on Github external
def to_binary(data):
        return utils.encode_b64(data).decode()
github cea-sec / ivre / ivre / activecli.py View on Github external
try:
                del h[fld]
            except KeyError:
                pass
        for port in h.get('ports', []):
            if no_screenshots:
                for fname in ['screenshot', 'screendata']:
                    if fname in port:
                        del port[fname]
            elif 'screendata' in port:
                port['screendata'] = utils.encode_b64(
                    dbase.from_binary(port['screendata'])
                )
            for script in port.get('scripts', []):
                if 'masscan' in script and 'raw' in script['masscan']:
                    script['masscan']['raw'] = utils.encode_b64(
                        dbase.from_binary(
                            script['masscan']['raw']
                        )
                    )
        print(json.dumps(h, indent=indent,
                         default=dbase.serialize))
github cea-sec / ivre / ivre / xmlnmap.py View on Github external
value = ssh2_enum[key]
                        ssh2_enum_out.append('  %s (%d)' % (key, len(value)))
                        ssh2_enum_out.extend('      %s' % v for v in value)
                self._curport.setdefault('scripts', []).append({
                    'id': 'ssh2-enum-algos',
                    'output': '\n'.join(ssh2_enum_out),
                    'ssh2-enum-algos': ssh2_enum,
                })
                continue
            if msgtype == 31:
                host_key_length = struct.unpack('>I', msg[:4])[0]
                host_key_length_data = msg[4:4 + host_key_length]
                info = utils.parse_ssh_key(host_key_length_data)
                # TODO this might be somehow factorized with
                # view.py:_extract_passive_SSH_SERVER_HOSTKEY()
                value = utils.encode_b64(host_key_length_data).decode()
                ssh_hostkey = {'type': info['algo'],
                               'key': value}
                if 'bits' in info:
                    ssh_hostkey['bits'] = info['bits']
                ssh_hostkey['fingerprint'] = info['md5']
                fingerprint = utils.decode_hex(info['md5'])
                self._curport.setdefault('scripts', []).append({
                    'id': 'ssh-hostkey',
                    'ssh-hostkey': [ssh_hostkey],
                    'output': '\n  %s %s (%s)\n%s %s' % (
                        ssh_hostkey.get('bits', '-'),
                        ':'.join('%02x' % (
                            ord(i) if isinstance(i, (bytes, str)) else i
                        ) for i in fingerprint),
                        {'ecdsa-sha2-nistp256': 'ECDSA'}.get(
                            ssh_hostkey['type'],
github cea-sec / ivre / ivre / xmlnmap.py View on Github external
def create_ssl_cert(data, b64encoded=True):
    """Produces an output similar to Nmap script ssl-cert from Masscan
X509 "service" tag.

    """
    if b64encoded:
        cert = utils.decode_b64(data)
    else:
        cert = data
        data = utils.encode_b64(cert)
    info = utils.get_cert_info(cert)
    newout = []
    for key, name in [('subject_text', 'Subject'),
                      ('issuer_text', 'Issuer')]:
        try:
            newout.append('%s: %s' % (name, info[key]))
        except KeyError:
            pass
    for key, name in [('md5', 'MD5:'), ('sha1', 'SHA-1:')]:
        try:
            newout.append('%-7s%s\n' % (name, info[key]))
        except KeyError:
            pass
    try:
        pubkeyalgo = info.pop('pubkeyalgo')
    except KeyError:
github cea-sec / ivre / ivre / geoiputils.py View on Github external
def locids_by_city(country_code, city_name):
    fdesc = csv.DictReader(codecs.open(os.path.join(
        config.GEOIP_PATH,
        'GeoLite2-City-Locations-%s.csv' % config.GEOIP_LANG,
    ), encoding='utf-8'))
    city_name = utils.encode_b64((city_name or
                                  "").encode('utf-8')).decode('utf-8')
    for line in fdesc:
        if (line['country_iso_code'], line['city_name']) == \
           (country_code, city_name):
            yield int(line['geoname_id'])