mirror of
https://github.com/fabriziosalmi/patterns.git
synced 2025-12-29 16:15:12 +00:00
Create owasp2traefik.py
This commit is contained in:
24
owasp2traefik.py
Normal file
24
owasp2traefik.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
OUTPUT_DIR = "waf_patterns/traefik/"
|
||||||
|
|
||||||
|
def load_owasp_rules(file_path):
|
||||||
|
with open(file_path, "r") as f:
|
||||||
|
return json.load(f)
|
||||||
|
|
||||||
|
def generate_traefik_conf(rules):
|
||||||
|
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
||||||
|
config_file = os.path.join(OUTPUT_DIR, "middleware.toml")
|
||||||
|
|
||||||
|
with open(config_file, "w") as f:
|
||||||
|
f.write("[http.middlewares]\n")
|
||||||
|
for rule in rules:
|
||||||
|
f.write(f"[http.middlewares.bad_bot_block_{rule['category']}]\n")
|
||||||
|
f.write(f" [http.middlewares.bad_bot_block_{rule['category']}.plugin.badbot]\n")
|
||||||
|
f.write(f" userAgent = [\"{rule['pattern']}\"]\n")
|
||||||
|
print(f"[+] Traefik WAF rules generated at {config_file}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
owasp_rules = load_owasp_rules("owasp_rules.json")
|
||||||
|
generate_traefik_conf(owasp_rules)
|
||||||
Reference in New Issue
Block a user