From 65eb66a739699ff4c88accc8592099b822e88949 Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Fri, 12 Oct 2018 10:41:19 +0200 Subject: [PATCH] fix: automatically fix missing uuids --- clusters/botnet.json | 1 + clusters/malpedia.json | 4 ++-- jq_all_the_things.sh | 1 + tools/add_missing_uuid.py | 9 ++++++--- 4 files changed, 10 insertions(+), 5 deletions(-) mode change 100644 => 100755 tools/add_missing_uuid.py diff --git a/clusters/botnet.json b/clusters/botnet.json index 21ce037..e85ebad 100644 --- a/clusters/botnet.json +++ b/clusters/botnet.json @@ -899,6 +899,7 @@ "https://www.bleepingcomputer.com/news/security/new-iot-botnet-torii-uses-six-methods-for-persistence-has-no-clear-purpose/" ] }, + "uuid": "92f38212-94e2-4d70-9b5e-e977eb1e7b79", "value": "Torii" }, { diff --git a/clusters/malpedia.json b/clusters/malpedia.json index 4786150..37cb020 100644 --- a/clusters/malpedia.json +++ b/clusters/malpedia.json @@ -13413,7 +13413,7 @@ "synonyms": [], "type": [] }, - "uuid": "", + "uuid": "39f609e3-e6fe-4c2c-af0e-b28bc81b2ecf", "value": "" }, { @@ -14429,7 +14429,7 @@ "synonyms": [], "type": [] }, - "uuid": "", + "uuid": "4db80a62-d318-48e7-b70b-759924ff515e", "value": "" }, { diff --git a/jq_all_the_things.sh b/jq_all_the_things.sh index 6fc3099..229c96a 100755 --- a/jq_all_the_things.sh +++ b/jq_all_the_things.sh @@ -17,6 +17,7 @@ set -x for dir in clusters/*.json do + python3 tools/add_missing_uuid.py -f ${dir} # Beautify it cat ${dir} | jq --sort-keys . | sponge ${dir} done diff --git a/tools/add_missing_uuid.py b/tools/add_missing_uuid.py old mode 100644 new mode 100755 index 229a9b3..1768bf7 --- a/tools/add_missing_uuid.py +++ b/tools/add_missing_uuid.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- import json @@ -9,13 +9,16 @@ parser = argparse.ArgumentParser(description='Add missing uuids in clusters') parser.add_argument("-f", "--filename", required=True, help="name of the cluster") args = parser.parse_args() +if 'mitre-' in args.filename: + exit() + with open(args.filename) as json_file: data = json.load(json_file) json_file.close() for value in data['values']: - if 'uuid' not in value: + if not value.get('uuid'): value['uuid'] = str(uuid.uuid4()) with open(args.filename, 'w') as json_file: - json.dump(data, json_file, indent=4) + json.dump(data, json_file, indent=2, sort_keys=True, ensure_ascii=False)