顯示具有 資安 標籤的文章。 顯示所有文章
顯示具有 資安 標籤的文章。 顯示所有文章

2025年6月24日 星期二

Ubuntu 24.04 的 Apache2 設定 Permissions-Policy




1.Apache2 啟用 mod_headers.so
$sudo a2enmod headers

2.編輯default-ssl.conf,設定#Permissions-Policy
$sudo nano /etc/apache2/sites-available/default-ssl.conf
加入
#Permissions-Policy
Header always set Permissions-Policy "geolocation=(),midi=(),sync-xhr=(),microphone=(),camera=(),magnetometer=(),gyroscope=(),fullscreen=(self),payment=()"

3.重啟 Apache2
$sudo service apache2 restart

資料來源:
2.

Ubuntu 24.04 的 Apache2 設定 Cookies marked as HttpOnly


1.Apache2 啟用 mod_headers.so
$sudo a2enmod headers

2.編輯default-ssl.conf, 設定 HttpOnly;Secure;XSRF
$sudo nano /etc/apache2/sites-available/default-ssl.conf
加入
# HttpOnly;Secure;XSRF
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure;SameSite=strict


3.重啟 Apache2
$sudo service apache2 restart

4.如何檢測是否設定成功
假設該網站為https://www.example.com
$curl -I https://www.example.com

資料來源:

2025年6月19日 星期四

Ubuntu 24.04 的 Apache2 解決 TLS/SSL Weak Cipher Suites

1.apache2 啟用 SSL 模組
$sudo a2enmod ssl

2.使用nmap 檢查本機的漏洞
#掃RDP的3389
$nmap --script ssl-enum-ciphers -p 3389 127.0.0.1

#掃https的443
$nmap --script ssl-enum-ciphers -p 443 127.0.0.1

3.編輯 /etc/apache2/sites-available/default-ssl.conf
$sudo nano  /etc/apache2/sites-available/default-ssl.conf
將下面寫入

# 伺服器使用自己定義的 Cipher 排序(不要讓 client 決定)
SSLHonorCipherOrder on

# 停用 SSL 壓縮(防止 CRIME 攻擊)
SSLCompression off

# 安全 Cipher 套件組合
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305

SSLSessionTickets off

 SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1

 # Security headers
 ## X-Content-Type-Options
 Header set X-Content-Type-Options "nosniff"
    
 ## Content-Security-Policy
 Header set Content-Security-Policy "frame-ancestors 'self';"
    
 ## Strict Transport Security (HSTS)
 Header set Strict-Transport-Security "max-age=31536000; includeSubdomains; preload"


4.檢查設定語法是否正確
$sudo apache2ctl configtest

Ubuntu 24.04 的 Apache2 設定 HTTP Strict Transport Security(HSTS)與檢測方法

1.啟用 apache headers 模組 
$sudo a2enmod headers

2.重新啟動 apache 
$sudo service apache2 restart

3.編輯 /etc/apache2/conf-available/security.conf ,加上 header 設定
$sudo nano /etc/apache2/conf-available/security.conf

    Header always set Strict-Transport-Security "max-age=31536000;includeSubdomains; preload"
步驟3.的方式會將整個設定複雜化,可以直接將
Header always set Strict-Transport-Security "max-age=31536000;includeSubdomains; preload"
寫入到/etc/apache2/sites-available/default-ssl.conf 。這樣設定會比較單純。所以
3.1 編輯 /etc/apache2/sites-available/default-ssl.conf

Header always set Strict-Transport-Security "max-age=31536000;includeSubdomains; preload"


4.重新載入設定 
$sudo service apache2 reload

5.檢測https://www.example.com.tw指令:
$curl -s -D - https://www.example.com.tw -o /dev/null

資料來源:



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}")

測試結果:
資料來源:

只要點兩下,就能將input資料夾內所有m4a 轉檔為 mp3

         最近需要將m4a檔案轉檔為mp3,所以寫python程式來處理。希望將很多的m4a放進input資料夾內,只要點兩下滑鼠就能將這些m4a 通通轉檔為 mp3。          Recently, I needed to convert M4A files in...