adding custom API

Adding the possibility to have our own API server.
pull/335/head
Fafner [_KeyZee_] 2019-09-17 11:07:23 +02:00 committed by GitHub
parent 5ebd0bd4fc
commit dc84c9f972
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -3,10 +3,12 @@ import requests
misperrors = {'error': 'Error'}
mispattributes = {'input': ['vulnerability'], 'output': ['text']}
moduleinfo = {'version': '0.2', 'author': 'Alexandre Dulaunoy', 'description': 'An expansion hover module to expand information about CVE id.', 'module-type': ['hover']}
moduleconfig = []
moduleinfo = {'version': '0.3', 'author': 'Alexandre Dulaunoy', 'description': 'An expansion hover module to expand information about CVE id.', 'module-type': ['hover']}
moduleconfig = ["custom_API"]
cveapi_url = 'https://cve.circl.lu/api/cve/'
def check_url(url):
return "{}/".format(url) if not url.endswith('/') else url
def handler(q=False):
if q is False:
@ -16,7 +18,8 @@ def handler(q=False):
misperrors['error'] = 'Vulnerability id missing'
return misperrors
r = requests.get(cveapi_url + request.get('vulnerability'))
api_url = check_url(request['config']['custom_API']) if request['config'].get('custom_API') else cveapi_url
r = requests.get("{}{}".format(api_url, request.get('vulnerability')))
if r.status_code == 200:
vulnerability = json.loads(r.text)
if vulnerability:
@ -25,7 +28,7 @@ def handler(q=False):
else:
summary = 'Non existing CVE'
else:
misperrors['error'] = 'cve.circl.lu API not accessible'
misperrors['error'] = 'API not accessible'
return misperrors['error']
r = {'results': [{'types': mispattributes['output'], 'values': summary}]}