久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      PHP的一些安全設置(優(yōu)化)

      PHP的一些安全設置(優(yōu)化)

      由于腳本語言和早期版本設計的諸多原因,php項目存在不少安全隱患。從配置選項來看,可以做如下的優(yōu)化。

      1.屏蔽PHP錯誤輸出。

      在/etc/php.ini(默認配置文件位置),將如下配置值改為Off

      display_errors=Off

      不要將錯誤堆棧信息直接輸出到網(wǎng)頁上,防止黑客加以利用相關信息。

      正確的做法是:

      把錯誤日志寫到日志文件中,方便排查問題。

      2.屏蔽PHP版本。

      默認情況下PHP版本會被顯示在返回頭里,如:

      Response Headers X-powered-by: PHP/7.2.0

      將php.ini中如下的配置值改為Off

      expose_php=Off

      3.關閉全局變量。

      如果開啟全局變量會使一些表單提交的數(shù)據(jù)被自動注冊為全局變量。代碼如下:

      <form action="/login" method="post"> <input name="username" type="text"> <input name="password" type="password"> <input type="submit" value="submit" name="submit"> </form>

      如果開啟了全局變量,則服務器端PHP腳本可以用$username和$password來獲取到用戶名和密碼,這會造成極大的腳本注入危險。

      開啟方法是在php.ini中修改如下:

      register_globals=On

      建議關閉,參數(shù)如下:

      register_globals=Off

      當關閉后,就只能從$_POST、$_GET、$_REQUEST里面獲取相關參數(shù)。

      4.文件系統(tǒng)限制

      可以通過open_basedir來限制PHP可以訪問的系統(tǒng)目錄。

      如果不限制使用下面的腳本代碼(hack.php)可以獲取到系統(tǒng)密碼。

      <?php echo file_get_contents('/etc/passwd');

      當設置了后則會報錯,不再顯示相關信息,讓系統(tǒng)目錄b不會被非法訪問:

      PHP Warning: file_get_contents(): open_basedir restriction in effect. File(/etc/passwd) is not within the allowed path(s): (/var/www) in /var/www/hack.php on line 3 Warning: file_get_contents(): open_basedir restriction in effect. File(/etc/passwd) is not within the allowed path(s): (/var/www) in /var/www/hack.php on line 3 PHP Warning: file_get_contents(/etc/passwd): failed to open stream: Operation not permitted in /var/www/hack.php on line 3 Warning: file_get_contents(/etc/passwd): failed to open stream: Operation not permitted in /var/www/hack.php on line 3

      設置方法如下:

      open_basedir=/var/www

      5.禁止遠程資源訪問。

      allow_url_fopen=Off allow_url_include=Off

      其他第三方安全擴展

      6.Suhosin。

      Suhosin是一個PHP程序的保護系統(tǒng)。它的設計初衷是為了保護服務器和用戶,抵御PHP程序和PHP核心中已知或者未知的缺陷(感覺挺實用的,可以抵御一些小攻擊)。Suhosin有兩個獨立的部分,使用時可以分開使用或者聯(lián)合使用。

      第一部分是一個用于PHP核心的補丁,它能抵御緩沖區(qū)溢出或者格式化串的弱點(這個必須的?。?;

      第二部分是一個強大的 PHP擴展(擴展模式挺好的,安裝方便…),包含其他所有的保護措施。

      安裝擴展

      wget http://download.suhosin.org/suhosin-0.9.37.1.tar.gz tar zxvf suhosin-0.9.37.1.tar.gz cd suhosin-0.9.37.1/ phpize ./configure  --with-php-config=/usr/local/bin/php-config make make install 在php.ini下加入suhosin.so即可 extension=suhosin.so

      特性

      ● 模擬器保護模式

      ● 增加兩個函數(shù)sha256()和sha256_file()到PHP核心中

      ● 所有平臺,加入CRYPT_BLOWFISH到函數(shù)crypt()中

      ● 打開對phpinfo()頁的透明保護

      ● SQL數(shù)據(jù)庫用戶保護(測試階段)

      運行時保護

      ● 加密cookies

      ● 防止不同種類的包含漏洞(不允許遠程URL包含(黑/白名單);不允許包含已上傳的文件;防止目錄穿越攻擊)

      ● 允許禁止preg_replace()

      ● 允許禁止eval()函數(shù)

      ● 通過配置一個最大執(zhí)行深度,來防止無窮遞歸

      ● 支持每個vhost配置黑白名單

      ● 為代碼執(zhí)行提供分離的函數(shù)黑白名單

      ● 防止HTTP響應拆分漏洞

      ● 防止腳本控制memory_limit選項

      ● 保護PHP的superglobals,如函數(shù)extract(),import_request_vars()

      ● 防止mail()函數(shù)的新行攻擊

      ● 防止preg_replace()的攻擊

      Session 保護

      ● 加密session數(shù)據(jù)

      ● 防止session被劫持

      ● 防止超長的session id

      ● 防止惡意的session id

      SESSION里的數(shù)據(jù)通常在服務器上的明文存放的。這里通過在服務端來加解密$_SESSION。這樣將Session的句柄存放在Memcache或數(shù)據(jù)庫時,就不會被輕易攻破,很多時候我們的session數(shù)據(jù)會存放一些敏感字段。

      這個特性在缺省情況下是啟用的,也可以通過php.ini來修改:

      suhosin.session.encrypt = On suhosin.session.cryptkey = zuHywawAthLavJohyRilvyecyondOdjo suhosin.session.cryptua = On suhosin.session.cryptdocroot = On ;; IPv4 only suhosin.session.cryptraddr = 0 suhosin.session.checkraddr = 0

      Cookie加密

      Cookie在客戶端瀏覽器的傳輸?shù)腍TTP頭也是明文的。通過加密cookie,您可以保護您的應用程序對眾多的攻擊,如

      Cookie篡改:攻擊者可能會嘗試猜測其他合理的cookie值來攻擊程序。

      跨應用程序使用Cookie:不正確配置的應用程序可能具有相同的會話存儲,如所有會話默認存儲在/tmp目錄下,一個應用程序的cookie可能永遠不會被重新用于另一應用,只要加密密鑰不同。

      Cookie加密在php.ini中的配置:

      suhosin.cookie.encrypt = On ;; the cryptkey should be generated, e.g. with 'apg -m 32' suhosin.cookie.cryptkey = oykBicmyitApmireipsacsumhylWaps1 suhosin.cookie.cryptua = On suhosin.cookie.cryptdocroot = On ;; whitelist/blacklist (use only one) ;suhosin.cookie.cryptlist = WALLET,IDEAS suhosin.cookie.plainlist = LANGUAGE ;; IPv4 only suhosin.cookie.cryptraddr = 0 suhosin.cookie.checkraddr = 0 Blocking Functions 測試 ##默認PHP的Session保存在tmp路徑下 ll  -rt /tmp | grep sess ##擴展未開啟時查看某條sesson的數(shù)據(jù) cat  sess_ururh83qvkkhv0n51lg17r4aj6 //記錄是明文的 ##擴展開啟后查看某條sesson 的數(shù)據(jù) cat  sess_ukkiiiheedupem8k4hheo0b0v4 //記錄是密文的 可見加密對安全的重要性

      阻斷功能

      白名單

      ##顯式指定指定白名單列表 suhosin.executor.func.whitelist = htmlentities,htmlspecialchars,base64_encode suhosin.executor.eval.whitelist = htmlentities,htmlspecialchars,base64_encode <?php echo htmlentities('<test>'); eval('echo htmlentities("<test>");');

      黑名單

      ##顯式指定指定黑名單列表 suhosin.executor.func.blacklist = assert,unserialize,exec,popen,proc_open,passthru,shell_exec,system,hail,parse_str,mt_srand suhosin.executor.eval.whitelist = assert,unserialize,exec,popen,proc_open,passthru,shell_exec,system,hail,parse_str,mt_srand 通過日志來查看非法調(diào)用黑白名單 suhosin.simulation = 1 suhosin.log.file = 511 suhosin.log.file.name = /tmp/suhosin-alert.log

      其他配置項

      suhosin.executor.include.max_traversal    擴目錄的最大深度,可以屏蔽切換到非法路徑 suhosin.executor.include.whitelist        允許包含的URL,用逗號分隔 suhosin.executor.include.blacklist        禁止包含的URL,用逗號分隔 suhosin.executor.disable_eval = On        禁用eval函數(shù) suhosin.upload.max_uploads suhosin.upload.disallow_elf suhosin.upload.disallow_binary suhosin.upload.remove_binary suhosin.upload.verification_script        上傳文件檢查腳本,可以來檢測上傳的內(nèi)容是否包含webshell特征

      使用Suhosin,你可以得到一些錯誤日志,你能把這些日志放到系統(tǒng)日志中,也可以同時寫到其他任意的日志文件中去;

      它還可以為每一個虛擬主機創(chuàng)建黑名單和白名單;

      可以過濾GET和POST請求、文件上載和cookie;

      你還能傳送加密的會話和cookie,可以設置不能傳送的存儲上線等等;

      它不像原始的PHP強化補丁,Suhosin是可以被像Zend Optimizer這樣的第三方擴展軟件所兼容的。

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號