Update modules/botnet_protect.py

This commit is contained in:
Nova Cat 2025-01-11 00:08:29 -08:00
parent dcb4d2f0f1
commit b9859c7fa2

View file

@ -1,24 +1,36 @@
import threading
__ircat_type__ = "allsocket"
__ircat_requires__ = []
__ircat_giveme__ = ["banprovider", "threadid"] # Only command and allsocket have these.
__ircat_requires__ = ["ban-provider"]
__ircat_giveme__ = ["sql"] # Only command and allsocket have these.
__ircat_fakechannels__ = {"#IRCATSUCKS": "WHATEVER YOU DO, DO NOT JOIN IF YOU ARE HUMAN"}
class IRCatModule:
sus_strings = [
" .''."
" .''." # Latest Supernets spambot!
]
memory = {} # {nick: {channel: trustlevel}} one can also be {nick: True} if it is whitelisted for the session.
def __init__(self, banprovider):
self.ban_provider = banprovider
def __init__(self, ban_provider, sql):
self.ban_provider = ban_provider
if ban_provider == "sql":
self.useSQLengine = True
self.SQLengine = sql
def ban(self, ip):
if self.useSQLengine:
cur = self.SQLengine.conn.cursor()
else:
open(self.ban_provider, "a").write(f"\n{ip} Botnet detected!")
raise Exception("Botnet detected!")
def onSocket(self, ip, socket, value, cachedNick=None, validated=False):
if validated:
if self.memory[cachedNick + "|" + ip] != True:
if "JOIN" in value:
target = value.split(" ")[1]
memory[cachedNick + "|" + ip][target] = 1 # 1: Just joined the channel, continue observing.
self.memory[cachedNick + "|" + ip][target] = 1 # 1: Just joined the channel, continue observing.
if target = "#IRCATSUCKS":
self.ban(ip)
elif "PRIVMSG" in value:
target = value.split(" ")[1]
content = " ".join(value.split(" ")[2:])[1:]
if content in sus_strings and self.memory[cachedNick + "|" + ip][target] == 1:
self.ban_provider.ban(target_mask=ip, reason="Botnet detected!")
self.ban(ip)
else:
self.memory[cachedNick + "|" + ip] = True # Trust the connection :3