mirror of
https://github.com/fabriziosalmi/patterns.git
synced 2025-12-17 17:55:48 +00:00
Create owasp2haproxy.py
This commit is contained in:
parent
95b3411231
commit
ad5e6cd789
23
owasp2haproxy.py
Normal file
23
owasp2haproxy.py
Normal file
@ -0,0 +1,23 @@
|
||||
import os
|
||||
import json
|
||||
|
||||
OUTPUT_DIR = "waf_patterns/haproxy/"
|
||||
|
||||
def load_owasp_rules(file_path):
|
||||
with open(file_path, "r") as f:
|
||||
return json.load(f)
|
||||
|
||||
def generate_haproxy_conf(rules):
|
||||
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
||||
config_file = os.path.join(OUTPUT_DIR, "waf.acl")
|
||||
|
||||
with open(config_file, "w") as f:
|
||||
f.write("# HAProxy WAF ACL rules\n")
|
||||
for rule in rules:
|
||||
f.write(f"acl block_{rule['category']} hdr_sub(User-Agent) -i {rule['pattern']}\n")
|
||||
f.write(f"http-request deny if block_{rule['category']}\n")
|
||||
print(f"[+] HAProxy WAF rules generated at {config_file}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
owasp_rules = load_owasp_rules("owasp_rules.json")
|
||||
generate_haproxy_conf(owasp_rules)
|
||||
Loading…
x
Reference in New Issue
Block a user