From 513ad99b9344146acab072bed6e41f80f517c2eb Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sat, 29 May 2021 16:24:30 +0200 Subject: [PATCH] new: [api] namespace API access added You can do queries like: - http://127.0.0.1:5000/namespace/finduuid/mitre-attack-id/T1589.003 and also list the known namespaces of the CyCAT instance. curl -X 'GET' \ 'http://127.0.0.1:5000/namespace/getall' \ -H 'accept: application/json' and get [ "capec", "mitre-attack-id" ] --- backend/bin/server.py | 27 +++++++++++++++++++++++++++ crawler/mitre-cti/cti-importer.py | 1 + 2 files changed, 28 insertions(+) diff --git a/backend/bin/server.py b/backend/bin/server.py index e8b0a1c..d778ad1 100644 --- a/backend/bin/server.py +++ b/backend/bin/server.py @@ -33,6 +33,7 @@ class info(Resource): info['publishers'] = r.zcard('t:1') info['projects'] = r.zcard('t:2') info['items'] = r.zcard('t:3') + info['namespaces'] = r.scard('idnamespace') info['version'] = version return info @@ -139,6 +140,32 @@ class relationshipsexpanded(Resource): else: return {'message': 'UUID is incorrect'}, 400 +@api.route('/namespace/getall') +@api.doc(description="List all known namespaces.") +class namespacegetall(Resource): + def get(self): + s = r.smembers("idnamespace") + return(list(s)) + +@api.route('/namespace/getid/') +@api.doc(description="Get all ID from a given namespace.") +class namespacegetid(Resource): + def get(self, namespace=None): + if namespace is None: + return None + k = "idk:{}".format(namespace) + s = r.smembers(k) + return(list(s)) + +@api.route('/namespace/finduuid//') +@api.doc(description="Get all known UUID for a given namespace id.") +class namespacefinduuid(Resource): + def get(self, namespace=None, namespaceid=None): + if namespaceid is None or namespace is None: + return None + k = "id:{}:{}".format(namespace, namespaceid) + s = r.smembers(k) + return(list(s)) if __name__ == '__main__': app.run() diff --git a/crawler/mitre-cti/cti-importer.py b/crawler/mitre-cti/cti-importer.py index 5ea9f63..9731b2d 100644 --- a/crawler/mitre-cti/cti-importer.py +++ b/crawler/mitre-cti/cti-importer.py @@ -48,6 +48,7 @@ def addexternalid(uuidsource=None, namespace=None, namespaceid=None): rdb.sadd(k, uuidsource) k = "idk:{}".format(namespace) rdb.sadd(k, namespaceid) + rdb.sadd("idnamespace", namespace) models = ['enterprise-attack', 'mobile-attack', 'ics-attack', 'pre-attack']