Skip to content

Latest commit

Β 

History

87 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DevSecOps-Web Lab

Terraform Ansible OWASP Grafana MySQL License

An automated deployment of a web stack with WAF, SOC monitoring and kill chain simulation.


πŸ“‹ Table of Contents


🎯 Overview

This lab deploys a complete intentionnaly vulnerable web infrastructure 100% locally with Podman, behind a WAF (ModSecurity + OWASP CRS), supervised by a Grafana/Loki stack, and tested by attack simulations covering OWASP Top 10 2025.

Objective: This project was built to demonstrate the ability to deploy, configure, attack, detect and remediate web security incidents in a containerized environment.

What the project demonstrates

  • Complete IaC: With Terraform + Ansible, everything is versioned and reproducible
  • Production WAF: 846 OWASP CRS rules, effective blocking
  • MySQL Hardening: Password policy, SSL/TLS, least privilege
  • SOC Monitoring: Grafana dashboard with real-time LogQL queries
  • Realistic Kill Chain: Reconnaissance β†’ SQLi β†’ XSS β†’ Path Traversal
  • Secret Management: Sensitive variables encrypted with Ansible Vault
  • Documented Troubleshooting: 12 real problems with Root Cause Analysis
  • Documented attacks: all atacks are all documented on the way they were done and what was seen.

πŸ—οΈ Architecture

Here is a very simplified version of the architecture but it explains briefly well the data flow between all the components of the projects.

simplified-architecture

The detailed diagram with explanation about the small parts, data flow and role of every component can be found at docs/architecture.md


βš™οΈ Tech Stack

Domain Technology Version
Infrastructure as Code Terraform + Docker Provider ~> 3.0
Configuration Management Ansible + Ansible Vault Latest
Containerization Podman (rootless) Latest
Target Application OWASP Juice Shop latest
WAF Nginx + ModSecurity 3 + OWASP CRS 1.30.1 / 3.0.15
Database MySQL 8.0 8.0
Monitoring Grafana + Loki + Alloy 13.0.2 / latest
Attack Simulation SQLMap + Nmap Latest

πŸ“¦ Prerequisites

  • Linux (tested on Fedora / Debian / Arch)
  • Podman (or Docker) with socket enabled
  • Terraform β‰₯ 1.5
  • Ansible β‰₯ 2.15
  • Kali VM ready to go

Automated installation: If one or nothing of these ones are installed you can run

make install

and everything will be setup correctly


πŸš€ Quick Start

# 1. Provision infrastructure (5 containers)
terraform -chdir=terraform apply

# 2. Configure WAF + DB + Monitoring
ansible-playbook ansible/playbooks/site.yml --ask-vault-pass

# 3. Verify everything is running
podman ps

Service Access

Service URL Credentials
WAF (Juice Shop) http://localhost:8080 β€”
Grafana http://localhost:3001 admin / as-you-go
Loki http://localhost:3100 β€” (API)

βš”οΈ Attack Simulation (Kill Chain)

cd attack_simulation && bash simulate_killchain.sh

The script executes 5 phases covering the OWASP Top 10 2025:

Phase OWASP 2025 Category Technique Expected Result
Reconnaissance A02 Security Misconfiguration Scan for sensitive paths 403 on /phpinfo.php, /.git
SQL Injection A05 Injection OR 1=1, UNION SELECT, DROP TABLE 403 blocked
XSS A05 Injection Script alert, encoded version 403 blocked
Path Traversal A01 Broken Access Control /../../etc/passwd 200 (normalized path)
False Positive WAF Tuning O'Reilly search 500 (app error)

Expected Result

[PHASE 1] Reconnaissance (A02 Security Misconfiguration)
  /phpinfo.php β†’ HTTP 403   ← server information protected
  /.git/config β†’ HTTP 403   ← exposed repository protected

[PHASE 2] SQL Injection (A05 Injection)
  Payload : OR 1=1 β†’ HTTP 403   ← WAF blocks

[PHASE 3] Cross-Site Scripting (XSS) (A05 Injection)
  Payload : script alert β†’ HTTP 403   ← WAF blocks

SQLi blocked


πŸ“Š SOC Monitoring

Grafana Dashboard

A Security Overview dashboard with 3 panels is pre-configured:

  1. WAF Log Volume β€” time series of all requests
  2. Blocked Requests (403) β€” time series of blocks (in red)
  3. Top Attacked URIs β€” horizontal bar chart of most-targeted endpoints

LogQL Queries Used

# Total log volume
count_over_time({job="waf"} [$__interval])

# Blocked requests
count_over_time({job="waf"} |= "403" [$__interval])

# Top attacked URIs (ranking)
topk(10, sum by (uri) (count_over_time({job="waf"} |= "403" | json | __error__="" [$__interval])))

LogQL Queries

Log Pipeline

WAF (Nginx logs JSON) β†’ waf-logs volume β†’ Promtail β†’ Loki β†’ Grafana

Valid Pipeline


πŸ“ Project Structure

devsecops-web-lab/
β”‚
β”œβ”€β”€ terraform/                         # Infrastructure as Code
β”‚   β”œβ”€β”€ main.tf                        # 5 containers, network, volumes
β”‚   β”œβ”€β”€ variables.tf                   # Sensitive variables
β”‚   β”œβ”€β”€ outputs.tf                     # Output URLs
β”‚   └── grafana_provisioning/          # Grafana provisioning (IaC)
β”‚       β”œβ”€β”€ datasources/loki.yml
β”‚       └── dashboards/
β”‚           β”œβ”€β”€ dashboard_provider.yml
β”‚           └── security_overview.json
β”‚
β”œβ”€β”€ ansible/                           # Configuration Management
β”‚   β”œβ”€β”€ ansible.cfg
β”‚   β”œβ”€β”€ inventory.ini
β”‚   β”œβ”€β”€ playbooks/
β”‚   β”‚   β”œβ”€β”€ site.yml                   # Master playbook
β”‚   β”‚   β”œβ”€β”€ setup-python.yml           # Python bootstrap
β”‚   β”‚   β”œβ”€β”€ waf-setup.yml              # Nginx + ModSecurity + Promtail
β”‚   β”‚   β”œβ”€β”€ db-hardening.yml           # MySQL hardening
β”‚   β”‚   └── monitoring.yml             # Pipeline verification
β”‚   β”œβ”€β”€ files/
β”‚   β”‚   β”œβ”€β”€ waf/                       # WAF config (Nginx, ModSecurity)
β”‚   β”‚   └── promtail/                  # Promtail config
β”‚   └── group_vars/all/
β”‚       β”œβ”€β”€ vars.yml                   # Normal variables
β”‚       └── vault.yml                  # Encrypted variables
β”‚
β”œβ”€β”€ attack_simulation/
β”‚   └── simulate_killchain.sh          # Automated kill chain
β”‚
β”œβ”€β”€ grafana/dashboards/
β”‚   └── security-dashboard.json        # Exported dashboard
β”‚
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ architecture.md               # Architecture diagram and details
β”‚   β”œβ”€β”€ incident-report.md            # SOC incident report
β”‚   β”œβ”€β”€ ISSUES.md                     # Troubleshooting (12 problems)
β”‚   β”œβ”€β”€ Resources.md                  # Documentation and references
β”‚   └── evidences/bunch/                    # Screenshots
β”‚       β”œβ”€β”€ Sqli-bloque.png
β”‚       β”œβ”€β”€ Containers.png
β”‚       β”œβ”€β”€ pipeline-valide.png
β”‚       └── ...
β”‚
β”œβ”€β”€ tests.sh                          # Dependency installation script
└── README.md                         # This page

πŸ”§ Troubleshooting

12 documented incidents in docs/ISSUES.md with root cause analysis:

# Problem Solution
1 Permission denied logs WAF Bind mount β†’ Named Docker volume
2 Connection reset by peer Internal port 80 β†’ 8080
3 Python missing from containers Bootstrap with raw module
4 Nginx syntax error (backslash) Remove escape character
5 Unknown ModSecurity variable Remove proprietary log_format
6 pkill/pgrep not found Install procps
7 Logs symlinked to /dev/stdout Replace with real files
8 Incorrect MySQL vault password Align Terraform/Ansible
9 audit_log plugin missing (Community) Alternative validate_password
10 Secrets exposed via podman inspect Document best practices
11 Grafana provisioning failed Manual datasource configuration
12 WAF blocks nothing (200 instead of 403) SecRuleEngine On + SecDefaultAction deny

Feel free to update this if you encounter any problem.


πŸ“š Documentation

Document Description
docs/architecture.md Architecture diagram and data flow
docs/incident-report.md SOC incident report (kill chain + remediation)
docs/ISSUES.md Detailed troubleshooting (12 entries)
docs/Resources.md Sources, documentation and references

πŸ§ͺ Project is complete. Possible improvements

  • CI/CD pipeline integration (GitHub Actions) for automatic apply
  • Container image vulnerability scanning with Trivy
  • Advanced CRS exclusion rules for false positives
  • Grafana alerting via email/Slack on blocking spikes

πŸ“„ License

MIT - see LICENSE file.


Project completed as part of a DevSecOps / SOC Analyst learning and skill demonstration initiative.

About

Automated deployment of a secured web stack using Terraform (Docker provider) and Ansible. Features a WAF (Nginx + ModSecurity + OWASP CRS) in front of OWASP Juice Shop, with centralized log monitoring via Grafana/Loki. Includes SOC-oriented attack simulation and log analysis.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages