Host Header Injection

Host Header Injection, bir web uygulamasının, gelen HTTP isteğindeki Host header'ını doğrulamadan kullanması sonucu oluşan bir güvenlik zafiyetidir. Saldırgan, bu header'ı manipüle ederek şifre sıfırlama bağlantıları, cache poisoning, XSS ve hatta backend sistemlere erişim gibi çeşitli saldırılar gerçekleştirebilir.

Host Header Nasıl Çalışır?
Host header'ı, HTTP/1.1'den beri zorunludur ve aynı IP adresinde birden fazla domain barındıran sunucularda hangi domain'e istek yapıldığını belirtir.

Örnek İstek:

http
GET /reset-password HTTP/1.1
Host: hedef.com
User-Agent: Mozilla/5.0
Uygulama, şifre sıfırlama bağlantısını oluştururken Host header'ını kullanıyorsa:

text
Saldırgan Host header'ını değiştirir:

http
GET /reset-password HTTP/1.1
Host: saldırgan.com
Uygulama bağlantıyı şu şekilde oluşturur:

text
Kullanıcı, bu bağlantıya tıkladığında saldırganın sitesine yönlendirilir ve token çalınır.

Host Header Injection Türleri:
1. Password Reset Poisoning
Şifre sıfırlama bağlantılarının zehirlenmesi.

Örnek:

http
POST /reset-password HTTP/1.1
Host: saldırgan.com
Content-Type: application/json

{
"email": "[email protected]"
}
Kullanıcıya gönderilen link: https://saldirgan.com/reset?token=xyz

2. Cache Poisoning
Önbelleğin zehirlenmesi.

Örnek:

http
GET /main.js HTTP/1.1
Host: saldırgan.com
Önbelleğe, saldırganın kontrol ettiği içerik eklenir.

3. Virtual Host Misconfiguration
Aynı IP'de barındırılan diğer sanal host'lara erişim.

Örnek:

http
GET /admin HTTP/1.1
Host: internal-admin.hedef.com
Internal domain'e erişim sağlanabilir.

4. XSS via Host Header
Host header'ı doğrudan sayfada yansıtılıyorsa XSS.

Örnek:

http
GET / HTTP/1.1
Host: <script>alert(1)</script>
5. Routing Manipülasyonu
Backend'de yanlış yönlendirmeye neden olma.

Host Header Injection Nasıl Bulunur? (Test Teknikleri)
A. Manuel Keşif Teknikleri:
Temel Host Manipülasyonu:

http
Host: evil.com
Host: subdomain.hedef.com
Host: hedef.com.evil.com
Host: [email protected]
Host: hedef.com:8080
Port Manipülasyonu:

http
Host: hedef.com:443
Host: hedef.com:8080
Host: hedef.com:65535
Localhost Testi:

http
Host: localhost
Host: 127.0.0.1
Host: 0.0.0.0
Internal IP Testi:

http
Host: 192.168.1.1
Host: 10.0.0.1
Host: 172.16.0.1
XSS Testi:

http
Host: <script>alert(1)</script>
Host: "><script>alert(1)</script>
Host: javascript:alert(1)
Header Injection:

http
Host: hedef.com%0d%0aX-Forwarded-For: 127.0.0.1
Host: hedef.com%0d%0aSet-Cookie: admin=true
Duplicate Host Header:

http
Host: hedef.com
Host: evil.com
B. Otomatik Test Araçları:
Burp Suite: Host header manipülasyonu testi.

HostHeader-Injection: Özel payload listeleri.

Nuclei: Host header template'leri.

ffuf: Host header fuzzing.

Koruma Teknikleri (Güvenli Geliştirme):
1. Host Header Validasyonu
Sadece güvenilir domain'lere izin verin.

python
def validate_host(host_header):
ALLOWED_HOSTS = [
'hedef.com',
'www.hedef.com',
'api.hedef.com'
]

# Port'u temizle
host = host_header.split(':')[0]

# Domain kontrolü
if host not in ALLOWED_HOSTS:
return False

# Localhost ve internal IP engeli
if host in ['localhost', '127.0.0.1', '0.0.0.0']:
return False

# IP adresi kontrolü (sadece domain)
import re
if re.match(r'^\d+\.\d+\.\d+\.\d+$', host):
return False

return True
2. Absolute URL Kullanımı
Bağlantı oluştururken dinamik Host header kullanmayın.

YANLIŞ:

python
reset_link = f"https://{request.headers['Host']}/reset?token={token}"
DOĞRU:

python
# Sabit domain kullan
reset_link = f"https://hedef.com/reset?token={token}"

# Veya yapılandırma dosyasından al
reset_link = f"{config.BASE_URL}/reset?token={token}"
3. Framework'ün Güvenli Fonksiyonları
Django: ALLOWED_HOSTS ayarı.

Flask: SERVER_NAME yapılandırması.

Spring: HostnameVerifier ile validasyon.

Django Örneği:

python
# settings.py
ALLOWED_HOSTS = ['hedef.com', 'www.hedef.com']
Flask Örneği:

python
from flask import Flask
app = Flask(__name__)
app.config['SERVER_NAME'] = 'hedef.com'
4. Nginx Yapılandırması
nginx
server {
listen 80;
server_name hedef.com www.hedef.com;

# Geçersiz Host header'larını engelle
if ($host !~* ^(hedef\.com|www\.hedef\.com)$) {
return 444;
}

# Host header'ını normalize et
proxy_set_header Host $host;
proxy_pass http://backend;
}
5. Apache Yapılandırması
apache
<VirtualHost *:80>
ServerName hedef.com
ServerAlias www.hedef.com

# Geçersiz Host header'larını engelle
RewriteEngine On
RewriteCond %{HTTP_HOST} !^hedef\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\.hedef\.com$ [NC]
RewriteRule ^ - [F]
</VirtualHost>
6. WAF Kullanımı
Host header'daki anormal pattern'leri tespit edin.

XSS ve injection payload'larını engelleyin.

7. Log ve İzleme
Anormal Host header'larını loglayın.

Farklı domain'lere yapılan istekleri izleyin.

Host Header Injection Kontrol Listesi:
A. Validasyon:
Host header'ı doğrulanıyor mu?

Beyaz liste kullanılıyor mu?

Port kısmı temizleniyor mu?

Localhost ve internal IP'ler engelleniyor mu?

B. Link Oluşturma:
Absolute URL kullanılıyor mu?

Dinamik Host header kullanılmıyor mu?

Güvenli framework fonksiyonları kullanılıyor mu?

C. Sunucu Yapılandırması:
Nginx/Apache doğru yapılandırılmış mı?

Geçersiz Host header'ları engelleniyor mu?

SSL/TLS yapılandırması doğru mu?

Özel Senaryolar:
1. CDN ve Proxy Kullanımı
Cloudflare, Akamai gibi CDN'ler Host header'ını değiştirebilir.

X-Forwarded-Host veya X-Original-Host header'larını kullanın.

python
def get_safe_host(request):
# CDN proxy'leri için
if 'X-Forwarded-Host' in request.headers:
host = request.headers['X-Forwarded-Host']
elif 'X-Original-Host' in request.headers:
host = request.headers['X-Original-Host']
else:
host = request.headers.get('Host', '')

return validate_host(host)
2. Load Balancer Senaryoları
Load balancer'ın gönderdiği header'ları kullanın.

X-Forwarded-Host ve X-Forwarded-Proto header'larını doğrulayın.

3. Multi-Tenant Uygulamalar
Her tenant'ın domain'ini ayrı ayrı doğrulayın.

Dinamik domain validasyonu yapın.

python
def validate_tenant_host(host):
# Veritabanından tenant domain'lerini kontrol et
tenant = Tenant.objects.filter(domain=host).first()
if not tenant:
return False
return True

🔒 Bu içeriği görmek için giriş yapın

 
Yanıt yazmak için giriş yapmalısınız
Forum özelliklerini kullanmak ve Level 2 üyelik satın almak için hesabınıza giriş yapın.
133,675Konular
3,288,638Mesajlar
324,376Kullanıcılar
alexsandresSon Üye
Üst Alt