Merge pull request #1 from jesopo/develop

Develop
This commit is contained in:
David Schultz 2020-10-04 17:43:38 -05:00 committed by GitHub
commit 35ce974a0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 43 deletions

View file

@ -83,7 +83,7 @@ class Module(ModuleManager.BaseModule):
channel = server.channels.get(channel_name) channel = server.channels.get(channel_name)
args = timer.kwargs.get("args", [timer.kwargs.get("arg", None)]) args = timer.kwargs.get("args", [timer.kwargs.get("arg", None)])
if args: if any(args):
channel.send_modes(args, False) channel.send_modes(args, False)
else: else:
channel.send_mode(timer.kwargs["mode"], False) channel.send_mode(timer.kwargs["mode"], False)
@ -238,7 +238,7 @@ class Module(ModuleManager.BaseModule):
if event["spec"][1]: if event["spec"][1]:
self.timers.add_persistent("unmode", event["spec"][1], self.timers.add_persistent("unmode", event["spec"][1],
channel=event["spec"][0].id, mode="m") channel=event["spec"][0].id, mode="-m")
@utils.hook("received.command.cunmute") @utils.hook("received.command.cunmute")
@utils.kwarg("require_mode", "o") @utils.kwarg("require_mode", "o")
@utils.kwarg("require_access", "high,cmute") @utils.kwarg("require_access", "high,cmute")

View file

@ -43,14 +43,22 @@ class Module(ModuleManager.BaseModule):
failed = [] failed = []
for list in lists: for list in lists:
record = self._check_list(list.hostname, address) record = self._check_list(list.hostname, address)
if not record == None: if record is not None:
reason = list.process(record) or "unknown" a_record, txt_record = record
reason = list.process(a_record, txt_record) or "unknown"
failed.append((list.hostname, reason)) failed.append((list.hostname, reason))
return failed return failed
def _check_list(self, list, address): def _check_list(self, list, address):
list_address = "%s.%s" % (address, list) list_address = "%s.%s" % (address, list)
try: try:
return dns.resolver.query(list_address, "A")[0].to_text() a_record = dns.resolver.resolve(list_address, "A")[0].to_text()
except dns.resolver.NXDOMAIN: except dns.resolver.NXDOMAIN:
return None return None
try:
txt_record = dns.resolver.resolve(list_address, "TXT")[0].to_text()
except:
txt_record = None
return (a_record, txt_record)

View file

@ -5,23 +5,28 @@ class DNSBL(object):
if not hostname == None: if not hostname == None:
self.hostname = hostname self.hostname = hostname
def process(self, result: str): def process(self, a_record, txt_record):
return result out = a_record
if txt_record is not None:
out += f" - {txt_record}"
return out
class ZenSpamhaus(DNSBL): class ZenSpamhaus(DNSBL):
hostname = "zen.spamhaus.org" hostname = "zen.spamhaus.org"
def process(self, result): def process(self, a_record, txt_record):
result = result.rsplit(".", 1)[1] result = a_record.rsplit(".", 1)[1]
if result in ["2", "3", "9"]: if result in ["2", "3", "9"]:
desc = "spam" desc = "spam"
elif result in ["4", "5", "6", "7"]: elif result in ["4", "5", "6", "7"]:
desc = "exploits" desc = "exploits"
else:
desc = "unknown"
return f"{result} - {desc}" return f"{result} - {desc}"
class EFNetRBL(DNSBL): class EFNetRBL(DNSBL):
hostname = "rbl.efnetrbl.org" hostname = "rbl.efnetrbl.org"
def process(self, result): def process(self, a_record, txt_record):
result = result.rsplit(".", 1)[1] result = a_record.rsplit(".", 1)[1]
if result == "1": if result == "1":
desc = "proxy" desc = "proxy"
elif result in ["2", "3"]: elif result in ["2", "3"]:
@ -32,46 +37,30 @@ class EFNetRBL(DNSBL):
desc = "flooding" desc = "flooding"
return f"{result} - {desc}" return f"{result} - {desc}"
DRONEBL_CATEGORIES = {
3: "IRC drone",
5: "bottler",
6: "unknown spambot or drone",
7: "DDoS drone",
8: "open SOCKS proxy",
9: "open HTTP proxy",
10: "proxychain",
11: "web page proxy",
12: "open DNS resolver",
13: "brute force attacker",
14: "open WINGATE proxy",
15: "compromised router/gateway",
16: "autorooting malware",
17: "detected botnet IP",
18: "DNS/MX on IRC",
19: "abused VPN service"
}
class DroneBL(DNSBL): class DroneBL(DNSBL):
hostname = "dnsbl.dronebl.org" hostname = "dnsbl.dronebl.org"
def process(self, result):
result = int(result.rsplit(".", 1)[1])
desc = DRONEBL_CATEGORIES.get(result, "unknown")
return f"{result} - {desc}"
class AbuseAtCBL(DNSBL): class AbuseAtCBL(DNSBL):
hostname = "cbl.abuseat.org" hostname = "cbl.abuseat.org"
def process(self, result): def process(self, a_record, txt_record):
result = result.rsplit(".", 1)[1] result = a_record.rsplit(".", 1)[1]
if result == "2": if result == "2":
desc = "abuse" desc = "abuse"
else: else:
desc = "unknown" desc = "unknown"
return f"{result} - {desc}" return f"{result} - {desc}"
class TorExitDan(DNSBL):
hostname = "torexit.dan.me.uk"
def process(self, a_record, txt_record):
return "tor exit"
DEFAULT_LISTS = [ DEFAULT_LISTS = [
ZenSpamhaus(), ZenSpamhaus(),
EFNetRBL(), EFNetRBL(),
DroneBL(), DroneBL(),
AbuseAtCBL() AbuseAtCBL(),
TorExitDan()
] ]
def default_lists(): def default_lists():

View file

@ -228,6 +228,9 @@ class Module(ModuleManager.BaseModule):
if existing_hook: if existing_hook:
raise utils.EventError("There's already a hook for %s" % raise utils.EventError("There's already a hook for %s" %
hook_name) hook_name)
if hook_name == None:
command = "%s%s" % (event["command_prefix"], event["command"])
raise utils.EventError("Not enough arguments (Usage: %s add <hook>)" % command)
all_hooks[hook_name] = { all_hooks[hook_name] = {
"events": DEFAULT_EVENT_CATEGORIES.copy(), "events": DEFAULT_EVENT_CATEGORIES.copy(),

View file

@ -55,7 +55,7 @@ class Module(ModuleManager.BaseModule):
for record_type in record_types: for record_type in record_types:
record_type_strip = record_type.rstrip("?").upper() record_type_strip = record_type.rstrip("?").upper()
try: try:
query_result = resolver.query(hostname, record_type_strip, query_result = resolver.resolve(hostname, record_type_strip,
lifetime=4) lifetime=4)
query_results = [q.to_text() for q in query_result] query_results = [q.to_text() for q in query_result]
results.append([record_type_strip, query_result.rrset.ttl, results.append([record_type_strip, query_result.rrset.ttl,

View file

@ -66,7 +66,8 @@ class Module(ModuleManager.BaseModule):
self._set_throttle(sender, positive) self._set_throttle(sender, positive)
karma_str = self._karma_str(karma) karma_str = self._karma_str(karma)
karma_total = self._karma_str(self._get_karma(server, target)) karma_total = sum(self._get_karma(server, target).values())
karma_total = self._karma_str(karma_total)
return True, "%s now has %s karma (%s from %s)" % ( return True, "%s now has %s karma (%s from %s)" % (
target, karma_total, karma_str, sender.nickname) target, karma_total, karma_str, sender.nickname)
@ -118,18 +119,32 @@ class Module(ModuleManager.BaseModule):
target = event["user"].nickname target = event["user"].nickname
target = self._get_target(event["server"], target) target = self._get_target(event["server"], target)
karma = self._karma_str(self._get_karma(event["server"], target)) karma = sum(self._get_karma(event["server"], target).values())
karma = self._karma_str(karma)
event["stdout"].write("%s has %s karma" % (target, karma)) event["stdout"].write("%s has %s karma" % (target, karma))
def _get_karma(self, server, target): @utils.hook("received.command.karmawho")
@utils.spec("!<target>string")
def karmawho(self, event):
target = event["spec"][0]
karma = self._get_karma(event["server"], target, True)
karma = sorted(list(karma.items()),
key=lambda k: abs(k[1]),
reverse=True)
parts = ["%s (%d)" % (n, v) for n, v in karma]
event["stdout"].write("%s has karma from: %s" %
(target, ", ".join(parts)))
def _get_karma(self, server, target, own=False):
settings = dict(server.get_all_user_settings("karma-%s" % target)) settings = dict(server.get_all_user_settings("karma-%s" % target))
target_lower = server.irc_lower(target) target_lower = server.irc_lower(target)
if target_lower in settings: if target_lower in settings and not own:
del settings[target_lower] del settings[target_lower]
return sum(settings.values()) return settings
@utils.hook("received.command.resetkarma") @utils.hook("received.command.resetkarma")
@utils.kwarg("min_args", 2) @utils.kwarg("min_args", 2)

View file

@ -1,7 +1,7 @@
beautifulsoup4 ==4.8.0 beautifulsoup4 ==4.8.0
cryptography ==2.7 cryptography ==2.7
dataclasses ==0.6;python_version<'3.7' dataclasses ==0.6;python_version<'3.7'
dnspython ==1.16.0 dnspython ==2.0.0
feedparser ==5.2.1 feedparser ==5.2.1
html5lib ==1.0.1 html5lib ==1.0.1
isodate ==0.6.0 isodate ==0.6.0