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)
args = timer.kwargs.get("args", [timer.kwargs.get("arg", None)])
if args:
if any(args):
channel.send_modes(args, False)
else:
channel.send_mode(timer.kwargs["mode"], False)
@ -238,7 +238,7 @@ class Module(ModuleManager.BaseModule):
if 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.kwarg("require_mode", "o")
@utils.kwarg("require_access", "high,cmute")

View file

@ -43,14 +43,22 @@ class Module(ModuleManager.BaseModule):
failed = []
for list in lists:
record = self._check_list(list.hostname, address)
if not record == None:
reason = list.process(record) or "unknown"
if record is not None:
a_record, txt_record = record
reason = list.process(a_record, txt_record) or "unknown"
failed.append((list.hostname, reason))
return failed
def _check_list(self, list, address):
list_address = "%s.%s" % (address, list)
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:
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:
self.hostname = hostname
def process(self, result: str):
return result
def process(self, a_record, txt_record):
out = a_record
if txt_record is not None:
out += f" - {txt_record}"
return out
class ZenSpamhaus(DNSBL):
hostname = "zen.spamhaus.org"
def process(self, result):
result = result.rsplit(".", 1)[1]
def process(self, a_record, txt_record):
result = a_record.rsplit(".", 1)[1]
if result in ["2", "3", "9"]:
desc = "spam"
elif result in ["4", "5", "6", "7"]:
desc = "exploits"
else:
desc = "unknown"
return f"{result} - {desc}"
class EFNetRBL(DNSBL):
hostname = "rbl.efnetrbl.org"
def process(self, result):
result = result.rsplit(".", 1)[1]
def process(self, a_record, txt_record):
result = a_record.rsplit(".", 1)[1]
if result == "1":
desc = "proxy"
elif result in ["2", "3"]:
@ -32,46 +37,30 @@ class EFNetRBL(DNSBL):
desc = "flooding"
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):
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):
hostname = "cbl.abuseat.org"
def process(self, result):
result = result.rsplit(".", 1)[1]
def process(self, a_record, txt_record):
result = a_record.rsplit(".", 1)[1]
if result == "2":
desc = "abuse"
else:
desc = "unknown"
return f"{result} - {desc}"
class TorExitDan(DNSBL):
hostname = "torexit.dan.me.uk"
def process(self, a_record, txt_record):
return "tor exit"
DEFAULT_LISTS = [
ZenSpamhaus(),
EFNetRBL(),
DroneBL(),
AbuseAtCBL()
AbuseAtCBL(),
TorExitDan()
]
def default_lists():

View file

@ -228,6 +228,9 @@ class Module(ModuleManager.BaseModule):
if existing_hook:
raise utils.EventError("There's already a hook for %s" %
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] = {
"events": DEFAULT_EVENT_CATEGORIES.copy(),

View file

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

View file

@ -66,7 +66,8 @@ class Module(ModuleManager.BaseModule):
self._set_throttle(sender, positive)
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)" % (
target, karma_total, karma_str, sender.nickname)
@ -118,18 +119,32 @@ class Module(ModuleManager.BaseModule):
target = event["user"].nickname
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))
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))
target_lower = server.irc_lower(target)
if target_lower in settings:
if target_lower in settings and not own:
del settings[target_lower]
return sum(settings.values())
return settings
@utils.hook("received.command.resetkarma")
@utils.kwarg("min_args", 2)

View file

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