Apache PHP基本安全設定

Apache Security

修補已知Apache漏洞

已知Apache漏洞
http://www.cvedetails.com/vendor/45/Apache.html
http://sebug.net/appdir/Apache

 

建議值:ServerSignature Off

隱藏Apache的版本號及其它敏感資訊
ServerSignature會出現在Apache所產生的頁面 ex:404頁面、目錄清單頁面的底部

 

建議值:ServerTokens Prod

ServerTokens用來判斷Apache在Server HTTP回應包header填充什麼資訊
若把ServerTokens設為Prod,則HTTP回應header就會被設置為:Server:Apache

 

建議值:User和Group apache

User apache Group apache 以Apache的身份執行apache web server

 

建議值:TraceEnable off

關閉HTTP METHOD中的TRACE方法

 

建議值

< Directory />
    Options None
    AllowOverride None
     < LimitExcept GET POST>
  	deny from all
     < /LimitExcept>
< /Directory>

預設關閉所有功能, 並只限制GET和POST使用
ps
其他設定Directory下的option如下
關閉瀏覽目錄 ex:Options -Indexes
關閉includes ex:Options -Includes
關閉CGI執行程式 ex:Options -ExecCGI
禁止Apache遵循符號連結 ex: Options -FollowSymLinks

 

關閉任何不必要的模組

常見的無用模組如下
mod_imap, mod_include, mod_info, mod_userdir, mod_status, mod_cgi, mod_autoindex

 

refer
http://superuser.com/questions/306057/bare-minimum-apache-modules-needed-for-static-website-and-no-authn
http://www.tecmint.com/apache-security-tips/

 


PHP security

調整php.ini的設定提升安全

register_globals = off
關閉全域變數

allow_url_fopen = off
關閉以url讀取php或其他檔案

ex:  
$fp = fopen("http://127.0.0.1/test.php", "rt");  // support in allow_url_include = On  
$fp = fopen("test.php", "rt");  

allow_url_include = Off
關閉以url方式引入php或其他檔案

ex:  
include(“ http://127.0.0.1/test.php”); // support in allow_url_include = On  
include(“ test.php”);  

display_errors = off
關閉錯誤訊息顯示
ps:
如需debug,建議使用log_errors = On和error_log = filename
將錯誤訊息記錄到指定的檔案

expose_php = Off
不讓伺服器流出版本資訊

open_basedir =web目錄
盡量將網站的起路徑限制在web的路徑,並免駭客去引用web路徑以外的檔案。

disable_functions=
使用disable_functions關閉沒在用的funciton
對外的Web建議要把可以執行系統指令的functions拿掉

ex
disable_functions= passthru,exec,shell_exec,system

ex:
disable_functions  = system,exec,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exe,c,popen,dl,set_time_limit

ex:
disable_functions = passthru,exec,shell_exec,system,fopen,mkdir,rmdir,chmod,unlink,dir,fopen,fread,fclose,fwrite,file_exists,closedir,is_dir,readdir.opendir,fileperms.copy,unlink,delfile

 

refer
http://php.net/manual/en/security.intro.php
http://www.cyberciti.biz/tips/php-security-best-practices-tutorial.html