{{ v.name }}
{{ v.cls }}类
{{ v.price }} ¥{{ v.price }}
[root@hf-01111.com]#vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf把代码放入到配置文件中
[root@hf-01111.com]#/usr/local/apache2.4/bin/apachectl-tsyntaxok[root@hf-01111.com]#/usr/local/apache2.4/bin/apachectlgraceful[root@hf-01111.com]#创建upload目录,新建php文件
[root@hf-01111.com]#mkdirupload[root@hf-01111.com]#ls123.phpadminindex.phpqq111.jpgupload[root@hf-01111.com]#cp123.phpupload/[root@hf-01111.com]#curl访问
[root@hf-01111.com]#curl-x127.0.0.1:80'111.com/upload/123.php'-ihttp/1.1403forbiddendate:tue,26dec201716:09:43gmtserver:apache/2.4.29(unix)php/7.1.6content-type:text/html;charset=iso-8859-1[root@hf-01111.com]#这时在去虚拟主机配置文件中注释掉filesmatch
[root@hf-01111.com]#vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
[root@hf-01111.com]#/usr/local/apache2.4/bin/apachectl-tsyntaxok[root@hf-01111.com]#/usr/local/apache2.4/bin/apachectlgraceful[root@hf-01111.com]#这时候访问php,会发现无法解析php
[root@hf-01111.com]#!curlcurl-x127.0.0.1:80'111.com/upload/123.php'
[root@hf-01111.com]#/usr/local/apache2.4/bin/apachectl-tsyntaxok[root@hf-01111.com]#/usr/local/apache2.4/bin/apachectlgraceful[root@hf-01111.com]#这时再去浏览器访问php,会直接显示forbidden
有时候,网站会受到一种叫cc攻击,cc攻击就是黑客,通过软件,肉鸡同时去访问一个站点,超过服务器的并发,就会导致站点宕机;通过肉鸡,软件去访问站点,就是普通的访问,没有什么特殊的,只是让站点超过并发导致严重超负荷而宕机,所以没办法去进行控制;所谓cc攻击都会有一个规律的特征,就是user_agent是一致的,比如同一个ip、同一个标识、同一个地址;遇到这种规律的user_agent频繁访问的情况我们就可以判定他就是cc攻击,我们就可以通过限制他的user_agent减轻服务器压力,只需要让他从正常访问的200,限制为403,就能减轻服务器的压力,因为403仅仅是一个请求,只会使用到很少的带宽,毕竟他没有牵扯到php和mysql
cc攻击
肉鸡(受黑客远程控制的电脑)
[root@hf-01111.com]#vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
[root@hf-01111.com]#/usr/local/apache2.4/bin/apachectl-tsyntaxok[root@hf-01111.com]#/usr/local/apache2.4/bin/apachectlgraceful[root@hf-01111.com]#去访问的时候,会显示403,这是因为限制了user_agent
[root@hf-01111.com]#curl-x127.0.0.1:80'111.com/upload/123.php'-ihttp/1.1403forbiddendate:tue,26dec201720:52:15gmtserver:apache/2.4.29(unix)php/5.6.30content-type:text/html;charset=iso-8859-1[root@hf-01111.com]#curl-x127.0.0.1:80'111.com/123.php'-ihttp/1.1403forbiddendate:tue,26dec201720:53:30gmtserver:apache/2.4.29(unix)php/5.6.30content-type:text/html;charset=iso-8859-1[root@hf-01111.com]#查看访问日志
[root@hf-01logs]#tail-5/usr/local/apache2.4/logs/123.com-access_20171227.log192.168.74.1--[27/dec/2017:04:32:09+0800]"get/123.phphttp/1.1"2007"-""mozilla/5.0(windowsnt6.1;wow64)applewebkit/537.36(khtml,likegecko)chrome/49.0.2623.221safari/537.36se2.xmetasr1.0"192.168.74.1--[27/dec/2017:04:32:10+0800]"get/123.phphttp/1.1"2007"-""mozilla/5.0(windowsnt6.1;wow64)applewebkit/537.36(khtml,likegecko)chrome/49.0.2623.221safari/537.36se2.xmetasr1.0"192.168.74.1--[27/dec/2017:04:32:17+0800]"get/upload/123.phphttp/1.1"403223"-""mozilla/5.0(windowsnt6.1;wow64)applewebkit/537.36(khtml,likegecko)chrome/49.0.2623.221safari/537.36se2.xmetasr1.0"127.0.0.1--[27/dec/2017:04:52:15+0800]"headhttp://111.com/upload/123.phphttp/1.1"403-"-""curl/7.29.0"127.0.0.1--[27/dec/2017:04:53:30+0800]"headhttp://111.com/123.phphttp/1.1"403-"-""curl/7.29.0"[root@hf-01logs]#测试是否是因为user_agent才会被信任的首先自定义user_agentcurl-a参数,去自定义
模拟user_agent,去访问会看到状态码为200可以正常访问[root@hf-01111.com]#curl-a"hanfenghanfeng"-x127.0.0.1:80'111.com/123.php'-ihttp/1.1200okdate:tue,26dec201721:17:47gmtserver:apache/2.4.29(unix)php/5.6.30x-powered-by:php/5.6.30content-type:text/html;charset=utf-8[root@hf-01111.com]#curl-a"hanfenghanfeng"-x127.0.0.1:80'111.com/123.php'123.php[root@hf-01111.com]#[root@hf-01111.com]#查看访问日志,会看到user_agent是hanfenghanfeng
[root@hf-01111.com]#!tailtail-5/usr/local/apache2.4/logs/123.com-access_20171227.log192.168.74.1--[27/dec/2017:04:32:17+0800]"get/upload/123.phphttp/1.1"403223"-""mozilla/5.0(windowsnt6.1;wow64)applewebkit/537.36(khtml,likegecko)chrome/49.0.2623.221safari/537.36se2.xmetasr1.0"127.0.0.1--[27/dec/2017:04:52:15+0800]"headhttp://111.com/upload/123.phphttp/1.1"403-"-""curl/7.29.0"127.0.0.1--[27/dec/2017:04:53:30+0800]"headhttp://111.com/123.phphttp/1.1"403-"-""curl/7.29.0"127.0.0.1--[27/dec/2017:05:17:47+0800]"headhttp://111.com/123.phphttp/1.1"200-"-""hanfenghanfeng"127.0.0.1--[27/dec/2017:05:19:40+0800]"gethttp://111.com/123.phphttp/1.1"2007"-""hanfenghanfeng"[root@hf-01111.com]#curl命令curl命令是一个利用url规则在命令行下工作的文件传输工具-a,指定user-agent,设置用户代理发送给服务器-e,指定referer,就是来源网址-i,仅仅查看它的状态码-x,在指定的端口上使用http代理11.30/11.31php相关配置php相关配置目录概要查看php配置文件位置/usr/local/php/bin/php-i|grep-i"loadedconfigurationfile"date.timezonedisable_functionseval,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_closeerror_log,log_errors,display_errors,error_reportingopen_basedirphp_admin_valueopen_basedir"/data/wwwroot/111.com:/tmp/"php相关配置查看php配置文件的位置通过浏览器,访问phpinfo找到配置文件的路径也可以用/usr/local/php/bin/php-i|grep-i“loadedconfigurationfile”找到他的路径;但是有些情况“php-i”是不准的,因为apache他是调用了php的一模块,而且“php-i”只是php的一个程序,它和libphp5.so可能有关系也可能没有关系;案例:有时改了php.ini,改动了也重启了服务,结果配置还是不生效;因为使用“php-i”找到的配置文件和在web上的phpinfo找到的php.ini不是同一个,如果想要准确的找到php.ini配置文件,就在对应的站点目录下,创建一个phpinfo的php文件,在web上打开,在phpinfo上找到的,才是最准确的
[root@hf-01111.com]#ls11.png123.phpadminindex.phpinedx.phpupload[root@hf-01111.com]#viindex.php[root@hf-01111.com]#cd/usr/local/src/php-5.6.30/[root@hf-01php-5.6.30]#cpphp.ini-development/usr/local/php/etc/php.ini[root@hf-01php-5.6.30]#/usr/local/apache2.4/bin/apachectlgraceful[root@hf-01php-5.6.30]#这时用浏览器访问看到配置文件的路径设置安全函数disable_functions//安全函数eval之前提到的一句话木马涉及到的函数,如果把这个函数禁用,那么那个木马将不会生效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以上是比较危险的函数设置php文件打开php文件,禁掉一些危险的函数,默认配置文件里面是空的(这里使用的是php5),
[root@hf-01php-5.6.30]#vim/usr/local/php/etc/php.ini搜索/disable在disable_functions=后禁掉一些危险的函数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然后保存当然也可以把phpinfo禁掉,很多企业在生产环境都会禁掉,因为phpinfo涉及到服务器很多php的配置相关,如果一不小心上传到了线上,那么久很容易被黑客查到,进行对应的攻击设置时区重新加载配置文件
[root@hf-01php-5.6.30]#/usr/local/apache2.4/bin/apachectlgraceful[root@hf-01php-5.6.30]#再去浏览器访问111.com/index.php,会显示phpinfo是被禁掉了
[root@hf-01php-5.6.30]#vim/usr/local/php/etc/php.ini搜索/timezone在date.timezone定义时区需要删除;分号date.timezone=asia/shanghai搜索/display需要删除;分号将display_errors=on更改为display_errors=off然后保存退出检查配置文件是否存在语法错误,并重新加载配置文件
[root@hf-01php-5.6.30]#/usr/local/apache2.4/bin/apachectl-tsyntaxok[root@hf-01php-5.6.30]#/usr/local/apache2.4/bin/apachectlgraceful[root@hf-01php-5.6.30]#这时候再去用浏览器访问111.com/index.php,会看到的是白页,这就是因为display_errors=off
搜索/log_errors,将错误日志文件打开log_errors=on搜索/error_log,将错误日志文件定义到tmp目录下需要删除;分号error_log=/tmp/php_errors.log然后保存退出检查配置文件是否存在语法错误,并重新加载配置文件这时再去访问一遍,会看到tmp目录下生成了php_errors.log
[root@hf-01php-5.6.30]#curl-a"a"-x127.0.0.1:80http://111.com/index.php[root@hf-01php-5.6.30]#ls/tmp/mysql.sockphp_errors.log
10查看php_errors.log文件,会看到属主属组是daemon
[root@hf-01php-5.6.30]#ls-l/tmp/php_errors.log-rw-r--r--1daemondaemon13512月2707:30/tmp/php_errors.log[root@hf-01php-5.6.30]#daemon实际上是httpd的属主,php_errors.log日志文件是以httpd这个进程的身份去生成的
[root@hf-01php-5.6.30]#psaux|grephttpdroot25390.01.225830412708?ss04:260:01/usr/local/apache2.4/bin/httpd-kgracefuldaemon36850.00.95451329580?sl07:300:00/usr/local/apache2.4/bin/httpd-kgracefuldaemon36860.00.95451329580?sl07:300:00/usr/local/apache2.4/bin/httpd-kgracefuldaemon36870.01.261066812388?sl07:300:00/usr/local/apache2.4/bin/httpd-kgracefulroot37760.00.0112676984pts/0r+07:330:00grep--color=autohttpd[root@hf-01php-5.6.30]#有时候,定义了一个错误日志,但是这个错误日志始终没有生成,那么就需要检查一下定义错误日志所在的目录,到底httpd有没有写权限最保险的办法,就是在所在目录创建一个错误日志的文件,然后赋予它777的权限,这样就不需要担心这个文件httpd是否有写权限了
[root@hf-01php-5.6.30]#greperror_log/usr/local/php/etc/php.ini;server-specificlog,stderr,oralocationspecifiedbytheerror_log;setmaximumlengthoflog_errors.inerror_loginformationaboutthesourceiserror_log=/tmp/php_errors.log;error_log=syslog;opcacheerror_logfilename.emptystringassumes"stderr".;opcache.error_log=[root@hf-01php-5.6.30]#
-可以先创建好/tmp/php_errors.log文件,然后赋予chmod777权限查看文件日志
[root@hf-01php-5.6.30]#cat/tmp/php_errors.log//会告诉你因为安全的原因,这个函数已经被禁掉了[26-dec-201723:30:19utc]phpwarning:phpinfo()hasbeendisabledforsecurityreasonsin/data/wwwroot/111.com/index.phponline2[root@hf-01php-5.6.30]#安全相关的参数一台服务器上,运行了多个站点,有一台服务器假如代码有问题,结果这个站点被黑客攻击了,被黑客拿到了权限,黑客拿了权限肯定会继续往里渗透,继续往里渗透,就会有可能渗透到其他的站点,同时导致其他的站点被黑open_basedir,它是一个安全选项,限制不能串岗php.ini文件中的内容是针对所有虚拟主机进行的配置!!!打开php配置文件
[root@hf-01php-5.6.30]#vim/usr/local/php/etc/php.ini搜索/open_basedir,并上删除;号open_basedir=/data/wwwroot/111.com:/tmp然后保存退出检查配置文件是否存在语法错误,并重新加载配置文件再来访问,会显示正常
[root@hf-01php-5.6.30]#curl-a"a"-x127.0.0.1:80http://111.com/index.php-ihttp/1.1200okdate:wed,27dec201700:04:36gmtserver:apache/2.4.29(unix)php/5.6.30x-powered-by:php/5.6.30content-type:text/html;charset=utf-8[root@hf-01php-5.6.30]#若是服务器上跑了n多个站点,那应该怎么去做限制呢?应该针对站点,这些网站去做open_basedir,但php.ini是做不到的,因为php.ini是针对所有站点的但我们可以在虚拟主机配置文件中设置,在apache虚拟主机配置文件中去设置/usr/local/apache2.4/conf/extra/httpd-vhosts.conf在这里可以针对不同虚拟主机限制不同的open_basedir
[root@hf-01php-7.1.6]#vim/usr/local/apache2.4/conf/extra/httpd-vhosts.confphp_admin_valueopen_basedir"/data/wwwroot/111.com:/tmp/"然后保存退出检查配置文件语法错误,并重新加载配置文件
[root@hf-01php-7.1.6]#/usr/local/apache2.4/bin/apachectl-tsyntaxok[root@hf-01php-7.1.6]#/usr/local/apache2.4/bin/apachectlgraceful[root@hf-01php-7.1.6]#curl测试
[root@hf-01php-7.1.6]#curl-a"a"-x127.0.0.1:80http://111.com/index.php111.com[root@hf-01php-7.1.6]#扩展
apache开启压缩
apache2.2到2.4配置文件变更
apacheoptions参数
apache禁止trace或track防止xss