Merge branch 'master' of github.com:MISP/misp-taxonomies
commit
7f2c310d37
|
@ -50,7 +50,7 @@ for element in elements:
|
|||
file_out = '../../misp-galaxy/machinetag.json'
|
||||
with open(file_out, 'w') as f:
|
||||
f.write(json.dumps(taxonomy, sort_keys=True, indent=4, separators=(',', ': ')))
|
||||
print("JSON saved to "+ file_out)
|
||||
print("JSON saved to " + file_out)
|
||||
|
||||
|
||||
# t = Taxonomy(taxonomy)
|
||||
|
|
|
@ -15,6 +15,7 @@ output['values'] = []
|
|||
with open(filename) as fp:
|
||||
t = json.load(fp)
|
||||
|
||||
|
||||
def lookupPredicate(predicate=False):
|
||||
if not predicate:
|
||||
return False
|
||||
|
@ -22,6 +23,7 @@ def lookupPredicate(predicate=False):
|
|||
if p['value'] == predicate:
|
||||
return True
|
||||
|
||||
|
||||
def lookupValues(predicate=False):
|
||||
if not predicate:
|
||||
return False
|
||||
|
@ -29,6 +31,7 @@ def lookupValues(predicate=False):
|
|||
if p['predicate'] == predicate:
|
||||
return True
|
||||
|
||||
|
||||
def machineTag(namespace=False, predicate=False, value=None, expanded=None):
|
||||
|
||||
if namespace is False or predicate is False:
|
||||
|
@ -54,6 +57,7 @@ def machineTag(namespace=False, predicate=False, value=None, expanded=None):
|
|||
prefix = []
|
||||
top = []
|
||||
|
||||
|
||||
def flatten(root, prefix_keys=True):
|
||||
dicts = [([], root)]
|
||||
ret = {}
|
||||
|
@ -70,11 +74,12 @@ def flatten(root, prefix_keys=True):
|
|||
else:
|
||||
p = ':'.join(prefix.rsplit(':')[:-1])
|
||||
if debug:
|
||||
print (namespace+":"+p+"="+v)
|
||||
print(namespace + ":" + p + "=" + v)
|
||||
machineTag(namespace=namespace, predicate=p, value=prefix.split(':')[-1], expanded=v)
|
||||
ret[prefix] = v
|
||||
return ret
|
||||
|
||||
flatten ( root = t)
|
||||
|
||||
print (json.dumps(output))
|
||||
flatten(root=t)
|
||||
|
||||
print(json.dumps(output))
|
||||
|
|
|
@ -54,13 +54,16 @@ if args.a:
|
|||
doc = doc + "= MISP taxonomies and classification as machine tags\n\n"
|
||||
doc = doc + "Generated from https://github.com/MISP/misp-taxonomies.\n\n"
|
||||
doc = doc + "\nimage::{images-cdn}misp-logo.png[MISP logo]\n"
|
||||
doc = doc + "Taxonomies that can be used in MISP (2.4) and other information sharing tool and expressed in Machine Tags (Triple Tags). A machine tag is composed of a namespace (MUST), a predicate (MUST) and an (OPTIONAL) value. Machine tags are often called triple tag due to their format.\n"
|
||||
doc = "{} {} {} {}".format(doc, "Taxonomies that can be used in MISP (2.4) and other information sharing tool and expressed in Machine Tags (Triple Tags).",
|
||||
"A machine tag is composed of a namespace (MUST), a predicate (MUST) and an (OPTIONAL) value.",
|
||||
"Machine tags are often called triple tag due to their format.\n")
|
||||
doc = doc + "\n\n"
|
||||
|
||||
if args.n:
|
||||
del taxonomies[:]
|
||||
taxonomies.append(args.n)
|
||||
|
||||
|
||||
def asciidoc(content=False, adoc=doc, t='title'):
|
||||
if not args.a:
|
||||
return False
|
||||
|
@ -71,12 +74,15 @@ def asciidoc(content=False, adoc=doc, t='title'):
|
|||
content = '=== ' + content
|
||||
elif t == 'namespace':
|
||||
content = '== ' + content + '\n'
|
||||
content = content + 'NOTE: ' + namespace + ' namespace available in JSON format at https://github.com/MISP/misp-taxonomies/blob/master/' + namespace + '/machinetag.json[*this location*]. The JSON format can be freely reused in your application or automatically enabled in https://www.github.com/MISP/MISP[MISP] taxonomy.'
|
||||
content = "{} {} {} {} {} {} {}".format(content, 'NOTE:', namespace, 'namespace available in JSON format at https://github.com/MISP/misp-taxonomies/blob/master/',
|
||||
namespace, '/machinetag.json[*this location*]. The JSON format can be freely reused in your application',
|
||||
'or automatically enabled in https://www.github.com/MISP/MISP[MISP] taxonomy.')
|
||||
elif t == 'description':
|
||||
content = '\n'+content+'\n'
|
||||
content = '\n' + content + '\n'
|
||||
adoc = adoc + content
|
||||
return adoc
|
||||
|
||||
|
||||
def machineTag(namespace=False, predicate=False, value=None):
|
||||
|
||||
if namespace is False or predicate is False:
|
||||
|
@ -86,6 +92,7 @@ def machineTag(namespace=False, predicate=False, value=None):
|
|||
else:
|
||||
return (u'{0}:{1}=\"{2}\"'.format(namespace, predicate, value))
|
||||
|
||||
|
||||
for taxonomy in taxonomies:
|
||||
filename = os.path.join(thisDir, "../", taxonomy, "machinetag.json")
|
||||
with open(filename) as fp:
|
||||
|
@ -99,7 +106,7 @@ for taxonomy in taxonomies:
|
|||
doc = asciidoc(content=t['namespace'], adoc=doc, t='namespace')
|
||||
doc = asciidoc(content=t['description'], adoc=doc, t='description')
|
||||
if args.v:
|
||||
print ('{0}'.format(t['description']))
|
||||
print('{0}'.format(t['description']))
|
||||
for predicate in t['predicates']:
|
||||
if args.a:
|
||||
doc = asciidoc(content=predicate['value'], adoc=doc, t='predicate')
|
||||
|
@ -110,11 +117,11 @@ for taxonomy in taxonomies:
|
|||
if predicate.get('description'):
|
||||
doc = asciidoc(content=machineTag(namespace=namespace, predicate=predicate['description']), adoc=doc, t='description')
|
||||
else:
|
||||
print (machineTag(namespace=namespace, predicate=predicate['value']))
|
||||
print(machineTag(namespace=namespace, predicate=predicate['value']))
|
||||
if args.e:
|
||||
print ("--> " + machineTag(namespace=expanded_namespace, predicate=predicate['expanded']))
|
||||
print("--> " + machineTag(namespace=expanded_namespace, predicate=predicate['expanded']))
|
||||
if predicate.get('description'):
|
||||
print ("--> " + predicate['description'])
|
||||
print("--> " + predicate['description'])
|
||||
else:
|
||||
for e in t['values']:
|
||||
if e['predicate'] == predicate['value']:
|
||||
|
@ -125,10 +132,10 @@ for taxonomy in taxonomies:
|
|||
doc = asciidoc(content=machineTag(namespace=namespace, predicate=e['predicate'], value=v['value']), adoc=doc)
|
||||
doc = asciidoc(content=machineTag(namespace=namespace, predicate=v['expanded']), adoc=doc, t='description')
|
||||
else:
|
||||
print (machineTag(namespace=namespace, predicate=e['predicate'], value=v['value']))
|
||||
print(machineTag(namespace=namespace, predicate=e['predicate'], value=v['value']))
|
||||
if args.e:
|
||||
if'expanded' in v:
|
||||
print ("--> " + machineTag(namespace=namespace, predicate=expanded, value=v['expanded']))
|
||||
print("--> " + machineTag(namespace=namespace, predicate=expanded, value=v['expanded']))
|
||||
|
||||
if args.a:
|
||||
print (doc)
|
||||
print(doc)
|
||||
|
|
Loading…
Reference in New Issue