From f793c17974eec076ce181efa3d167c8bac891908 Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Sun, 20 Oct 2019 18:48:24 +0200 Subject: [PATCH] fix: [galaxy] fixes issues when galaxies repo contain errors --- src/MISP_maltego/transforms/common/util.py | 38 ++++++++++++---------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/MISP_maltego/transforms/common/util.py b/src/MISP_maltego/transforms/common/util.py index 55627f1..0385520 100644 --- a/src/MISP_maltego/transforms/common/util.py +++ b/src/MISP_maltego/transforms/common/util.py @@ -463,23 +463,27 @@ def galaxy_update_local_copy(force=False): cluster_uuids = {} for galaxy_fname in galaxies_fnames: - fullPathClusters = os.path.join(local_path_clusters, galaxy_fname) - with open(fullPathClusters) as fp: - galaxy = json.load(fp) - with open(fullPathClusters.replace('clusters', 'galaxies')) as fg: - galaxy_main = json.load(fg) - for cluster in galaxy['values']: - if 'uuid' not in cluster: - continue - # skip deprecated galaxies/clusters - if galaxy_main['namespace'] == 'deprecated': - continue - # keep track of the cluster, but also enhance it to look like the cluster we receive when accessing the web. - cluster_uuids[cluster['uuid']] = cluster - cluster_uuids[cluster['uuid']]['type'] = galaxy['type'] - cluster_uuids[cluster['uuid']]['tag_name'] = 'misp-galaxy:{}="{}"'.format(galaxy['type'], cluster['value']) - if 'icon' in galaxy_main: - cluster_uuids[cluster['uuid']]['icon'] = galaxy_main['icon'] + try: + fullPathClusters = os.path.join(local_path_clusters, galaxy_fname) + with open(fullPathClusters) as fp: + galaxy = json.load(fp) + with open(fullPathClusters.replace('clusters', 'galaxies')) as fg: + galaxy_main = json.load(fg) + for cluster in galaxy['values']: + if 'uuid' not in cluster: + continue + # skip deprecated galaxies/clusters + if galaxy_main['namespace'] == 'deprecated': + continue + # keep track of the cluster, but also enhance it to look like the cluster we receive when accessing the web. + cluster_uuids[cluster['uuid']] = cluster + cluster_uuids[cluster['uuid']]['type'] = galaxy['type'] + cluster_uuids[cluster['uuid']]['tag_name'] = 'misp-galaxy:{}="{}"'.format(galaxy['type'], cluster['value']) + if 'icon' in galaxy_main: + cluster_uuids[cluster['uuid']]['icon'] = galaxy_main['icon'] + except Exception: + # we ignore incorrect galaxies + pass with open(local_path_uuid_mapping, 'w') as f: json.dump(cluster_uuids, f, sort_keys=True, indent=4)