久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放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. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

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

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

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

      1.屏蔽PHP錯(cuò)誤輸出。

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

      display_errors=Off

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

      正確的做法是:

      把錯(cuò)誤日志寫到日志文件中,方便排查問(wèn)題。

      2.屏蔽PHP版本。

      默認(rèn)情況下PHP版本會(huì)被顯示在返回頭里,如:

      Response Headers X-powered-by: PHP/7.2.0

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

      expose_php=Off

      3.關(guān)閉全局變量。

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

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

      如果開啟了全局變量,則服務(wù)器端PHP腳本可以用$username和$password來(lái)獲取到用戶名和密碼,這會(huì)造成極大的腳本注入危險(xiǎn)。

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

      register_globals=On

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

      register_globals=Off

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

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

      可以通過(guò)open_basedir來(lái)限制PHP可以訪問(wèn)的系統(tǒng)目錄。

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

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

      當(dāng)設(shè)置了后則會(huì)報(bào)錯(cuò),不再顯示相關(guān)信息,讓系統(tǒng)目錄b不會(huì)被非法訪問(wèn):

      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

      設(shè)置方法如下:

      open_basedir=/var/www

      5.禁止遠(yuǎn)程資源訪問(wèn)。

      allow_url_fopen=Off allow_url_include=Off

      其他第三方安全擴(kuò)展

      6.Suhosin。

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

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

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

      安裝擴(kuò)展

      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

      特性

      ● 模擬器保護(hù)模式

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

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

      ● 打開對(duì)phpinfo()頁(yè)的透明保護(hù)

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

      運(yùn)行時(shí)保護(hù)

      ● 加密cookies

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

      ● 允許禁止preg_replace()

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

      ● 通過(guò)配置一個(gè)最大執(zhí)行深度,來(lái)防止無(wú)窮遞歸

      ● 支持每個(gè)vhost配置黑白名單

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

      ● 防止HTTP響應(yīng)拆分漏洞

      ● 防止腳本控制memory_limit選項(xiàng)

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

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

      ● 防止preg_replace()的攻擊

      Session 保護(hù)

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

      ● 防止session被劫持

      ● 防止超長(zhǎng)的session id

      ● 防止惡意的session id

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

      這個(gè)特性在缺省情況下是啟用的,也可以通過(guò)php.ini來(lái)修改:

      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頭也是明文的。通過(guò)加密cookie,您可以保護(hù)您的應(yīng)用程序?qū)Ρ姸嗟墓?,?/p>

      Cookie篡改:攻擊者可能會(huì)嘗試猜測(cè)其他合理的cookie值來(lái)攻擊程序。

      跨應(yīng)用程序使用Cookie:不正確配置的應(yīng)用程序可能具有相同的會(huì)話存儲(chǔ),如所有會(huì)話默認(rèn)存儲(chǔ)在/tmp目錄下,一個(gè)應(yīng)用程序的cookie可能永遠(yuǎn)不會(huì)被重新用于另一應(yīng)用,只要加密密鑰不同。

      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 測(cè)試 ##默認(rèn)PHP的Session保存在tmp路徑下 ll  -rt /tmp | grep sess ##擴(kuò)展未開啟時(shí)查看某條sesson的數(shù)據(jù) cat  sess_ururh83qvkkhv0n51lg17r4aj6 //記錄是明文的 ##擴(kuò)展開啟后查看某條sesson 的數(shù)據(jù) cat  sess_ukkiiiheedupem8k4hheo0b0v4 //記錄是密文的 可見加密對(duì)安全的重要性

      阻斷功能

      白名單

      ##顯式指定指定白名單列表 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 通過(guò)日志來(lái)查看非法調(diào)用黑白名單 suhosin.simulation = 1 suhosin.log.file = 511 suhosin.log.file.name = /tmp/suhosin-alert.log

      其他配置項(xiàng)

      suhosin.executor.include.max_traversal    擴(kuò)目錄的最大深度,可以屏蔽切換到非法路徑 suhosin.executor.include.whitelist        允許包含的URL,用逗號(hào)分隔 suhosin.executor.include.blacklist        禁止包含的URL,用逗號(hào)分隔 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        上傳文件檢查腳本,可以來(lái)檢測(cè)上傳的內(nèi)容是否包含webshell特征

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

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

      可以過(guò)濾GET和POST請(qǐng)求、文件上載和cookie;

      你還能傳送加密的會(huì)話和cookie,可以設(shè)置不能傳送的存儲(chǔ)上線等等;

      它不像原始的PHP強(qiáng)化補(bǔ)丁,Suhosin是可以被像Zend Optimizer這樣的第三方擴(kuò)展軟件所兼容的。

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