From 618857e5ce419f3a41b922856f91cdb4b6eae437 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sun, 22 Nov 2015 08:16:09 +0100 Subject: [PATCH] Support triple tags JSON file without values --- tools/machinetag.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tools/machinetag.py b/tools/machinetag.py index 0d3a029..15e4959 100755 --- a/tools/machinetag.py +++ b/tools/machinetag.py @@ -30,9 +30,9 @@ import json import os.path import argparse -taxonomies = ['admiralty-scale'] +taxonomies = ['admiralty-scale','tlp'] -argParser = argparse.ArgumentParser(description='Dump Machine Tags (Triple Tags) from MISP taxonomiesi') +argParser = argparse.ArgumentParser(description='Dump Machine Tags (Triple Tags) from MISP taxonomies') argParser.add_argument('-e', action='store_true', help='Including expanded tags') args = argParser.parse_args() @@ -52,10 +52,15 @@ for taxonomy in taxonomies: t = json.load(fp) namespace = t['namespace'] for predicate in t['predicates']: - for e in t['values']: - if e['predicate'] == predicate['value']: - expanded = predicate['expanded'] - for v in e['entry']: - print (machineTag(namespace=namespace, predicate=e['predicate'], value=v['value'])) - if args.e: - print ("--> " + machineTag(namespace=namespace, predicate=expanded, value=v['expanded'])) + if t['values'] is None: + print (machineTag(namespace=namespace, predicate=predicate['value'])) + if args.e: + print ("--> " + machineTag(namespace=namespace, predicate=predicate['expanded'])) + else: + for e in t['values']: + if e['predicate'] == predicate['value']: + expanded = predicate['expanded'] + for v in e['entry']: + print (machineTag(namespace=namespace, predicate=e['predicate'], value=v['value'])) + if args.e: + print ("--> " + machineTag(namespace=namespace, predicate=expanded, value=v['expanded']))