nemubot/modules/cve.py

34 lines
768 B
Python
Raw Normal View History

2014-11-17 13:24:18 +00:00
from bs4 import BeautifulSoup
2015-07-07 10:34:00 +00:00
from urllib.parse import quote
from nemubot.hooks import hook
2015-07-07 10:34:00 +00:00
from nemubot.tools.web import getURLContent
2014-11-17 13:24:18 +00:00
from more import Response
2015-07-07 10:34:00 +00:00
"""CVE description"""
2014-11-17 13:24:18 +00:00
2015-07-07 10:34:00 +00:00
nemubotversion = 4.0
2014-11-17 13:24:18 +00:00
2015-07-07 10:34:00 +00:00
BASEURL_MITRE = 'http://cve.mitre.org/cgi-bin/cvename.cgi?name='
2014-11-17 13:24:18 +00:00
2015-07-07 10:34:00 +00:00
def get_cve(cve_id):
search_url = BASEURL_MITRE + quote(cve_id.upper())
2014-11-17 13:24:18 +00:00
2015-07-07 10:34:00 +00:00
soup = BeautifulSoup(getURLContent(search_url))
desc = soup.body.findAll('td')
2014-11-17 13:24:18 +00:00
2015-07-07 10:34:00 +00:00
return desc[17].text.replace("\n", " ") + " Moar at " + search_url
2014-11-17 13:24:18 +00:00
2015-07-07 10:34:00 +00:00
@hook("cmd_hook", "cve")
def get_cve_desc(msg):
res = Response(channel=msg.channel)
2014-11-17 13:24:18 +00:00
2015-07-07 10:34:00 +00:00
for cve_id in msg.args:
if cve_id[:3].lower() != 'cve':
cve_id = 'cve-' + cve_id
2014-11-17 13:24:18 +00:00
2015-07-07 10:34:00 +00:00
res.append_message(get_cve(cve_id))
2014-11-17 13:24:18 +00:00
2015-07-07 10:34:00 +00:00
return res