<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>https://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>https://jackxiang.com/post//</link>
<title><![CDATA[如何查看nginx 安装了哪些模块，及其nginx安全模块安装使用:Nginx与Apache安全配置实现防黑客sql注入与上传木马攻击，Apache需要安装mod_security模块,Nginx终于有了类似modsecurity的模块]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Sat, 10 Apr 2010 18:14:06 +0000</pubDate> 
<guid>https://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	如何查看nginx 安装了哪些模块，及其nginx安全模块安装使用。<br/>nginx的安全模块ngx_http_secure_link_module，想查看下，发现这个无非是当时编译时的那些参数，但也给我们提供了升级重新编译的线索喔，还是安一个吧，免得会有人注入，拿Webserver权限。<br/>注意:要使用到这个模块,需要在configure的时候,加入--with-http_secure_link_module选项.<br/><textarea name="code" class="html" rows="15" cols="100">
ngingx -V
</textarea><br/>看下示例：<br/><textarea name="code" class="html" rows="15" cols="100">
root@116.255.139.24*:/usr/local/webserver/nginx/sbin# ./nginx -V
nginx: nginx version: nginx/1.1.1
nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-50)
nginx: TLS SNI support disabled
nginx: configure arguments: --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/root/software/nginx_http_push_module-0.692 --add-module=/root/software/ngx_cache_purge-1.3
</textarea><br/><br/>自己加入安全模块的编译选项：<br/><textarea name="code" class="html" rows="15" cols="100">
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/root/software/nginx_http_push_module-0.692 --add-module=/root/software/ngx_cache_purge-1.3&nbsp;&nbsp;--with-http_secure_link_module
</textarea><br/>编译：<br/><textarea name="code" class="html" rows="15" cols="100">
make;make install
</textarea><br/><br/>配置nginx.conf:<br/>ngx_http_secure_link_module.<br/><br/>下面是一个简单的配置示例:<br/><br/>location /p/ &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;secure_link_secret&nbsp;&nbsp; some_secret_word;<br/>&nbsp;&nbsp;&nbsp;&nbsp;if ($secure_link = &quot;&quot;) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 403;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&#125;<br/><br/>注意:要使用到这个模块,需要在configure的时候,加入--with-http_secure_link_module选项.<br/><br/>下面是说明:<br/><br/>syntax: secure_link_secret (后跟字词)<br/>default: 不包含在默认的编译选项中<br/>context: location<br/><br/>使用规定的加密字串来验证连结.完整的URL加密参考:<br/>/prefix/hash/一个hash示例:<br/>md5(路径(或连接), 参数(或选项));<br/>注:前缀可以有任意行,但不包括斜线.<br/>看了下俄文翻译的结果,晕忽忽,不太懂......<br/>也许是因为才加入的新特性的缘故(0.7.18+),使用方法写得不是很详细,需要自己去摸索. !<br/>希望这个模块能够对那些安全高手有作用!<br/><textarea name="code" class="html" rows="15" cols="100">
&nbsp;&nbsp;&nbsp;&nbsp;secure_link_secret&nbsp;&nbsp; concat union and select;
&nbsp;&nbsp;&nbsp;&nbsp;if ($secure_link = &quot;&quot;) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 403;
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
</textarea><br/>思路来自下面：<br/><textarea name="code" class="html" rows="15" cols="100">
&nbsp;&nbsp;error_page 519 /519.html;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;(cost&#92;()&#124;(concat&#92;()&quot;) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 519;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;[+&#124;(%20)]union[+&#124;(%20)]&quot;) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 519;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;[+&#124;(%20)]and[+&#124;(%20)]&quot;) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 519;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;[+&#124;(%20)]select[+&#124;(%20)]&quot;) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 519;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
</textarea><br/><br/><br/>最后配置并测试：<br/><textarea name="code" class="html" rows="15" cols="100">
 server &#123;
&nbsp;&nbsp;&nbsp;&nbsp; listen 80;
&nbsp;&nbsp;&nbsp;&nbsp; server_name c.jackxiang.com;
&nbsp;&nbsp;&nbsp;&nbsp; root /data0/htdocs/center;
&nbsp;&nbsp;&nbsp;&nbsp; access_log&nbsp;&nbsp;/data1/logs/c.justwinit_access.log&nbsp;&nbsp;access;
&nbsp;&nbsp;&nbsp;&nbsp; location / &#123;
&nbsp;&nbsp;&nbsp;&nbsp; root /data0/htdocs/center;
&nbsp;&nbsp;&nbsp;&nbsp; index index.html index.htm index.php;
&nbsp;&nbsp;&nbsp;&nbsp; &#125;
&nbsp;&nbsp;&nbsp;&nbsp; location ~ .*&#92;.(php&#124;php5)?$
&nbsp;&nbsp;&nbsp;&nbsp; &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; secure_link_secret&nbsp;&nbsp; union;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($secure_link = &quot;&quot;) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 403;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #fastcgi_pass&nbsp;&nbsp;unix:/tmp/php-cgi.sock;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fastcgi_pass&nbsp;&nbsp;127.0.0.1:9000;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fastcgi_index index.php;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; include fcgi.conf;
&nbsp;&nbsp;&nbsp;&nbsp; &#125;
 &#125;
</textarea><br/>测试后缀是PHP的文件：<br/>&#039;http://c.jackxiang.com/login/login.php?un=union&nbsp;&nbsp;出现：<br/>403 Forbidden<br/>nginx/1.1.1<br/>对error_page的知识补充：<br/>Nginx做404在网上有两种方式：<br/>１：<br/>error_page 404 http://www.252300.net/?page-error.html; <br/><br/>这样写发现不能正常转跳，看来Nginx不能自动转义，加上转义后还是不能转<br/>就来个直接点的 在下面再加个rewrite，让rewrite来做这事<br/><br/>error_page 404 http://www.252300.net/page-error;&nbsp;&nbsp;<br/>location /page-error &#123;&nbsp;&nbsp;<br/>rewrite ^(.*) http://www.252300.net/?page-error.html permanent;&nbsp;&nbsp;<br/>&#125; <br/>一步是用rewrite来完成的，下面来说第二种<br/>２：需如下几步：<br/><br/>　创建自己的404.html页面 <br/><br/>　更改nginx.conf在http定义区域加入： fastcgi_intercept_errors on; <br/><br/>　更改nginx.conf（或单独网站配置文件，例如在nginx -&gt; sites-enabled下的站点配置文件 ）<br/><br/>中在server 区域加入： error_page 404 = /404.html&nbsp;&nbsp;或者 error_page 404 = http://www.252300.net/404.html<br/><br/>4.更改后重启nginx,，测试nginx.conf正确性： /opt/nginx/sbin/nginx –t <br/><br/>#502 等错误可以用同样的方法来配置。&nbsp;&nbsp;<br/><br/>error_page&nbsp;&nbsp;500 502 503 504 = /50x.html; <br/><br/>注意：<br/> 必须要添加：fastcgi_intercept_errors on; 如果这个选项没有设置，即使创建了404.html和配置了error_page也没有效果。<br/>fastcgi_intercept_errors 语法: fastcgi_intercept_errors on&#124;off 默认: fastcgi_intercept_errors off 添加位置: http, server, location 默认情况下，nginx不支持自定义404错误页面，只有这个指令被设置为on，nginx才支持将404错误重定向。这里需要注意的是，并不是说设置了 fastcgi_intercept_errors on，nginx就会将404错误重定向。在nginx中404错误重定向生效的前提是设置了fastcgi_intercept_errors on,并且正确的设置了error_page这个选项（包括语法和对应的404页面)<br/>自定义的404页面必须大于512字节，否则可能会出现IE默认的404页面。例如，假设自定义了404.html,大小只有11个字节（内容为：404错误）<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>error_page 519 /519.html;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;(cost&#92;()&#124;(concat&#92;()&quot;) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 519;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;[+&#124;(%20)]union[+&#124;(%20)]&quot;) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 519;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;[+&#124;(%20)]and[+&#124;(%20)]&quot;) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 519;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;[+&#124;(%20)]select[+&#124;(%20)]&quot;) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 519;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/><br/>基本sql注入原理：<br/>通过union all 联合查询获取其他表的内容（如user表的用户密码）<br/><br/>防御原理：<br/>1. 通过以上配置过滤基本的url中的注入关键字；<br/>2. 当然，数据库中的用户密码得加密存放 ；<br/>3. php程序进行二次过滤，过滤GET和POST变量中的关键字；<br/>4. 生产环境关闭PHP和MySQL的错误信息。<br/><br/><br/>一、Nginx的安全配置:<br/>在Nginx的俄文站点上看到,从0.7.18版开始,Nginx有了自己的安全检查模块:<br/><br/>ngx_http_secure_link_module.<br/><br/>下面是一个简单的配置示例:<br/><br/>location /p/ &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;secure_link_secret&nbsp;&nbsp; some_secret_word;<br/>&nbsp;&nbsp;&nbsp;&nbsp;if ($secure_link = &quot;&quot;) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 403;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&#125;<br/><br/>注意:要使用到这个模块,需要在configure的时候,加入--with-http_secure_link_module选项.<br/><br/>下面是说明:<br/><br/>syntax: secure_link_secret (后跟字词)<br/>default: 不包含在默认的编译选项中<br/>context: location<br/><br/>使用规定的加密字串来验证连结.完整的URL加密参考:<br/>/prefix/hash/一个hash示例:<br/>md5(路径(或连接), 参数(或选项));<br/>注:前缀可以有任意行,但不包括斜线.<br/><br/>当然如果不想安装安全检测模块,解决方法是在conf文件加入以下代码:<br/><br/>error_page 444 /block_ip.html;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;(cost&#92;()&#124;(concat&#92;()&quot;) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 444;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;[+&#124;(%20)]union[+&#124;(%20)]&quot;) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 444;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;[+&#124;(%20)]and[+&#124;(%20)]&quot;) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 444;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_uri ~* &quot;[+&#124;(%20)]select[+&#124;(%20)]&quot;) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 444;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/><br/>二、apache的的安全配置:<br/>&nbsp;&nbsp;&nbsp;&nbsp;安装apache时根据情况带几个参数，网上也有其他优化参数，但估计性能差不了多少，如下<br/>./configure --prefix=/usr/local/apache2.2.10 --enable-so --enable-deflate --enable-rewrite --enable-expires<br/>我做过测试，apache自带的mod_mem_cache不太好使，最大使用内存不到200M时就会有问题，内存使用量突然下降，所以<br/>图片服务器建议不要用apache，用nginx会更好。<br/><br/>apache简单防DDOS攻击的配置，需要从网上找一个mod_evasive20模块，用/usr/local/apache/bin/apxs -cia mod_evasive20.c安装，一般情况下没有必要配置这玩意。<br/>&lt;IfModule mod_evasive20.c&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSHashTableSize&nbsp;&nbsp;&nbsp;&nbsp;10000&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSPageCount&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2<br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSSiteCount&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;50<br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSPageInterval&nbsp;&nbsp;&nbsp;&nbsp; 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSSiteInterval&nbsp;&nbsp;&nbsp;&nbsp; 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSBlockingPeriod&nbsp;&nbsp; 10<br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSEmailNotify&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webmaster@xxx.com<br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSLogDir&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /var/log/mod_dosevasive.log<br/>&lt;/IfModule&gt;<br/><br/>apache防sql注入攻击的配置，需要安装mod_security模块<br/>&lt;IfModule mod_security.c&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterEngine On<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterCheckURLEncoding On<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterForceByteRange 32 126<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterCheckUnicodeEncoding On<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecServerResponseToken Off<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecAuditEngine RelevantOnly<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecAuditLog logs/audit_log<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterDebugLog logs/modsec_debug_log<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterDebugLevel 0<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterDefaultAction &quot;deny,log,status:406&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter /etc/*passwd<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter /bin/*sh<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;&#92;.&#92;./&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;&lt;( &#124;&#92;n)*script&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;&lt;(.&#124;&#92;n)+&gt;&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;delete[[:space:]]+from&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;insert[[:space:]]+into&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;select.+from&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;union[[:space:]]+from&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;drop[[:space:]]&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterSelective &quot;HTTP_USER_AGENT&#124;HTTP_HOST&quot; &quot;^$&quot;<br/>&lt;/IfModule&gt;<br/><br/><br/>于5.20日下午6点发布了一个关于nginx的漏洞通告，由于该漏洞的存在，使用nginx+php组建的网站只要允许上传图片就可能被黑客入侵，直到5.21日凌晨，nginx尚未发布修复该漏洞的补丁；已经有一些网站被黑了，管理员速修复！<br/><br/><br/>根据Netcraft的统计，直到2010年4月，全球一共有1300万台服务器运行着nginx程序；非常保守的估计，其中至少有600万台服务器运行着nginx并启用了php支持；继续保守的估计，其中有1/6，也就是100万台服务器允许用户上传图片。有图有真相。<br/><br/>没错，重申一次，由于nginx有漏洞，这100万台服务器可能通过上传图片的方法被黑客轻易的植入木马。植入木马的过程也非常简单，就是把木马改成图片上传就是了，由于危害非常大，就不说细节了。<br/><br/>发一个小道消息，据说黑客已经在行动了；安全人员、系统管理人员、行动起来吧，赶紧修复该漏洞；最好不要有侥幸心理，否则下一个被黑客入侵的可能就是你的网站。根据test安全公告的描述，临时修复方法如下，可3选其一。<br/><br/>1、设置php.ini的cgi.fix_pathinfo为0，重启php。最方便，但修改设置的影响需要自己评估。<br/><br/>2、给nginx的vhost配置添加如下内容，重启nginx。vhost较少的情况下也很方便。<br/><br/>if ( $fastcgi_script_name ~ &#92;..*&#92;/.*php ) &#123;<br/>return 403;<br/>&#125;<br/><br/>3、禁止上传目录解释PHP程序。不需要动webserver，如果vhost和服务器较多，短期内难度急剧上升；建议在vhost和服务器较少的情况下采用。<br/><br/>漏洞介绍：nginx是一款高性能的web服务器，使用非常广泛，其不仅经常被用作反向代理，也可以非常好的支持PHP的运行。test发现其中存在一个较为严重的安全问题，默认情况下可能导致服务器错误的将任何类型的文件以PHP的方式进行解析，这将导致严重的安全问题，使得恶意的攻击者可能攻陷支持php的nginx服务器。<br/><br/><br/>漏洞分析：nginx默认以cgi的方式支持php的运行，譬如在配置文件当中可以以<br/><br/><br/>location ~ &#92;.php$ &#123;<br/>root html;<br/>fastcgi_pass 127.0.0.1:9000;<br/>fastcgi_index index.php;<br/>fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;<br/>include fastcgi_params;<br/>&#125;<br/><br/>的方式支持对php的解析，location对请求进行选择的时候会使用URI环境变量进行选择，其中传递到后端Fastcgi的关键变量SCRIPT_FILENAME由nginx生成的$fastcgi_script_name决定，而通过分析可以看到$fastcgi_script_name是直接由URI环境变量控制的，这里就是产生问题的点。而为了较好的支持PATH_INFO的提取，在PHP的配置选项里存在cgi.fix_pathinfo选项，其目的是为了从SCRIPT_FILENAME里取出真正的脚本名。<br/>那么假设存在一个http://www.test.com/test.jpg，我们以如下的方式去访问<br/><br/>将会得到一个URI<br/><br/>/test.jpg/test.php<br/><br/>经过location指令，该请求将会交给后端的fastcgi处理，nginx为其设置环境变量SCRIPT_FILENAME，内容为<br/><br/>/scripts/test.jpg/test.php<br/><br/>而在其他的webserver如lighttpd当中，我们发现其中的SCRIPT_FILENAME被正确的设置为<br/><br/>/scripts/test.jpg<br/><br/>所以不存在此问题。<br/>后端的fastcgi在接受到该选项时，会根据fix_pathinfo配置决定是否对SCRIPT_FILENAME进行额外的处理，一般情况下如果不对fix_pathinfo进行设置将影响使用PATH_INFO进行路由选择的应用，所以该选项一般配置开启。Php通过该选项之后将查找其中真正的脚本文件名字，查找的方式也是查看文件是否存在，这个时候将分离出SCRIPT_FILENAME和PATH_INFO分别为<br/><br/>/scripts/test.jpg和test.php<br/><br/>最后，以/scripts/test.jpg作为此次请求需要执行的脚本，攻击者就可以实现让nginx以php来解析任何类型的文件了。<br/><br/>http://www.test.com/test.jpg/test.php<br/><br/>POC： 访问一个nginx来支持php的站点，在一个任何资源的文件如robots.txt后面加上/test.php，这个时候你可以看到如下的区别：<br/><br/>访问http://www.test.com/robots.txt<br/><br/>HTTP/1.1 200 OK<br/>Server: nginx/0.6.32<br/>Date: Thu, 20 May 2010 10:05:30 GMT<br/>Content-Type: text/plain<br/>Content-Length: 18<br/>Last-Modified: Thu, 20 May 2010 06:26:34 GMT<br/>Connection: keep-alive<br/>Keep-Alive: timeout=20<br/>Accept-Ranges: bytes<br/><br/>访问访问http://www.test.com/robots.txt/test.php<br/><br/>HTTP/1.1 200 OK<br/>Server: nginx/0.6.32<br/>Date: Thu, 20 May 2010 10:06:49 GMT<br/>Content-Type: text/html<br/>Transfer-Encoding: chunked<br/>Connection: keep-alive<br/>Keep-Alive: timeout=20<br/>X-Powered-By: PHP/5.2.6<br/><br/>其中的Content-Type的变化说明了后端负责解析的变化，该站点就可能存在漏洞。<br/><br/>apache的一些配置和技巧。 <br/>&nbsp;&nbsp;&nbsp;&nbsp;安装apache时根据情况带几个参数，网上也有其他优化参数，但估计性能差不了多少，如下 <br/>./configure --prefix=/usr/local/apache2.2.10 --enable-so --enable-deflate --enable-rewrite --enable-expires&nbsp;&nbsp;<br/>我做过测试，apache自带的mod_mem_cache不太好使，最大使用内存不到200M时就会有问题，内存使用量突然下降，所以 <br/>图片服务器建议不要用apache，用lighttpd或者nginx会更好。lighttpd+memcached的方式我就没配成功过，nginx+memcached能从缓存 <br/>里获取，但不能set到缓存，所以我用的是lighttpd+mod_mem_cache（需要把lighttpd打个补丁），稍后作详细介绍。 <br/><br/>apache简单防DDOS攻击的配置，需要从网上找一个mod_evasive20模块，用/usr/local/apache/bin/apxs -cia mod_evasive20.c安装，一般情况下没有必要配置这玩意。 <br/>&lt;IfModule mod_evasive20.c&gt; <br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSHashTableSize&nbsp;&nbsp;&nbsp;&nbsp;10000&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSPageCount&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2 <br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSSiteCount&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;50 <br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSPageInterval&nbsp;&nbsp;&nbsp;&nbsp; 1 <br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSSiteInterval&nbsp;&nbsp;&nbsp;&nbsp; 1 <br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSBlockingPeriod&nbsp;&nbsp; 10 <br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSEmailNotify&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webmaster@xxx.com <br/>&nbsp;&nbsp;&nbsp;&nbsp;DOSLogDir&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /var/log/mod_dosevasive.log <br/>&lt;/IfModule&gt; <br/><br/>apache防sql注入攻击的配置，需要安装mod_security模块 <br/>&lt;IfModule mod_security.c&gt; <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterEngine On <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterCheckURLEncoding On <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterForceByteRange 32 126 <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterCheckUnicodeEncoding On <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecServerResponseToken Off <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecAuditEngine RelevantOnly <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecAuditLog logs/audit_log <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterDebugLog logs/modsec_debug_log <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterDebugLevel 0 <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterDefaultAction &quot;deny,log,status:406&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter /etc/*passwd <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter /bin/*sh <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;&#92;.&#92;./&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;&lt;( &#124;&#92;n)*script&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;&lt;(.&#124;&#92;n)+&gt;&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;delete[[:space:]]+from&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;insert[[:space:]]+into&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;select.+from&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;union[[:space:]]+from&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilter &quot;drop[[:space:]]&quot; <br/>&nbsp;&nbsp;&nbsp;&nbsp;SecFilterSelective &quot;HTTP_USER_AGENT&#124;HTTP_HOST&quot; &quot;^$&quot; <br/>&lt;/IfModule&gt; <br/><br/>加大apache最大连接数的配置，如果选择的是preworker工作方式。preworker和worker的区别就不讲了。apache2.0以上直接设置ServerLimit即可，apache2.0以前还要修改源代码才能使修改 <br/>的ServerLimit生效，建议应用服务器用apache2.0吧，性能差不了多少。 <br/><br/>&lt;IfModule mpm_prefork_module&gt; <br/>&nbsp;&nbsp;&nbsp;&nbsp;ServerLimit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 20000&nbsp;&nbsp;#ServerLimit据说要放第一行 <br/>&nbsp;&nbsp;&nbsp;&nbsp;StartServers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;50 <br/>&nbsp;&nbsp;&nbsp;&nbsp;MinSpareServers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 50 <br/>&nbsp;&nbsp;&nbsp;&nbsp;MaxSpareServers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 100 <br/>&nbsp;&nbsp;&nbsp;&nbsp;MaxClients&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10000 <br/>&nbsp;&nbsp;&nbsp;&nbsp;MaxRequestsPerChild&nbsp;&nbsp; 10000 <br/>&lt;/IfModule&gt; <br/><br/>压缩传输的配置，这个做为网站来说非常重要，它是不压缩传输大小的20%左右，也就是说用户访问一个网站速度快了5倍，不配置不行，但是图片不能做压缩了。 <br/><br/>&lt;IfModule mod_deflate.c&gt; <br/> SetOutputFilter DEFLATE <br/> DeflateCompressionLevel 3&nbsp;&nbsp;<br/> DeflateFilterNote Input instream <br/> DeflateFilterNote Output outstream <br/> DeflateFilterNote Ratio ratio <br/> LogFormat &#039;&quot;%h %l %u %t &#92;&quot;%r&#92;&quot; %&gt;s %b &#92;&quot;%&#123;Referer&#125;i&#92;&quot; &#92;&quot;%&#123;User-Agent&#125;i&#92;&quot;&quot; &quot;%r&quot; %&#123;outstream&#125;n/%&#123;instream&#125;n (%&#123;ratio&#125;n%%)&#039; deflate <br/> # Netscape 4.x has some problems... <br/> BrowserMatch ^Mozilla/4 gzip-only-text/html <br/> # Netscape 4.06-4.08 have some more problems <br/> BrowserMatch ^Mozilla/4&#92;.0[678] no-gzip <br/> # MSIE masquerades as Netscape, but it is fine <br/> #BrowserMatch &#92;bMSIE !no-gzip !gzip-only-text/html <br/> # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48 <br/> # the above regex won&#039;t work. You can use the following <br/> # workaround to get the desired effect: <br/> BrowserMatch &#92;bMSI[E] !no-gzip !gzip-only-text/html <br/> # Don&#039;t compress images, java scripts and style sheets <br/> SetEnvIfNoCase Request_URI &#92;.(?:gif&#124;jpe?g&#124;png&#124;js&#124;css)$ no-gzip dont-vary <br/><br/> # Make sure proxies don&#039;t deliver the wrong content <br/> # this needs mod_headers but it&#039;s very important <br/> # so I don&#039;t add a IfModule around it <br/> #Header append Vary User-Agent env=!dont-vary <br/> #CustomLog logs/deflate_log.log deflate <br/> #CustomLog &quot;&#124;/usr/local/cronolog/sbin/cronolog /usr/local/apache2.0.59_2/logs/www.shedewang.com.access.log.%Y%m%d&quot; deflate env=!IMAG <br/>&lt;/IfModule&gt; <br/><br/>apache配置mod_mem_cache，这个模块不太好使，建议不用 <br/>&lt;IfModule mod_cache.c&gt; <br/>#CacheForceCompletion 100 <br/>CacheDefaultExpire 3600 <br/>CacheMaxExpire 86400 <br/>CacheLastModifiedFactor 0.1 <br/>CacheIgnoreNoLastMod on <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;IfModule mod_mem_cache.c&gt; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CacheEnable mem / <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MCacheSize 2000000 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MCacheMaxObjectCount 10000 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MCacheMinObjectSize 1000 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MCacheMaxObjectSize 512000 <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MCacheRemovalAlgorithm LRU <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/IfModule&gt; <br/>&lt;/IfModule&gt; <br/><br/>CacheEnable: 启动 mod_cache，其后接两个参数。第一个参数指定快取的种类，应设为 mem (记忆体快取) 或 disk (磁碟快取) 之其一；第二个参数指定使用快取的 URI 路径，如果对整个网站 (或虚拟主机) 进行快取，简单指定为根目录(/) 即可。 <br/>CacheForceCompletion: 这个值指定当 HTTP request 被取消时，内容的产生动作要完成的百分比；预设是 60(%)。 <br/>CacheDefaultExpire: 指定快取的预设过期秒数；预设值是一小时 (3600)。 <br/>CacheMaxExpire: 指定快取最大的过期秒数；预设值是一天 (86400)。 <br/>CacheLastModifiedFactor: 用来从回应里 Last Modified 资讯算出 expire date。 <br/>计算方式是：expire period (过期时距) = 最后更新后至今的时间间距 * CacheLastModifiedFactor <br/>而expire date = 目前时间 + expire period <br/>不过无论如何，过期时间不能超过 CacheMaxExpire 的设定值。 <br/><br/><br/>配置mod_expires模块 <br/><br/>mod_expires可以减少10%左右的重复请求，让重复的用户对指定的页面请求结果都CACHE在本地，根本不向服务器发出请求，这一点特别实用在图片服务器上。 <br/><br/>mod_expires的安装配置： <br/>&lt;IfModule mod_expires.c&gt; <br/>&nbsp;&nbsp;# turn on the module for this directory <br/>&nbsp;&nbsp;ExpiresActive on <br/><br/>&nbsp;&nbsp;# cache common graphics for 3 days <br/>&nbsp;&nbsp;ExpiresByType image/jpg &quot;access plus 365 days&quot; <br/>&nbsp;&nbsp;ExpiresByType image/gif &quot;access plus 365 days&quot; <br/>&nbsp;&nbsp;ExpiresByType image/jpeg &quot;access plus 365 days&quot; <br/>&nbsp;&nbsp;ExpiresByType image/png &quot;access plus 365 days&quot; <br/><br/>&lt;/IfModule&gt; <br/><br/><br/><br/>本文来自CSDN博客，转载请标明出处：http://blog.csdn.net/wanghao72214/archive/2009/01/15/3788891.aspx<br/><br/>
]]>
</description>
</item><item>
<link>https://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] 如何查看nginx 安装了哪些模块，及其nginx安全模块安装使用:Nginx与Apache安全配置实现防黑客sql注入与上传木马攻击，Apache需要安装mod_security模块,Nginx终于有了类似modsecurity的模块]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>