Deploy a web application behind AWS WAF and demonstrate:
- Allowing normal traffic
- Blocking malicious IP addresses
- Blocking SQL Injection attacks
- Blocking XSS attacks
- Viewing WAF logs and metrics
AWS WAF (Web Application Firewall) protects web applications from common web exploits and malicious traffic.
Instead of protecting servers directly like a network firewall, WAF protects HTTP/HTTPS requests reaching applications.
Common threats:
- SQL Injection (SQLi)
- Cross Site Scripting (XSS)
- Bot Traffic
- Vulnerability Scanners
- DDoS Layer 7 Attacks
- Bad IP Addresses
- Geographic Restrictions
AWS WAF sits in front of:
- Application Load Balancer (ALB)
- CloudFront
- API Gateway
- App Runner
- Cognito
User
|
v
AWS WAF
|
|---- Check Rules
|
|---- Allow
|---- Block
|---- Count
|
v
Application Load Balancer
|
v
EC2 Application
Every HTTP request is inspected before reaching the application.
Internet
|
v
+-------------------+
| AWS WAF |
+-------------------+
|
v
+-------------------+
| ALB |
+-------------------+
|
v
+-------------------+
| EC2 Web Server |
| NGINX/Apache |
+-------------------+
Services Used:
- VPC
- EC2
- Security Group
- Application Load Balancer
- AWS WAF
- CloudWatch
Launch:
- Amazon Linux 2023
- t2.micro
- Allow HTTP (80)
Install nginx:
sudo dnf install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginxCreate custom page:
echo "AWS WAF Demo" | sudo tee /usr/share/nginx/html/index.htmlCreate:
Listener:
HTTP : 80
Target Group:
EC2 Instance
Verify:
http://ALB-DNS-NAME
returns:
AWS WAF Demo
Navigate:
AWS WAF
→ Web ACL
→ Create Web ACL
Resource:
Application Load Balancer
Associate:
Your ALB
AWS provides ready-made rules.
Add:
Protects against:
- SQL Injection
- XSS
- Command Injection
- Path Traversal
Rule Group:
AWS Managed Rules
→ Core Rule Set
Normal request:
http://alb-dns/
Works.
Now try:
http://alb-dns/?id=' OR 1=1 --
WAF should block.
Response:
403 Forbidden
Try:
http://alb-dns/?search=<script>alert(1)</script>
Expected:
403 Forbidden
Create custom rule.
Block:
203.0.113.10
Example rule:
IF Source IP = 203.0.113.10
THEN Block
Any request from that IP receives:
403 Forbidden
Example:
Block Country = China
Traffic from China:
Blocked
Traffic from India:
Allowed
Useful for:
- Region-restricted websites
- Compliance requirements
Protect against bots.
Rule:
More than 100 requests
per 5 minutes
from same IP
Action:
Block
Example:
ab -n 500 -c 50 http://alb-dns/
After threshold:
403 Forbidden
Open:
CloudWatch
Metrics:
- Allowed Requests
- Blocked Requests
- Counted Requests
Example dashboard:
Allowed Requests : 5000
Blocked Requests : 250
SQLi Attempts : 50
XSS Attempts : 20
Protect:
- Net Banking
- Credit Card Portals
- Payment Gateways
Example:
HDFC Bank, ICICI Bank
use WAF in front of internet-facing applications.
Protect:
- Login Pages
- Checkout APIs
- Payment Pages
Example:
Amazon, Flipkart
Protect:
- REST APIs
- Mobile Backend APIs
AWS WAF can be attached directly to:
Amazon API Gateway
Protect:
- Customer portals
- Admin dashboards
- Authentication services
After this lab, students should understand:
- What a Web Application Firewall is.
- Difference between Security Groups and WAF.
- How AWS WAF evaluates requests.
- Managed vs Custom Rules.
- SQL Injection protection.
- XSS protection.
- Rate Limiting.
- IP and Geo Blocking.
- CloudWatch monitoring integration.
- Real-world AWS security architecture.
Why use AWS WAF when Security Groups already exist?
Answer:
Security Groups operate at Layer 3/4 (IP, Port, Protocol).
AWS WAF operates at Layer 7 (HTTP/HTTPS) and can inspect URLs, headers, query strings, cookies, and request payloads to block attacks like SQL Injection and XSS that Security Groups cannot detect.