十一周二次课 11.28 限定某个目录禁止解析php 11.29 限制user_agent 11.30/11.31 php相关配置

11.28 限定某个目录禁止解析phpphp

假设有一个目录是能够上传图片,可是可能被有心之人上传php上去,由于httpd开放了php模块,因此若是被人上传了木马文件(php类型),httpd就有可能会进行执行,一旦执行,就会让对方得到咱们服务器的root权限,或者是被恶意删除或修改一些参数,致使服务器瘫痪或者是被攻击 静态文件里面没有PHP。html

在/usr/local/apache2.4/conf/extra/httpd-vhosts.conf配置文件下进行设定:shell

[root@localhost 111.com]#   !vi

核心配置文件内容apache

<Directory /data/wwwroot/www.123.com/upload>
        php_admin_flag engine off              #禁止解析php
        <FilesMatch (.*)\.php(.*)>
        Order allow,deny                   #deny禁止访问源代码
        Deny from all
        </FileMatch>
    </Directory>

查看设置是否成功浏览器

[root@localhost 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@localhost 111.com]# /usr/local/apache2.4/bin/apachectl graceful
[root@localhost 111.com]# !curl                            #解析php

在最上面添加内容 输入图片说明服务器

测试:curl

[root@localhost 111.com]#  mkdir upload                        #建立upload目录
[root@localhost 111.com]#  ls
123.php  admin  index.php qq.png   upload
[root@localhost 111.com]#  cp 123.php upload/                #123.php 拷贝到upload目录下
[root@localhost 111.com]# !curl 
curl -x 192.168.168.133:80 'http://111.com/admin.php?' I

curl测试时直接返回了php源代码,并未解析socket

11.29 限制user_agentxss

user_agent能够理解为浏览器标识测试

核心配置文件内容

<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 "123123" 指定user_agent

11.30/11.31 php相关配置

查看php配置文件位置

/usr/local/php/bin/php -i|grep -i "loaded configuration file" 
 date.timezone 
 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 
 error_log, log_errors, display_errors, error_reporting
 open_basedir
 php_admin_value open_basedir "/data/wwwroot/111.com:/tmp/"

常见问题:

设置php_admin_flag engine off后,curl -I访问状态码是200,这是否正确? 输入图片说明

答:解析不解析php,跟状态码是不是200没有关系。 你上面的显示结果表示,php已经没法解析了。

连接:https://www.cnblogs.com/wangshaojun/p/5034616.html

扩展 apache开启压缩 http://ask.apelearn.com/question/5528

apache2.2到2.4配置文件变动 http://ask.apelearn.com/question/7292

apache options参数 http://ask.apelearn.com/question/1051

apache禁止trace或track防止xss http://ask.apelearn.com/question/1045

apache 配置https 支持ssl http://ask.apelearn.com/question/1029

相关文章
相关标签/搜索