feat: implement dual-stack IPv4/IPv6 auditing and updated logs
This commit is contained in:
1 parent
68b8125279
commit
b08e4bec29
2 files changed
+40
-25
No files matched your search
+32
-25
@@ -29,41 +29,48 @@ class FirewallAuditor:
|
||||
continue
|
||||
|
||||
val = d.get('value')
|
||||
if val and ':' not in val:
|
||||
if 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
|
||||
except Exception as e:
|
||||
logging.error(f"LAPI Query Failed: {e}")
|
||||
return None
|
||||
|
||||
def get_kernel_state(self):
|
||||
"""Scans ALL sets in the crowdsec table to find every blocked IP."""
|
||||
try:
|
||||
cmd = ["/usr/sbin/nft", "-j", "list", "table", "ip", "crowdsec"]
|
||||
res = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
||||
data = json.loads(res.stdout)
|
||||
"""Scans BOTH IPv4 and IPv6 sets in the crowdsec tables."""
|
||||
all_ips = set()
|
||||
targets = [
|
||||
{"family": "ip", "table": "crowdsec"},
|
||||
{"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', []):
|
||||
nft_set = item.get('set')
|
||||
if nft_set:
|
||||
elements = nft_set.get('elem', [])
|
||||
for e in elements:
|
||||
if isinstance(e, dict):
|
||||
inner = e.get('elem', e)
|
||||
if isinstance(inner, dict):
|
||||
val = inner.get('val')
|
||||
if val:
|
||||
ips.add(val)
|
||||
else:
|
||||
ips.add(e)
|
||||
return ips
|
||||
for item in data.get('nftables', []):
|
||||
nft_set = item.get('set')
|
||||
if nft_set:
|
||||
elements = nft_set.get('elem', [])
|
||||
for e in elements:
|
||||
if isinstance(e, dict):
|
||||
inner = e.get('elem', e)
|
||||
if isinstance(inner, dict):
|
||||
val = inner.get('val')
|
||||
if val:
|
||||
all_ips.add(val)
|
||||
else:
|
||||
all_ips.add(e)
|
||||
except subprocess.CalledProcessError:
|
||||
# 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:
|
||||
logging.error(f"Kernel Table Scan Failed: {e}")
|
||||
return set()
|
||||
return all_ips
|
||||
|
||||
def heal(self):
|
||||
"""Directly restarts the bouncer service."""
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user