patterns/README.md

160 lines
4.9 KiB
Markdown
Raw Normal View History

2024-12-21 09:14:46 +01:00
# 🔒 Patterns: OWASP CRS and Bad Bot Detection for Web Servers
Automate the scraping of **OWASP Core Rule Set (CRS)** patterns and convert them into **Apache, Nginx, Caddy, Traefik, and HAProxy** WAF configurations.
Additionally, **Bad Bot/User-Agent detection** is integrated to block malicious web crawlers and scrapers.
2024-12-21 01:50:43 +01:00
2024-12-21 09:14:46 +01:00
> 🚀 **Protect your servers against SQL Injection (SQLi), XSS, RCE, LFI, and malicious bots with automated daily updates.**
2024-12-21 01:50:43 +01:00
---
2024-12-21 01:10:17 +01:00
2024-12-21 09:14:46 +01:00
## 📌 Project Highlights
- **🛡️ OWASP CRS Protection** Leverages OWASP Core Rule Set for web application firewall (WAF) defense.
- **🤖 Bad Bot Blocking** Blocks known malicious bots using public bot lists.
- **⚙️ Multi-Web Server Support** Generates WAF configs for **Apache, Nginx, Caddy, Traefik, and HAProxy**.
- **🔄 Automatic Updates** GitHub Actions fetch new rules **daily** and push updated configs.
---
## 🌐 Supported Web Servers
- **🔵 Nginx**
- **🟢 Caddy**
- **🟠 Apache (ModSecurity)**
- **🟣 Traefik**
- **🔴 HAProxy**
2024-12-21 01:50:43 +01:00
---
2024-12-21 01:10:17 +01:00
## 📂 Project Structure
```
patterns/
2024-12-21 01:41:06 +01:00
├── waf_patterns/ # 🔧 Generated WAF config files
│ ├── caddy/ # Caddy WAF configs
│ ├── nginx/ # Nginx WAF configs
2024-12-21 09:14:46 +01:00
│ ├── apache/ # Apache WAF configs (ModSecurity)
│ ├── traefik/ # Traefik WAF configs
│ └── haproxy/ # HAProxy WAF configs
│── import_apache_waf.py
│── import_caddy_waf.py
│── import_haproxy_waf.py
│── import_nginx_waf.py
│── import_traefik_waf.py
2024-12-21 01:41:06 +01:00
├── owasp.py # 🕵️ OWASP scraper (fetch CRS rules)
2024-12-21 01:10:17 +01:00
├── owasp2caddy.py # 🔄 Convert OWASP JSON to Caddy WAF configs
2024-12-21 01:41:06 +01:00
├── owasp2nginx.py # 🔄 Convert OWASP JSON to Nginx WAF configs
├── owasp2apache.py # 🔄 Convert OWASP JSON to Apache ModSecurity configs
2024-12-21 09:14:46 +01:00
├── owasp2haproxy.py # 🔄 Convert OWASP JSON to HAProxy WAF configs
├── badbots.py # 🤖 Generate WAF configs to block bad bots
├── requirements.txt # 📄 Required dependencies
2024-12-21 01:10:17 +01:00
└── .github/workflows/ # 🤖 GitHub Actions for automation
└── update_patterns.yml
```
2024-12-21 01:50:43 +01:00
---
2024-12-21 01:10:17 +01:00
## 🛠️ How It Works
### 🔹 1. Scraping OWASP Rules
2024-12-21 09:14:46 +01:00
- **`owasp.py`** scrapes the latest OWASP CRS patterns from GitHub.
- Extracts **SQLi, XSS, RCE, LFI** patterns from OWASP CRS `.conf` files.
2024-12-21 01:10:17 +01:00
2024-12-21 09:14:46 +01:00
### 🔹 2. Generating WAF Configs for Each Platform
- **`owasp2caddy.py`** Converts OWASP patterns into **Caddy WAF** rules.
- **`owasp2nginx.py`** Generates **Nginx WAF** configurations.
- **`owasp2apache.py`** Outputs **Apache ModSecurity** rules.
- **`owasp2traefik.py`** Creates **Traefik WAF** rules.
- **`owasp2haproxy.py`** Builds **HAProxy ACL** files.
2024-12-21 01:10:17 +01:00
2024-12-21 01:50:43 +01:00
### 🔹 3. Bad Bot/User-Agent Detection
2024-12-21 09:14:46 +01:00
- **`badbots.py`** fetches public bot lists and generates bot-blocking configs.
- Supports fallback lists to ensure reliable detection.
2024-12-21 01:50:43 +01:00
---
2024-12-21 01:10:17 +01:00
## ⚙️ Installation
**1. Clone the Repository:**
```bash
git clone https://github.com/your-username/patterns.git
cd patterns
```
**2. Install Dependencies:**
```bash
pip install -r requirements.txt
```
**3. Run Manually (Optional):**
```bash
python owasp.py
python owasp2caddy.py
2024-12-21 01:41:06 +01:00
python owasp2nginx.py
python owasp2apache.py
2024-12-21 01:50:43 +01:00
python badbots.py
2024-12-21 01:10:17 +01:00
```
2024-12-21 01:50:43 +01:00
---
2024-12-21 01:41:06 +01:00
## 🚀 Usage (Web Server Integration)
2024-12-21 09:14:46 +01:00
### 🔹 1. Nginx WAF Integration
2024-12-21 01:10:17 +01:00
```bash
2024-12-21 09:14:46 +01:00
sudo python3 import_nginx_waf.py
2024-12-21 01:10:17 +01:00
```
2024-12-21 09:14:46 +01:00
### 🔹 2. Caddy WAF Integration
2024-12-21 01:41:06 +01:00
```bash
2024-12-21 09:14:46 +01:00
sudo python3 import_caddy_waf.py
2024-12-21 01:41:06 +01:00
```
2024-12-21 09:14:46 +01:00
### 🔹 3. Apache WAF Integration
2024-12-21 01:41:06 +01:00
```bash
2024-12-21 09:14:46 +01:00
sudo python3 import_apache_waf.py
2024-12-21 01:41:06 +01:00
```
2024-12-21 01:10:17 +01:00
2024-12-21 01:50:43 +01:00
---
2024-12-21 09:14:46 +01:00
## 🔧 Example Output (Bot Blocker Nginx)
2024-12-21 01:50:43 +01:00
```nginx
map $http_user_agent $bad_bot {
"~*AhrefsBot" 1;
"~*SemrushBot" 1;
"~*MJ12bot" 1;
default 0;
}
if ($bad_bot) {
return 403;
}
```
---
2024-12-21 01:10:17 +01:00
## 🤖 Automation (GitHub Workflow)
2024-12-21 09:14:46 +01:00
- **🕛 Daily Updates** GitHub Actions fetch the latest OWASP CRS rules every day.
- **🔄 Auto Deployment** Pushes new `.conf` files directly to `waf_patterns/`.
- **🎯 Manual Trigger** Updates can also be triggered manually.
2024-12-21 01:10:17 +01:00
2024-12-21 01:50:43 +01:00
---
2024-12-21 01:10:17 +01:00
2024-12-21 09:14:46 +01:00
## 🤝 Contributing
1. **Fork** the repository.
2. Create a **feature branch** (`feature/new-patterns`).
3. **Commit** and push changes.
4. Open a **Pull Request**.
2024-12-21 01:10:17 +01:00
2024-12-21 01:50:43 +01:00
---
2024-12-21 01:10:17 +01:00
## 📄 License
This project is licensed under the **MIT License**.
See the [LICENSE](LICENSE) file for details.
2024-12-21 01:50:43 +01:00
---
2024-12-21 09:14:46 +01:00
## 📞 Need Help?
2024-12-21 10:00:11 +01:00
- **Issues?** Open a ticket in the [Issues Tab](https://github.com/fabriziosalmi/patterns/issues).
2024-12-21 09:14:46 +01:00
- **Questions?** Feel free to reach out via GitHub Discussions.
---
2024-12-21 01:10:17 +01:00
## 🌐 Resources
2024-12-21 09:14:46 +01:00
- [OWASP CRS](https://github.com/coreruleset/coreruleset)
2024-12-21 01:10:17 +01:00
- [Caddy Web Server](https://caddyserver.com/)
2024-12-21 01:41:06 +01:00
- [Nginx](https://nginx.org/)
- [Apache ModSecurity](https://modsecurity.org/)
2024-12-21 01:50:43 +01:00