2018-09-02 10:44:06 +00:00
|
|
|
#--require-config virustotal-api-key
|
|
|
|
|
|
|
|
import re
|
2018-09-24 14:13:27 +00:00
|
|
|
from src import Utils
|
2018-09-02 10:44:06 +00:00
|
|
|
|
|
|
|
URL_VIRUSTOTAL = "https://www.virustotal.com/vtapi/v2/url/report"
|
|
|
|
RE_URL = re.compile(r"https?://\S+", re.I)
|
|
|
|
|
|
|
|
class Module(object):
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2018-09-02 10:44:06 +00:00
|
|
|
self.bot = bot
|
|
|
|
self.events = events
|
2018-09-02 18:54:45 +00:00
|
|
|
exports.add("channelset", {"setting": "check-urls",
|
|
|
|
"help": "Enable/Disable automatically checking for "
|
|
|
|
"malicious URLs", "validate": Utils.bool_or_none})
|
2018-09-09 09:17:22 +00:00
|
|
|
exports.add("serverset", {"setting": "check-urls",
|
|
|
|
"help": "Enable/Disable automatically checking for "
|
|
|
|
"malicious URLs", "validate": Utils.bool_or_none})
|
2018-09-02 18:54:45 +00:00
|
|
|
exports.add("channelset", {"setting": "check-urls-kick",
|
|
|
|
"help": "Enable/Disable automatically kicking users that "
|
|
|
|
"send malicious URLs", "validate": Utils.bool_or_none})
|
2018-09-02 10:44:06 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.message.channel")
|
2018-09-02 10:44:06 +00:00
|
|
|
def message(self, event):
|
|
|
|
match = RE_URL.search(event["message"])
|
|
|
|
if match and event["channel"].get_setting("check-urls",
|
|
|
|
event["server"].get_setting("check-urls", False)):
|
|
|
|
url = match.group(0)
|
|
|
|
page = Utils.get_url(URL_VIRUSTOTAL, get_params={
|
|
|
|
"apikey": self.bot.config["virustotal-api-key"],
|
|
|
|
"resource": url}, json=True)
|
|
|
|
|
2018-09-02 10:50:32 +00:00
|
|
|
if page and page.get("positives", 0) > 1:
|
|
|
|
if event["channel"].get_setting("check-urls-kick", False):
|
|
|
|
event["channel"].send_kick(event["user"].nickname,
|
|
|
|
"Don't send malicious URLs!")
|
|
|
|
else:
|
2018-09-02 10:44:06 +00:00
|
|
|
self.events.on("send.stdout").call(
|
|
|
|
module_name="CheckURL", target=event["channel"],
|
|
|
|
message="%s just send a malicous URL!" %
|
|
|
|
event["user"].nickname)
|
|
|
|
|