標籤

bat (57) 作品 (56) python (36) laravel (35) shell (17) windows (16) 教學作品 (15) PDF (11) 虛擬機 (11) Apache2 (10) php (10) 轉檔 (9) Ubuntu (7) CPP (6) KMS (6) 程式設計 (6) DNS (5) docker (5) xoops (5) 使用教學 (5) 資安 (5) 公文 (4) Excel (3) juniper (3) 資料庫 (3) 電腦維修 (3) Centos (2) PE (2) chcweb (2) mysql (2) 免動手 (2) 編輯器 (2) 資料結構 (2) 軟體廣播 (2) Android Studio (1) Apple IPAD管理 (1) Arduino (1) CSS (1) Cookies marked as HttpOnly (1) HSTS (1) Host header attack (1) LAMP (1) Model (1) NAS (1) Permissions-Policy (1) TLS/SSL Weak Cipher Suites (1) VHD (1) Windows Server (1) 原因 (1) 本地端AI (1) 程式應用 (1) 程式積木 (1) 資安稽核 (1) 雲端硬碟 (1)
顯示具有 Host header attack 標籤的文章。 顯示所有文章
顯示具有 Host header attack 標籤的文章。 顯示所有文章

2025年6月19日 星期四

Laravel 網站遇到Host header attack 解決方法及python檢測漏洞方法

1.設定.env的APP_ENV為production
APP_ENV=production

2.問Chat everywhere 的 prompt
host header attack apache 解決方案
host header attack apache 解決方案 https
host header attack apache 解決方案 https://www.example.com.tw
經過上述三段式的prompt,就可得到比較完整

步驟(1).修改/etc/apache2/sites-available/000-default.conf
確保 Apache 僅接受您擁有的域名的請求
<VirtualHost *:80>
    ServerName www.example.com.tw
    ServerAlias example.com.tw

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.example\.com\.tw$ [NC]
    RewriteRule ^ - [F]

<Directory /home/webadmin/html/example/public> Options -Indexes AllowOverride All Require all granted </Directory>

Redirect permanent / https://www.example.com/

</VirtualHost>

步驟(2).修改/etc/apache2/sites-available/default-ssl.conf
<VirtualHost *:443>
    ServerName www.example.com
    ServerAlias example.com

<Directory "/home/webadmin/html/example/public/"> Options -Indexes AllowOverride All Require all granted </Directory>

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteRule ^ - [F]
    
    SSLEngine on
    SSLCertificateFile /path/to/certificate.crt
    SSLCertificateKeyFile /path/to/private.key
    SSLCertificateChainFile /path/to/chainfile.pem
</VirtualHost>

3.問Chat everywhere 的 prompt
給我一個python 檢測 https://www.example.com.tw 的host header attack 漏洞
安裝套件:
pip install requests

檢測程式:
import requests

# 目標 URL
url = "https://www.example.com.tw"

# 攻擊的 Host 標頭
malicious_host = "malicious.com"

# 自定義請求頭
headers = {
    "Host": malicious_host
}

try:
    # 發送請求
    response = requests.get(url, headers=headers)

    # 檢查響應
    if response.status_code == 200:
        print(f"可能存在 Host Header Attack 漏洞,響應內容:\n{response.text}")
    else:
        print(f"響應碼:{response.status_code},未檢測到漏洞。")
except requests.exceptions.RequestException as e:
    print(f"請求出錯:{e}")

測試結果:
資料來源:

只要點兩下就能將 彰化縣EIP系統全校學生帳號總表 依 各班級 分成 各班級學生帳號總表

系列文章: 1. 只要點兩下就能產出彰化縣Cloud School 學生帳號密碼匯入彰化縣EIP系統學生帳號密碼的CSV 1. https://skjhcreator.blogspot.com/2025/08/cloud-school-eipcsv.html 2. 只要點兩下就能...