11月20日
11.28 限定某个目录禁止解析php
禁止解析php是为了防止有人上传php,php里面写入一些木马文件,以获取数据。
核心配置文件内容
<Directory /data/wwwroot/www.123.com/upload>
php_admin_flag engine off 禁止解析php
<FilesMatch (.*)\.php(.*)> 所有访问php都403
Order allow,deny
Deny from all 全部deny,不deny会访问源代码
</FilesMatch>
</Directory>
测试
mkdir upload
cp 123.php upload/
Curl -x127.0.0.1:80 ‘http://111.co/upload/123.php’ -I
· curl 测试时直接返回了php源代码,并未解析
11.29 限制user_agent(预防cc攻击)
访问控制—user_agent
· user_agent可以理解为浏览器标识
· 核心配置文件内容
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteEngine %{HTTP_USER_AGENT} .*curl.* [NC,OR] or或者,上一条或者下一条,nc表示忽略大小写
RewriteEngine %{HTTP_USER_AGENT} .*baidu.com.* [NC]
</IfModule>
重新加载配置
curl -x127.0.0.1:80 ‘http://111.com/123.php’ -I 403限制访问
· curl -A “123123” 指定user_agent
· curl -e “http:// 指定referer
· curl -x
· curl -I 查看状态码
11.30/11.31 php相关配置
PHP相关配置
· 查看php配置文件位置
· /usr/local/php/bin/php-i|grep -i “loaded configuration file”
· vim /usr/local/php7/etc/php.ini配置文件的路径
· date.timezone 时区
Date.timezone = Asia/shanghai或chongqing
· disable_functins 安全函数
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,禁用这些安全相关函数
dispaly_errors = off 错误信息不输出到浏览器里,会暴露目录路径
log_errors = on 把错误日志打开
error_log = /tmp/php_errors.log 错误日志存放目录
error_reporting = E_ALL 错误日志级别
· open_basedir = /data/wwwroot/123.com:/tmp/ 安全选项 固定只能在这个目录下操作(针对所以站点)
· vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf 还可以再这个配置文件里配置
php_admin_value open_basedir “/data/wwwroot/123.com:/tmp/”