跳到主要內容

MooM

導向 Ubuntu 的 Apache2 http://..ip.. 至指定 https://domainname
joe /etc/apache2/sites-available/000-default.conf
[code]
<VirtualHost *:80>...
RewriteEngine on
RewriteRule ^ https://domainname/ [END,NE,R=permanent]
</VirtualHost>[/code]
啟用 ErrorDocument 404 顯示空白頁
編輯 joe /etc/httpd/conf/httpd.conf
[code]
AllowOverride All
[/code]

cd DOCUMENT_ROOT

編輯 joe .htaccess
[code]
ErrorDocument 404 /blank.html
[/code]

新增 touch blank.html

service httpd restart
關閉 /cgi-bin/ 目錄
編輯 joe /etc/httpd/conf/httpd.conf
[code]
#ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
[/code]
service httpd restart
移除 robots.txt 檔案
移除 robots.txt 檔案
移除 robots.txt 檔案
移除 robots.txt 檔案
關閉 httpd TRACE 與 TRACK
編輯 joe /etc/httpd/conf/httpd.conf
[code]
TraceEnable off
[/code]
測試 curl -v -X TRACE https://xxx.xxx.xxx
修正 SSL TLS 1.0, 1.1 問題
[code]
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
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
SSLHonorCipherOrder off
SSLOptions +StrictRequire
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"" vhost_combined
LogFormat "%v %h %l %u %t "%r" %>s %b" vhost_common
[/code]

驗證網址 https://www.ssllabs.com/
用 namp 查詢 Apache 版本。
[code]
nmap -sV hostname.com
[/code]
關於 ZAP 弱掃報告的 Secure Header 問題(2)
依照上一篇「關於 ZAP 弱掃報告的 Secure Header 問題(1)」的設定,網頁必定跑版。
如果修改如下:
[code]
script-src 'self' 'unsafe-inline' 'nonce-xxx'; \
style-src 'self' 'unsafe-inline' 'nonce-xxx'; \
[/code]
加上 'unsafe-inline' 可以解決跑版問題,但是 ZAP 弱掃報告會出現兩條缺失:
[code]
script-src unsafe-inline
style-src unsafe-inline
[/code]
這意思就是不能用 unsafe-inline。
關於 ZAP 弱掃報告的 Secure Header 問題(1)
如果 ZAP 弱掃報告指出一堆關於 Secure Header 的問題,以 Apache+PHP 為例,可以設定如下:
1.編輯 /etc/httpd/conf.d/secure.conf
[code]
header unset X-Powered-By
ServerTokens Prod
ServerSignature Off
Header always append X-Frame-Options "SAMEORIGIN "
Header always append Frame-Options "SAMEORIGIN"
Header always append STRICT-TRANSPORT-SECURITY "max-age=16070400; includeSubDomains"
Header always append X-XSS-Protection "1;mode=block"
Header always append X-Content-Type-Options "nosniff"
Header always append Content-Security-Policy " \
default-src 'self'; \
script-src 'self' 'nonce-xxx'; \
style-src 'self' 'nonce-xxx'; \
img-src 'self'; \
frame-src 'self'; \
frame-ancestors 'self'; \
form-action 'self'; \
"
Header always append Permissions-Policy " \
geolocation=(),microphone=(),camera=(),payment=(),magnetometer=() \
"
Header always append Referrer-Policy "strict-origin-when-cross-origin"
Header always edit Set-Cookie ^(.*)$ "$1;Secure;SameSite=Lax"
[/code]
2.必須停用 404 轉址,以下在 .htaccess 設定的 404 轉址設定不能使用,因為 404 轉址會導致 ZAP 的弱掃報告出現一個屬於「中風險」的「發現隱藏檔案」缺失,這有點不知 ZAP 在想什麼。
[code]
ErrorDocument 404 /Error404.php
[/code]
3.編輯 /etc/php.ini
[code]
expose_php = Off
session.cookie_httponly = 1
session.cookie_samesite = Lax
[/code]
4.編輯 /etc/httpd/conf.d/autoindex.conf
[code]
#Alias /icons/ "/usr/share/httpd/icons/"
[/code]
重新啟動 Apache
[code]
service httpd restart
[/code]
9