bitbot-3.11-fork/modules/cve.py

38 lines
1.1 KiB
Python
Raw Normal View History

#--depends-on commands
2019-03-28 21:47:35 +00:00
import datetime, json
from src import ModuleManager, utils
URL_CVE = "https://cve.circl.lu/api/cve/%s"
class Module(ModuleManager.BaseModule):
2019-03-28 21:54:18 +00:00
_name = "CVE"
2019-03-28 21:47:35 +00:00
@utils.hook("received.command.cve", min_args=1)
def cve(self, event):
"""
2019-05-25 20:44:50 +00:00
:help: Get information for a CVE number
:usage: <CVE>
2019-03-28 21:47:35 +00:00
"""
2019-09-18 16:51:08 +00:00
cve_id = event["args_split"][0].upper()
if not cve_id.startswith("CVE-"):
cve_id = "CVE-%s" % cve_id
page = utils.http.request(URL_CVE % cve_id, json=True)
2019-03-28 21:47:35 +00:00
if page and page.data:
cve_id = page.data["id"]
published = "%sZ" % page.data["Published"].rsplit(".", 1)[0]
published = datetime.datetime.strptime(published,
utils.ISO8601_PARSE)
published = datetime.datetime.strftime(published, "%Y-%m-%d")
rank = page.data["cvss"]
summary = page.data["summary"]
event["stdout"].write("%s, %s (%s): %s" %
(cve_id, published, rank, summary))
else:
raise utils.EventsResultsError()