|
|
@@ -25,7 +25,8 @@ BUFLEN = 16384
|
|
|
ALLOWED_IPS = []
|
|
|
BLOCKED_HOSTS = ['ads.doubleclick.net', 'telemetry.microsoft.com']
|
|
|
AUTO_BAN_STRIKES = 3 # Intentos de flood antes de banear la IP en memoria
|
|
|
-banned_ips_memory = set() # Lista negra dinámica en RAM
|
|
|
+BAN_TIME = 3600 # Tiempo de baneo en segundos (3600s = 1 hora)
|
|
|
+banned_ips_memory = {} # Diccionario: guarda la IP y su tiempo de expiración
|
|
|
ip_strikes = {}
|
|
|
|
|
|
# --- SECCIÓN DE CUSTOM HEADERS (Inyectados en la respuesta 101) ---
|
|
|
@@ -93,9 +94,16 @@ class ConnectionHandler(threading.Thread):
|
|
|
client_ip = self.addr[0]
|
|
|
|
|
|
try:
|
|
|
- # 1. Filtro de Auto-Baneo (Evita gasto de CPU en atacantes)
|
|
|
+ # 1. Filtro de Auto-Baneo temporal (1 hora)
|
|
|
if client_ip in banned_ips_memory:
|
|
|
- return # Cierra silenciosamente
|
|
|
+ if time.time() > banned_ips_memory[client_ip]:
|
|
|
+ # El tiempo de castigo terminó, perdonamos la IP
|
|
|
+ del banned_ips_memory[client_ip]
|
|
|
+ if client_ip in ip_strikes:
|
|
|
+ del ip_strikes[client_ip]
|
|
|
+ log(f"🔓 Baneo expirado. Acceso restaurado.", self.addr)
|
|
|
+ else:
|
|
|
+ return # Sigue baneado: Cierra silenciosamente
|
|
|
|
|
|
# 2. Validación de Lista Blanca
|
|
|
if ALLOWED_IPS and client_ip not in ALLOWED_IPS:
|
|
|
@@ -108,8 +116,8 @@ class ConnectionHandler(threading.Thread):
|
|
|
# Si viola el cooldown, sumamos un strike
|
|
|
ip_strikes[client_ip] = ip_strikes.get(client_ip, 0) + 1
|
|
|
if ip_strikes[client_ip] >= AUTO_BAN_STRIKES:
|
|
|
- banned_ips_memory.add(client_ip)
|
|
|
- log(f"⛔ IP Baneada en memoria RAM por Flood/Spam", self.addr)
|
|
|
+ banned_ips_memory[client_ip] = time.time() + BAN_TIME
|
|
|
+ log(f"⛔ IP Baneada en memoria por {BAN_TIME} segundos (Flood/Spam)", self.addr)
|
|
|
return
|
|
|
|
|
|
ip_cooldowns[client_ip] = now
|