11.28 限定某個目錄禁止解析phpphp
11.29 限制user_agenthtml
11.30/11.31 php相關配置linux
配置以下shell
#禁止解析php ... <Directory /data/wwwroot/ddd.com/uplode/> php_admin_flag engine off //禁止解析uplode裏的php #<FilesMatch (.*)\.php(.*)> //禁止訪問uplode裏的php #Order allow,deny #Deny from all #</FilesMatch> </Directory> ... bin/apachectl -t bin/apachectl graceful
測試方法以下apache
mkdir /data/wwwroot/ddd.com/uplode/ vim /data/wwwroot/ddd.com/uplode/index.php ... <?php echo "flag engine off"; ?> ... curl -x127.0.0.1:80 ddd.com/uplode/index.php
如圖,curl直接返回了php源代碼,並未解析、vim
ps:瀏覽器訪問默認執行下載..瀏覽器
核心配置文件內容安全
#可針對瀏覽器的特徵拒絕訪問請求,經常使用於防cc攻擊。 #[F]即表示Forbidden <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_USER_AGENT} .*curl.* [NC,OR] RewriteCond %{HTTP_USER_AGENT} .*baidu.com.* [NC] RewriteRule .* - [F] </IfModule>
如圖curl能夠經過-A修改本身的user_agent,繞過限制php7
查看php配置文件路徑 php -icurl
[root@axiang-02 php]# /usr/local/php/bin/php -i|grep -i "loaded configur Loaded Configuration File => /usr/local/php/etc/php.ini PHP Warning: Unknown: It is not safe to rely on the system's timezone sault_timezone_set() function. In case you used any of those methods and identifier. We selected the timezone 'UTC' for now, but please set date.
注意,有可能php -i看到的配置不是當前網站調用的php模塊的,用瀏覽器查看phpinfo是最準確的
[root@axiang-02 ddd.com]# ls admin admin.php aming.png index.php uplode [root@axiang-02 ddd.com]# vi index.php [root@axiang-02 ddd.com]# cat index.php <?php phpinfo(); ?>
瀏覽器查看
能夠看到,實際調用模塊爲php7
若是沒有調用,則須要從源碼包裏複製粘貼配置文件到指定路徑,刷新apache
[root@axiang-02 ddd.com]# cp /usr/local/src/php-7.1.6/php.ini-development /usr/local/php7/etc/php.ini cp:是否覆蓋"/usr/local/php7/etc/php.ini"? yes [root@axiang-02 ddd.com]# /usr/local/apache2.4/bin/apachectl graceful
關閉PHP Warning
[root@axiang-02 php]# vim etc/php.ini
如圖修改date.timezone 便可關閉PHP Warning報警
[root@axiang-02 php]# /usr/local/php/bin/php -i|grep -i "loaded configuration file" Loaded Configuration File => /usr/local/php/etc/php.ini [root@axiang-02 php]#
如圖修改disable_functions,禁用有風險函數
eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close,phpinfo
瀏覽器再次訪問顯示以下圖
這裏顯示目錄仍是不安全
這時就須要修改錯誤日誌了,有如下幾個點要改
log_errors = On 錯誤日誌開啓 error_log = /tmp/php_errors.log 定義日誌路徑 display_errors = Off 不把錯誤輸出到瀏覽器裏 error_reporting = E_ALL //這是全紀錄 定義錯誤級別,Notic通常不用記錄,上面有修改格式
測試
curl -x172.0.0.1:80 ddd.com -A "a" -I touch /tmp/php_errors.log ; chmod 777 /tmp/php_errors.log 有時候建立不出來,強制建立又寫不進去日誌,刪掉disable_f下的phpinfo再試試
最終出現須要的錯誤日誌
[root@axiang-02 php7]# cat /tmp/php_errors.log [03-Aug-2017 08:37:19 UTC] PHP Parse error: syntax error, unexpected end of file in /data/wwwroot/ddd.com/1.php on line 3 [03-Aug-2017 08:38:02 UTC] PHP Warning: phpinfo() has been disabled for security reasons in /data/wwwroot/ddd.com/index.php on line 1
設置php.ini文件
open_basedir = /data/wwwroot/ddd.com:/tmp
以上是對全局進行定義
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf ... 加入: php_admin_value open_basedir "/data/wwwroot/xxx.com:/tmp/" ...
apache開啓壓縮 http://www.aminglinux.com/bbs/thread-5528-1-1.html
apache2.2到2.4配置文件變動 http://www.aminglinux.com/bbs/thread-7292-1-1.html
apache options參數 http://www.aminglinux.com/bbs/thread-1051-1-1.html
apache禁止trace或track防止xss http://www.aminglinux.com/bbs/thread-1045-1-1.html
apache 配置https 支持ssl http://www.aminglinux.com/bbs/thread-1029-1-1.html