WAF (Web Application Firewall) คืออะไร?
WAF (Web Application Firewall) คือ Firewall ที่ทำงานบนชั้น Layer 7 (Application Layer) โดยตรวจสอบและกรองสอง HTTP/HTTPS Traffic ระหว่างผู้ใช้และเว็บแอปพลิเคชัน ต่างจาก Network Firewall ทั่วไปที่ดูแล IP/Port, WAF เข้าใจเนื้อหาและพฤติกรรมของคำขอเพื่อตรวจจับการโจมตีเช่น SQL Injection, XSS, CSRF, Bot Attack และอื่นๆ
WAF ช่วยป้องกันอะไรบ้าง?
| ประเภทภัยคุกคาม | WAF ช่วยได้ |
|---|---|
| SQL Injection | ตรวจจับ Pattern SQL ผิดปกติใน Query String |
| XSS | บล็อคคำขอที่มี Script Tag หรือ JavaScript Event Handler |
| CSRF | ตรวจสอบ Origin/Referer Header |
| DDoS / Bot Attack | Rate Limiting, Bot Detection, Challenge Pages |
| Path Traversal | บล็อค URL ที่มี ../ เพื่อป้องกันการเข้าถึง File System |
| File Upload Attack | ตรวจสอบประเภทไฟล์และบล็อคไฟล์อันตราย |
ประเภทของ WAF
1. Cloud-based WAF
WAF ที่เป็นบริการบนคลาวด์ เชื่อมต่อง่าย ไม่ต้องติดตั้งซอฟต์แวร์เพิ่มเติม:
- Cloudflare WAF: ดูแล Rule อัตโนมัติ มีประสิทธิภาพสูง รองรับ OWASP Top 10
- AWS WAF: เหมาะสำหรับระบบบน AWS เชื่อมต่อกับ CloudFront, ALB
- Azure Front Door WAF: สำหรับสภาพแวดล้อม Azure
2. Self-hosted WAF
ติดตั้งเองบน Server ของตน ให้ควบคุมได้เต็มที่:
- ModSecurity: WAF Open Source ที่นิยมใช้กับ Nginx/Apache
- NAXSI: WAF สำหรับ Nginx เพิ่มเติม
- Coraza WAF: Modern WAF ที่เขียนด้วย Go, รองรับ OWASP CRS
การติดตั้ง ModSecurity บน Nginx
# ติดตั้ง ModSecurity
sudo apt install libmodsecurity3 libmodsecurity-dev
# ติดตั้ง OWASP Core Rule Set (CRS)
cd /etc/nginx
git clone https://github.com/coreruleset/coreruleset.git
cd coreruleset
cp crs-setup.conf.example crs-setup.conf
# คอนฟิก Nginx (ใน nginx.conf)
modsecurity on;
modsecurity_rules_file /etc/nginx/coreruleset/crs-setup.conf;
modsecurity_rules_file /etc/nginx/coreruleset/rules/*.conf;
Cloudflare WAF: Custom Rules ตัวอย่าง
# ตัวอย่าง Rule บล็อค SQL Injection
(คำสั่ง WAF - ตั้งใน Cloudflare Dashboard)
# Block SQL Injection
Expression: (http.request.uri.query contains "union select" or
http.request.uri.query contains "1=1" or
http.request.body contains "drop table")
Action: Block
# Block XSS Attempts
Expression: (http.request.uri.query contains "
