[Centos7] 解決資安的幾個問題

URL Link //n.sfs.tw/14944

2021-02-23 13:56:33 By 張○○

因為資安的關係,接到了一些弱點掃描出現的問題,解決方法做個整理。

弱點名稱

1. The web server is sending the X-Powered-By: response headers, revealing the PHP version.

發生原因:php送出 X-Powered-By的標頭中顯示php的版本

解決方法:

修改php.ini [1]

expose_php = Off

2. TRACE method is enabled

發生原因:http協定TRACE方法有效

解決方法:關掉他

修改 httpd.conf 加入一行

TraceEnable off

3. Clickjacking: X-Frame-Options header missing [2]

發生原因:沒有避免點擊劫持(Clickjacking)的設定

解決方法:

修改 httpd.conf 加入一行

Header always set X-Frame-Options "SAMEORIGIN"

4. Apache mod_negotiation filename bruteforcing

發生原因:使用者若使用不合法的標頭會回傳406錯誤,攻擊者可由暴力方式取得檔名、備份檔等資訊。

解決方法:

修改 httpd.conf 加入一行,例如:

<Directory "/var/www/html">
  Options -Indexes -Multiviews
</Directory>

5. PHP allow_url_fopen enabled

發生原因:允許取得遠端的服務,如http ftp等。allow_url_fopen預設是開啟的。

解決方法:如果用不到可以關閉,貿然關閉的話,file_get_contents 等函數會出錯。

修改php.ini

allow_url_fopen = 'off'

或 .htaccess

php_flag allow_url_fopen off

6. Cross site scripting

報告說明:

URI was set to "onmouseover='nYUc(93652)'bad="
The input is reflected inside a tag parameter between double quotes.

發生原因:跨站攻擊(XSS),基本上只要攻擊者輸入的程式或指令會出現在網頁上的話就算。

解決方法:

  攻擊者在輸入欄位或url網址中會插入JS程式碼,程式應該要進行檢查及字串取代,不應直接顯示在頁面上。

  簡單來說,頁面中有沒有直接把get中的結果放到程式碼中的情形?如果有就會引起此類的攻擊。

7. Git repository found

發生原因:Git 的目錄被發現 (.git)

解決方法:把.git 目錄消失,或是在目錄上層放入以下的 .htaccess

<Directory ~ "\.git">
Order allow,deny
Deny from all
</Directory>

測試方法就是直接用網頁開啟該目錄的檔案,應該要404或是500才正確。

8. Development configuration files

發生原因:被發現和開發有關的檔案,例如Vagrantfile, Gemfile, Rakefile…

解決方法:刪掉

https://example.com/third/bootstrap/Gemfile.lock
https://example.com/third/bootstrap/package.json
https://example.com/third/bootstrap/bower.json
https://example.com/third/bootstrap/.bower.json
https://example.com/third/jquery-animateNumber/package.json
https://example.com/third/jquery-animateNumber/bower.json
https://example.com/third/bootstrap-select/bower.json
https://example.com/third/bootstrap-select/.bower.json
https://example.com/third/chart.js/package.json
https://example.com/third/chart.js/composer.json
https://example.com/third/ckeditor/composer.json
https://example.com/third/jquery-ui/bower.json
https://example.com/third/jquery-ui/.bower.json
https://example.com/third/jquery-ui/composer.json

9. Content Security Policy (CSP) not implemented

發生原因:沒設置CSP

解決方法:掛上去,因為這是info等級的,也不知有多少外部的連結,沒有時間一個個測試,所以先不上,有興趣可以參考[3]

參考[3] Content Security Policy是寫給瀏覽器看的
他寫在從伺服端回應給使用者瀏覽器端網頁的HTTP Header裡
主要用來限制網頁中對外部的請求來源(例如:css,js(ajax,ws),webfont,img,video,iframe等等)
還有一部份是禁止HTML行內的JS或CSS運作
以及限制<form>表單的指向網址

過濾XSS語法是伺服器端語言的工作(例如PHP)
如果不幸過濾失敗的話CSP的功能可以阻止惡意語法在瀏覽器端運作
算是多一道擋XSS的防線
(要注意是規則要寫對才能起作用,寫法限制太寬鬆還是會阻止不了)

 

10. SSH SUPPORTS WEAK ALGORITHMS / SSH servers

發生原因:SSH使用弱加密算法

解決方法:參考[4] ,修改SSH配置文件,去掉弱加密算法:

vi /etc/ssh/sshd_config
最後面添加以下內容(去掉arcfour,arcfour128,arcfour256等弱加密算法):

Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc

重啟 ssh

 

 

 

 

目前整理這樣,爾後有再補充。

參考資料

[1] https://blogs.oracle.com/oswald/hide-x-powered-by:-php

[2] https://zh.wikipedia.org/wiki/%E7%82%B9%E5%87%BB%E5%8A%AB%E6%8C%81

[3] https://hackmd.io/@Eotones/BkOX6u5kX

[4] https://60dmx.blogspot.com/2018/09/ssh-weak-algorithms-supported.html