feat: implement dual-stack IPv4/IPv6 auditing and updated logs
This commit is contained in:
1 parent
68b8125279
commit
b08e4bec29
2 files changed
+26
-11
No files matched your search
+18
-11
@@ -29,23 +29,28 @@ 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."""
|
||||||
|
all_ips = set()
|
||||||
|
targets = [
|
||||||
|
{"family": "ip", "table": "crowdsec"},
|
||||||
|
{"family": "ip6", "table": "crowdsec6"}
|
||||||
|
]
|
||||||
|
for target in targets:
|
||||||
try:
|
try:
|
||||||
cmd = ["/usr/sbin/nft", "-j", "list", "table", "ip", "crowdsec"]
|
cmd = ["/usr/sbin/nft", "-j", "list", "table", target["family"], target["table"]]
|
||||||
res = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
res = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
||||||
data = json.loads(res.stdout)
|
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:
|
||||||
@@ -56,14 +61,16 @@ class FirewallAuditor:
|
|||||||
if isinstance(inner, dict):
|
if isinstance(inner, dict):
|
||||||
val = inner.get('val')
|
val = inner.get('val')
|
||||||
if val:
|
if val:
|
||||||
ips.add(val)
|
all_ips.add(val)
|
||||||
else:
|
else:
|
||||||
ips.add(e)
|
all_ips.add(e)
|
||||||
return ips
|
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:
|
except Exception as e:
|
||||||
logging.error(f"Kernel Table Scan Failed: {e}")
|
logging.error(f"Kernel Table Scan Failed for {target['table']}: {e}")
|
||||||
return set()
|
|
||||||
|
return all_ips
|
||||||
|
|
||||||
def heal(self):
|
def heal(self):
|
||||||
"""Directly restarts the bouncer service."""
|
"""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