זיהוי והבנת WAF¶
מהו WAF - Web Application Firewall?¶
חומת אש לאפליקציות רשת (WAF) היא שכבת הגנה שיושבת בין הלקוח לשרת ומנתחת את תעבורת ה-HTTP. בניגוד לחומת אש רגילה שעובדת ברמת רשת (שכבות 3-4), ה-WAF עובד ברמת האפליקציה (שכבה 7) ומבין את תוכן הבקשות.
מנגנוני הגנה של WAF¶
שלושה מנגנונים מרכזיים מרכיבים WAF מודרני:
התאמת דפוסים - Pattern Matching:
המנגנון הבסיסי ביותר. ה-WAF מחזיק מאגר של ביטויים רגולריים (regex) ומחפש התאמה בבקשות נכנסות. לדוגמה, חוקה שמחפשת את המחרוזת UNION SELECT תחסום ניסיונות SQL injection.
זיהוי חריגות - Anomaly Detection:
המערכת בונה פרופיל של תעבורה תקינה ומזהה סטיות. כל חריגה מקבלת ניקוד, וכאשר הניקוד עובר סף מסוים - הבקשה נחסמת. גישה זו מאפשרת זיהוי התקפות חדשות שאין להן signature ידועה.
ניתוח התנהגותי - Behavioral Analysis:
מעקב אחרי דפוסי שימוש לאורך זמן. לדוגמה, משתמש ששולח 100 בקשות בדקה עם פרמטרים שונים - ככל הנראה מריץ סריקה אוטומטית.
סוגי WAF¶
WAF ברמת רשת - Network-based WAF¶
מותקן כהתקן פיזי או וירטואלי ברשת, לפני שרת האפליקציה. מספק ביצועים גבוהים אך יקר ודורש תחזוקת חומרה.
דוגמאות: F5 BIG-IP ASM, Fortinet FortiWeb, Barracuda WAF
WAF ברמת מארח - Host-based WAF¶
מותקן כמודול על שרת האפליקציה עצמו. גמיש יותר והתאמה אישית קלה, אך צורך משאבים מהשרת.
דוגמאות: ModSecurity (מודול של Apache/Nginx), NAXSI (מודול של Nginx)
WAF בענן - Cloud-based WAF¶
שירות ענן שמתפקד כ-reverse proxy. תעבורה עוברת דרך תשתית הספק לפני שמגיעה לשרת. קל לפריסה, מתרחב אוטומטית, אך מוסיף latency.
דוגמאות: Cloudflare WAF, AWS WAF, Akamai Kona Site Defender, Imperva Cloud WAF
ספקי WAF מרכזיים¶
Cloudflare¶
הפופולרי ביותר. פועל כ-CDN ו-reverse proxy. מזהים אותו לפי:
- הheader תגובה: server: cloudflare
- עוגיית __cfduid או cf_clearance
- דף חסימה עם לוגו Cloudflare ו-Ray ID
AWS WAF¶
משולב בשירותי AWS כמו CloudFront ו-ALB. מזהים לפי:
- עוגיית AWSALB או AWSALBCORS
- הheader x-amzn-requestid
- דף שגיאה של AWS
ModSecurity¶
קוד פתוח, הנפוץ ביותר כמודול שרת. מזהים לפי:
- הheader server שמכילה Apache או Nginx
- דפי שגיאה 403 עם הודעת ModSecurity
- הheader X-Mod-Security (אם לא הוסרה)
Akamai Kona Site Defender¶
מזהים לפי:
- הheader server: AkamaiGHost
- דף חסימה עם Reference ID של Akamai
- הheader X-Akamai-Transformed
Imperva / Incapsula¶
מזהים לפי:
- עוגיית visid_incap_ או incap_ses_
- הheader X-CDN: Imperva
- דף חסימה עם הודעת Incapsula
F5 BIG-IP ASM¶
מזהים לפי:
- עוגיית TS ואחריה מחרוזת ארוכה
- עוגיית BIGipServer
- דפי שגיאה ייחודיים של F5
Fortinet FortiWeb¶
מזהים לפי:
- עוגיית FORTIWAFSID
- הheader server: FortiWeb
- דפי חסימה ייחודיים של FortiWeb
זיהוי WAF באופן אוטומטי - wafw00f¶
הכלי wafw00f הוא כלי הסטנדרט לזיהוי WAF. הוא שולח בקשות מיוחדות ומנתח את התגובות.
התקנה ושימוש בסיסי¶
# Installation
pip install wafw00f
# Basic scan
wafw00f https://target.com
# Verbose scan
wafw00f https://target.com -v
# Scan all possible WAFs (not just the first one found)
wafw00f https://target.com -a
# Show list of supported WAFs
wafw00f -l
פלט לדוגמה¶
[*] Checking https://target.com
[+] The site https://target.com is behind Cloudflare (Cloudflare Inc.) WAF.
[~] Number of requests: 6
פלט מפורט:
[*] Checking https://target.com
[+] Generic Detection results:
[-] Response code: 403
[-] Response headers:
server: cloudflare
cf-ray: 7a1b2c3d4e5f6-TLV
[-] Matched WAF: Cloudflare (Cloudflare Inc.)
[-] Detection confidence: 100%
זיהוי ידני של WAF¶
זיהוי דרך headers תגובה - Response Headers¶
# Send a normal request and check headers
curl -I https://target.com
# Send a malicious request and check the difference
curl -I "https://target.com/?id=1' UNION SELECT 1--"
הheaders האופייניות שחושפות WAF:
# Cloudflare
server: cloudflare
cf-ray: 7a1b2c3d4e5f6-TLV
# Akamai
server: AkamaiGHost
X-Akamai-Transformed: 9 - 0
# Imperva
X-CDN: Imperva
# AWS
x-amzn-requestid: a1b2c3d4-e5f6-7890
זיהוי דרך עוגיות - Cookies¶
עוגיות אופייניות:
# Cloudflare
Set-Cookie: __cfduid=d1234567890abcdef; ...
Set-Cookie: cf_clearance=abc123; ...
# AWS ALB
Set-Cookie: AWSALB=xyz789; ...
Set-Cookie: AWSALBCORS=xyz789; ...
# Imperva
Set-Cookie: visid_incap_123456=abc; ...
Set-Cookie: incap_ses_456_123456=def; ...
# F5 BIG-IP
Set-Cookie: BIGipServerpool_web=1234567890.12345.0000; ...
# FortiWeb
Set-Cookie: FORTIWAFSID=abcdef; ...
זיהוי דרך דפי חסימה - Block Pages¶
כל WAF מציג דף חסימה שונה. שליחת בקשה זדונית בכוונה חושפת את ה-WAF:
# Basic XSS request
curl "https://target.com/?q=<script>alert(1)</script>"
# Basic SQLi request
curl "https://target.com/?id=1' OR 1=1--"
# Traversal request
curl "https://target.com/?file=../../../../etc/passwd"
זיהוי מבוסס תזמון - Timing-based Detection¶
import requests
import time
target = "https://target.com"
# Normal request
start = time.time()
r1 = requests.get(f"{target}/?q=hello")
normal_time = time.time() - start
# Malicious request
start = time.time()
r2 = requests.get(f"{target}/?q=<script>alert(1)</script>")
malicious_time = time.time() - start
print(f"Normal request time: {normal_time:.3f}s")
print(f"Malicious request time: {malicious_time:.3f}s")
print(f"Difference: {malicious_time - normal_time:.3f}s")
# A large difference suggests additional WAF processing
if malicious_time > normal_time * 1.5:
print("[!] WAF likely active - longer response time for malicious request")
הבנת מערכות חוקים - Rule Sets¶
ModSecurity Core Rule Set - CRS¶
מערכת החוקים הפתוחה הנפוצה ביותר. מכילה מאות חוקים המחולקים לקטגוריות:
# ModSecurity rule structure
SecRule ARGS "@rx (?i)(union\s+select)" \
"id:942100,\
phase:2,\
deny,\
status:403,\
msg:'SQL Injection Attack Detected',\
severity:'CRITICAL',\
tag:'attack-sqli'"
פירוש החוקה:
- ARGS - בדיקת כל הפרמטרים
- @rx - שימוש ב-regex
- (?i) - case insensitive
- union\s+select - הדפוס המבוקש
- phase:2 - בדיקה אחרי קבלת גוף הבקשה
- deny - חסימת הבקשה
רמות פרנויה - Paranoia Levels¶
ה-CRS תומך ב-4 רמות פרנויה:
רמה 1 (ברירת מחדל):
חוקים בסיסיים עם מינימום false positives. חוסם התקפות ברורות בלבד.
רמה 2:
חוקים נוספים שמזהים טכניקות bypass נפוצות. יותר false positives.
רמה 3:
חוקים אגרסיביים. מתאים לאפליקציות רגישות. הרבה false positives.
רמה 4:
הרמה הגבוהה ביותר. חוסם כמעט כל דבר חשוד. דורש tuning מאסיבי.
# Level 4 - blocks anything unusual
Any use of special characters
Any word that looks like an SQL command
Any HTML tag
איך חוקים מתאימים - Rule Matching¶
# Common operators in ModSecurity
@rx - regular expression
@pm - string search (pattern match)
@contains - simple containment
@eq - equals
@gt - greater than
# Transformations - changes applied before the check
t:lowercase - convert to lowercase
t:urlDecode - URL decode
t:htmlEntityDecode - HTML entity decode
t:removeWhitespace - remove whitespace
t:compressWhitespace - compress whitespace
מצבי WAF - Detection vs Blocking¶
מצב גילוי - Detection Mode¶
ה-WAF מזהה התקפות ומתעד אותן ביומן, אך לא חוסם. שימושי בשלב הטמעה.
מצב חסימה - Blocking Mode¶
ה-WAF חוסם בקשות זדוניות באופן פעיל.
כתוקפים, חשוב לזהות באיזה מצב ה-WAF עובד. במצב גילוי, ההתקפה תעבור אך תתועד ביומן.
סקירת אסטרטגיות bypass¶
לפני שנצלול לטכניקות ספציפיות בשיעורים הבאים, הנה סקירה כללית:
| אסטרטגיה | תיאור | דוגמה |
|---|---|---|
| הencoding | שינוי הייצוג של התווים | %3Cscript%3E |
| זיהום פרמטרים | שליחת פרמטרים כפולים | id=1&id=1 UNION SELECT |
| נורמליזציית Unicode | תווים חלופיים | <script> |
| הbypass ברמת פרוטוקול | הexploit של הבדלי פרסור | Chunked encoding |
| תחביר חלופי | אותה פעולה במילים שונות | SELECT/**/1 |
| מניפולציית מבנה | שינוי מבנה הבקשה | Content-Type mismatch |
דפי חסימה לדוגמה¶
דף חסימה של Cloudflare¶
HTTP/1.1 403 Forbidden
Server: cloudflare
CF-RAY: 7a1b2c3d4e5f6-TLV
<!DOCTYPE html>
<html>
<head><title>Attention Required! | Cloudflare</title></head>
<body>
<h1>Sorry, you have been blocked</h1>
<p>You are unable to access this website.</p>
<p>Ray ID: 7a1b2c3d4e5f6</p>
</body>
</html>
דף חסימה של ModSecurity¶
HTTP/1.1 403 Forbidden
Server: Apache/2.4.41
<!DOCTYPE html>
<html>
<head><title>403 Forbidden</title></head>
<body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
<p>ModSecurity Action: Request denied with status 403</p>
</body>
</html>
דף חסימה של Imperva¶
HTTP/1.1 403 Forbidden
<!DOCTYPE html>
<html>
<head><title>Access Denied</title></head>
<body>
<h1>Request Blocked</h1>
<p>This request was blocked by the security rules.</p>
<p>Incident ID: 12345-67890</p>
<p>Powered by Incapsula</p>
</body>
</html>
נקודת מבט הגנתית - הגדרת WAF נכונה¶
כתוקפים, הבנת הגדרה נכונה עוזרת לנו להבין מה קשה לעקוף:
# Recommended ModSecurity configuration in Nginx
modsecurity on;
modsecurity_rules_file /etc/modsecurity/modsecurity.conf;
# Enable CRS
Include /etc/modsecurity/crs/crs-setup.conf
Include /etc/modsecurity/crs/rules/*.conf
# Recommended settings in modsecurity.conf
SecRuleEngine On
SecRequestBodyAccess On
SecResponseBodyAccess On
# Paranoia level 2 - good balance
SecAction "id:900000,phase:1,pass,t:none,nolog,\
setvar:tx.paranoia_level=2"
# Setting anomaly threshold
SecAction "id:900110,phase:1,pass,t:none,nolog,\
setvar:tx.inbound_anomaly_score_threshold=5"
# Mandatory transformations
SecRule ARGS "@rx .*" "id:1,phase:2,pass,\
t:urlDecode,t:htmlEntityDecode,t:lowercase"
עקרונות חשובים בהגדרת WAF:
1. תמיד לבצע decode לפני בדיקה (URL decode, HTML entity decode)
2. להשתמש ברמת פרנויה מתאימה לאפליקציה
3. לעדכן חוקים באופן שוטף
4. לפקח על יומנים ולזהות false positives
5. לשלב WAF עם הגנות ברמת האפליקציה - WAF הוא שכבה נוספת, לא תחליף
סיכום¶
זיהוי ה-WAF הוא השלב הראשון בכל ניסיון bypass. בשיעורים הבאים נלמד טכניקות ספציפיות לbypass - החל מencoding, דרך זיהום פרמטרים, נורמליזציית Unicode, ועד bypass ברמת פרוטוקול. הבנה עמוקה של איך ה-WAF עובד, אילו חוקים הוא מפעיל ובאיזו רמת פרנויה - היא המפתח לbypass מוצלחת.