<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[ 让 Nginx 支持 WAF 防护功能web防火墙 ]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[服务器技术]]></category>
<pubDate>Mon, 15 Jul 2013 06:19:47 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	ngx_lua_waf 安装说明文档<br/><br/>作者github地址:<br/><a href="https://github.com/loveshell/ngx_lua_waf" target="_blank">https://github.com/loveshell/ngx_lua_waf</a><br/><div class="code"><br/>ngx_lua_waf是我一个基于ngx_lua的web应用防火墙。<br/>代码很简单，开发初衷主要是使用简单，高性能和轻量级。<br/>现在开源出来.其中包含我们的过滤规则。如果大家有什么建议和想fa，欢迎和我一起完善。<br/><br/><br/>用途：<br/>用于过滤post，get，cookie方式常见的web攻击<br/>防止sql注入，本地包含，部分溢出，fuzzing测试，xss,SSRF等web攻击<br/>防止svn/备份之类文件泄漏<br/>防止ApacheBench之类压力测试工具的攻击<br/>屏蔽常见的扫描黑客工具，扫描器&#91;separator&#93;<br/>屏蔽异常的网络请求<br/>屏蔽图片附件类目录php执行权限<br/>防止webshell上传<br/></div><br/><br/>正文:<br/>1 下载luajit 2.0并安装<br/><a href="http://luajit.org/download.html" target="_blank">http://luajit.org/download.html</a><br/>直接使用源码make && make install<br/>所以lib和include是直接放在/usr/local/lib和usr/local/include<br/><div class="code"><br/>wget http://luajit.org/download/LuaJIT-2.0.3.tar.gz<br/>tar -zxvf LuaJIT-2.0.3.tar.gz<br/>cd LuaJIT-2.0.3<br/>make<br/>make install<br/>cd ../<br/></div><br/><br/><br/>2 下载nginx源码解压<br/>wget&nbsp;&nbsp;<a href="http://nginx.org/download/nginx-1.7.6.tar.gz" target="_blank">http://nginx.org/download/nginx-1.7.6.tar.gz</a><br/>注意版本号，如果机子上已经装了nginx，不想升级的话，请使用/usr/local/nginx/sbin/nginx -v 来查看版本号tar -zxvf&nbsp;&nbsp;nginx-1.2.7.tar.gz<br/><div class="code"><br/>wget http://nginx.org/download/nginx-1.7.6.tar.gz<br/></div><br/><br/>3&nbsp;&nbsp;下载ngx_devel_kit解压<br/><a href="https://github.com/simpl/ngx_devel_kit/tags" target="_blank">https://github.com/simpl/ngx_devel_kit/tags</a><br/><div class="code"><br/>wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz --no-check-certificate<br/>tar -zxvf&nbsp;&nbsp;v0.2.19 <br/></div><br/><br/>4&nbsp;&nbsp;下载nginx_lua_module解压<br/><a href="https://github.com/chaoslawful/lua-nginx-module/tags" target="_blank">https://github.com/chaoslawful/lua-nginx-module/tags</a><br/><div class="code"><br/>wget https://github.com/openresty/lua-nginx-module/archive/v0.9.13rc1.tar.gz --no-check-certificate<br/>tar -zxvf v0.9.13rc1<br/></div><br/><br/>5 进入nginx源码文件夹<br/><div class="code"><br/>tar -zxvf nginx-1.7.6.tar.gz<br/>cd nginx-1.7.6<br/></div><br/><br/>6 导入环境变量，编译<br/><br/><div class="code"><br/>export LUAJIT_LIB=/usr/local/lib<br/>export LUAJIT_INC=/usr/local/include/luajit-2.0<br/>./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/root/soft/ngx_devel_kit-0.2.19 --add-module=/root/soft/lua-nginx-module-0.9.13rc1 --with-ld-opt=&quot;-Wl,-rpath,$LUAJIT_LIB&quot;<br/>make -j2<br/>make install<br/></div><br/><br/>7 请提前新建/data/logs/hack/目录攻击日志，并赋予nginx用户对该目录的写入权限。<br/>www账户是跑nginx和php-fpm<br/><div class="code"><br/>mkdir -p /data/logs/hack/<br/>chown -R www:www /data/logs/hack/<br/>chmod -R 755 /data/logs/hack/<br/></div><br/><br/>8 安装ngx_lua_waf模块<br/><br/><div class="code"><br/>wget https://github.com/loveshell/ngx_lua_waf/archive/master.zip --no-check-certificate<br/>unzip master<br/>cd ngx_lua_waf-master/<br/>mkdir /usr/local/nginx/conf/waf<br/>mv * /usr/local/nginx/conf/waf/<br/></div><br/><br/>然后在nginx.conf里的http配置里添加<br/><br/><div class="code"><br/>lua_package_path &quot;/usr/local/nginx/conf/waf/?.lua&quot;;<br/>lua_shared_dict limit 10m;<br/>init_by_lua_file&nbsp;&nbsp;/usr/local/nginx/conf/waf/init.lua; <br/>access_by_lua_file /usr/local/nginx/conf/waf/waf.lua;<br/></div><br/>配置config.lua里的waf规则目录(一般在waf/conf/目录下)<br/><div class="code"><br/>&nbsp;&nbsp;&nbsp;&nbsp;RulePath = &quot;/usr/local/nginx/conf/waf/wafconf/&quot;<br/></div><br/>绝对路径如有变动，需对应修改<br/>注意:waf.lua一定要放在/usr/local/nginx-help/conf/waf.lua 已经他的子目录.否则会报500错误.<br/><br/><div class="code"><br/>/usr/local/nginx/sbin/nginx -t<br/></div><br/><br/><div class="code"><br/>ps -ef &#124; grep &quot;nginx: master process&quot; &#124; grep -v &quot;grep&quot; &#124; awk -F &#039; &#039; &#039;&#123;print $2&#125;&#039;<br/></div><br/>9 过滤配置说明:<br/>过滤规则在wafconf下，可根据需求自行调整，每条规则需换行,或者用&#124;分割<br/>&nbsp;&nbsp;&nbsp;&nbsp;global是全局过滤文件，里面的规则对post和get都过滤<br/>&nbsp;&nbsp;&nbsp;&nbsp;get是只在get请求过滤的规则<br/>&nbsp;&nbsp;&nbsp;&nbsp;post是只在post请求过滤的规则<br/>&nbsp;&nbsp;&nbsp;&nbsp;whitelist是白名单，里面的url匹配到不做过滤<br/>&nbsp;&nbsp;&nbsp;&nbsp;user-agent是对user-agent的过滤规则<br/><br/>为了不返回一些无用给用户直接把注入测试防护返回信息改为http 403状态,修改/usr/local/nginx-help/conf/init.lua<br/><div class="code"><br/>&nbsp;&nbsp;function check()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.header.content_type = &quot;text/html&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--ngx.print(&quot;403&quot;)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ngx.exit(403)<br/>&nbsp;&nbsp;end<br/></div><br/>注意:每次更改waf.lua代码需要把nginx reload一下!<br/>Tags - <a href="http://www.dzhope.com/tags/nginx/" rel="tag">nginx</a> , <a href="http://www.dzhope.com/tags/%25E9%2598%25B2%25E7%2581%25AB%25E5%25A2%2599/" rel="tag">防火墙</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论]  让 Nginx 支持 WAF 防护功能web防火墙 ]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>