feat: implement dual-stack IPv4/IPv6 auditing and updated logs

This commit is contained in:
patrick committed 2026-01-23 13:18:55 -05:00
1 parent 68b8125279
commit b08e4bec29
2 files changed
+40 -25

No files matched your search

+32 -25
View File
@@ -29,41 +29,48 @@ class FirewallAuditor:
continue continue
val = d.get('value') val = d.get('value')
if val and ':' not in val: if val:
ips.add(val) ips.add(val)
logging.info(f"LAPI Parser (IPv4-Only) found {len(ips)} active bans.") logging.info(f"LAPI Parser: found {len(ips)} active bans (IPv4+IPv6).")
return ips return ips
except Exception as e: except Exception as e:
logging.error(f"LAPI Query Failed: {e}") logging.error(f"LAPI Query Failed: {e}")
return None return None
def get_kernel_state(self): def get_kernel_state(self):
"""Scans ALL sets in the crowdsec table to find every blocked IP.""" """Scans BOTH IPv4 and IPv6 sets in the crowdsec tables."""
try: all_ips = set()
cmd = ["/usr/sbin/nft", "-j", "list", "table", "ip", "crowdsec"] targets = [
res = subprocess.run(cmd, capture_output=True, text=True, check=True) {"family": "ip", "table": "crowdsec"},
data = json.loads(res.stdout) {"family": "ip6", "table": "crowdsec6"}
]
for target in targets:
try:
cmd = ["/usr/sbin/nft", "-j", "list", "table", target["family"], target["table"]]
res = subprocess.run(cmd, capture_output=True, text=True, check=True)
data = json.loads(res.stdout)
ips = set() for item in data.get('nftables', []):
for item in data.get('nftables', []): nft_set = item.get('set')
nft_set = item.get('set') if nft_set:
if nft_set: elements = nft_set.get('elem', [])
elements = nft_set.get('elem', []) for e in elements:
for e in elements: if isinstance(e, dict):
if isinstance(e, dict): inner = e.get('elem', e)
inner = e.get('elem', e) if isinstance(inner, dict):
if isinstance(inner, dict): val = inner.get('val')
val = inner.get('val') if val:
if val: all_ips.add(val)
ips.add(val) else:
else: all_ips.add(e)
ips.add(e) except subprocess.CalledProcessError:
return ips # This happens if a node doesn't have IPv6 enabled/initialized
logging.debug(f"Table {target['table']} not found, skipping.")
except Exception as e:
logging.error(f"Kernel Table Scan Failed for {target['table']}: {e}")
except Exception as e: return all_ips
logging.error(f"Kernel Table Scan Failed: {e}")
return set()
def heal(self): def heal(self):
"""Directly restarts the bouncer service.""" """Directly restarts the bouncer service."""
+8
View File
@@ -0,0 +1,8 @@
2026-01-22T23:17:42.801219 - HEAL: Fixed desync of 99 IPs
2026-01-22T23:47:43.636016 - HEAL: Fixed desync of 102 IPs
2026-01-23T00:37:44.806560 - HEAL: Fixed desync of 104 IPs
2026-01-23T04:37:49.240762 - HEAL: Fixed desync of 94 IPs
2026-01-23T07:57:52.612421 - HEAL: Fixed desync of 96 IPs
2026-01-23T10:37:55.353533 - HEAL: Fixed desync of 77 IPs
2026-01-23T11:27:56.544553 - HEAL: Fixed desync of 77 IPs
2026-01-23T13:14:06.888027 - HEAL: Fixed desync of 84 IPs