OpenResty®是一个结合了Nginx与Lua的高性能Web平台,其内部集成了大量精良的Lua库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态Web应用、Web服务和动态网关。OpenResty®通过汇聚各种设计精良的Nginx模块(主要由OpenResty团队自主开发),从而将Nginx有效地变成一个强大的通用Web应用平台。这样,Web开发人员和系统工程师可以使用Lua脚本语言调动Nginx支持的各种C以及Lua模块,快速构造出足以胜任10K乃至1000K以上单机并发连接的高性能Web应用系统。OpenResty®的目标是让你的Web服务直接跑在Nginx服务内部,充分利用Nginx的非阻塞I/O模型,不仅仅对HTTP客户端请求,甚至于对远程后端诸如MySQL、PostgreSQL、Memcached以及Redis等都进行一致的高性能响应。
Openresty安装以下采用进行部署
1.安装依赖开发组件
•pcre-devel:扩展的正则表达式引擎,为了使Nginx处理更复杂的正则表达式机制•openssl-devel:--with-http_ssl_module使用该模块必需装openssl库,来实现http支持https协议•zlib-devel:zlib库是网络通信压缩库,ngx_http_gzip_module(gzip压缩模块)所必需的•readline-devel:readline是安装Openresty所必须的依赖包
yuminstallgcc-c++libtoolgmakemake-yyuminstallpcrepcre-developensslopenssl-develzlibzlib-develreadlinereadline-devel-y
2.创建nginx用户组Nginx的Master主进程以root用户身份运行,而worker子进程我们指定它为nginx用户运行
groupaddnginxuseradd-d/home/nginx-gnginx-s/sbin/nginxnginx
3.下载编译并安装Openresty
wget\--sbin-path=/usr/local/openresty/nginx/sbin/nginx\--conf-path=/usr/local/openresty/nginx/conf/\--pid-path=/usr/local/openresty/nginx/run/\--error-log-path=/usr/local/openresty/nginx/logs/\--http-log-path=/usr/local/openresty/nginx/logs/\--user=nginx\--group=nginx\--with-pcre\--with-stream\--with-threads\--with-file-aio\--with-http_v2_module\--with-http_ssl_module\--with-http_realip_module\--with-http_gzip_static_module\--with-http_stub_status_modulegamkegmakeinstall
4.为Openresty添加环境变量
vim/etc//=/usr/local/openresty/bin:$PATH
5.添加location配置确认结合了Nginx与Lua的Openresty部署成功
location/hello{default_typetext/html;content_by_lua_block{("HelloWorld")Cookie策略文件-rw-r--r--1rootroot7497月2709:30白名单URL策略文件-rw-r--r--1rootroot07月2709:30异常UserAgent策略文件-rw-r--r--1rootroot3077月2709:30异常POST参数策略文件-rw-r--r--1rootroot07月2709:57:signalprocessstarted2020/07/2715:39:38[alert]27311模拟网站下载curl'HTTrack'htmlheadmetahttp-equiv="Content-Type"content="text/html;charset=utf-8"/metahttp-equiv="Content-Language"content="zh-cn"/title网站防火墙/title/headbodyh1align="center"欢迎白帽子进行授权安全测试,安全漏洞请联系QQ:1111111。/body/html跟随配置添加到最后(HTTrack|harvest|audit|dirbuster|pangolin|nmap|sqln|-scan|hydra|Parser|libwww|BBBike|sqlmap|w3af|owasp|Nikto|fimap|havij|PycURL|zmeu|BabyKrokodil|netsparker|httperf|bench|Chrome)然后重启Openrestry,通过Chrome浏览器进行访问
-w1474
如上所示全部命中了WAF的规则
异常Get参数策略配置需要在配置中开启config_url_args_check="on"参数
默认封锁了如下:
\.\./\:\$\$\{select.+(from|limit)(?:(union(.*?)select))having|rongjitestsleep\((\s*)(\d*)(\s*)\)benchmark\((.*)\,(.*)\)base64_decode\((?:from\W+information_schema\W)(?:(?:current_)user|database|schema|connection_id)\s*\((?:etc\/\W*passwd)into(\s+)+(?:dump|out)file\s*group\s+by.+\((?:define|eval|file_get_contents|include|require|require_once|shell_exec|phpinfo|system|passthru|preg_\w+|execute|echo|print|print_r|var_dump|(fp)open|alert|showmodaldialog)\(xwork\.MethodAccessor(gopher|doc|php|glob|file|phar|zlib|ftp|ldap|dict|ogg|data)\:\/java\.lang\$_(GET|post|cookie|files|session|env|phplib|GLOBALS|SERVER)\[\(iframe|script|body|img|layer|div|meta|style|base|object|input)(onmouseover|onerror|onload)\=我们进行访问,进行匹配
curl''htmlheadmetahttp-equiv="Content-Type"content="text/html;charset=utf-8"/metahttp-equiv="Content-Language"content="zh-cn"/title网站防火墙/title/headbodyh1align="center"欢迎白帽子进行授权安全测试,安全漏洞请联系QQ:1111111。/body/html
我们也可以根据自己需求去配置,如下最后添加abcops
\.\./\:\$\$\{select.+(from|limit)(?:(union(.*?)select))having|rongjitestsleep\((\s*)(\d*)(\s*)\)benchmark\((.*)\,(.*)\)base64_decode\((?:from\W+information_schema\W)(?:(?:current_)user|database|schema|connection_id)\s*\((?:etc\/\W*passwd)into(\s+)+(?:dump|out)file\s*group\s+by.+\((?:define|eval|file_get_contents|include|require|require_once|shell_exec|phpinfo|system|passthru|preg_\w+|execute|echo|print|print_r|var_dump|(fp)open|alert|showmodaldialog)\(xwork\.MethodAccessor(gopher|doc|php|glob|file|phar|zlib|ftp|ldap|dict|ogg|data)\:\/java\.lang\$_(GET|post|cookie|files|session|env|phplib|GLOBALS|SERVER)\[\(iframe|script|body|img|layer|div|meta|style|base|object|input)(onmouseover|onerror|onload)\=abcops然后我们进行访问
-w1270
异常POST参数策略配置需要在中开启config_post_check="on"选项
默认POST请求封禁如下,POST封禁内容与GET相似
\.\./select.+(from|limit)(?:(union(.*?)select))having|rongjitestsleep\((\s*)(\d*)(\s*)\)benchmark\((.*)\,(.*)\)base64_decode\((?:from\W+information_schema\W)(?:(?:current_)user|database|schema|connection_id)\s*\((?:etc\/\W*passwd)into(\s+)+(?:dump|out)file\s*group\s+by.+\((?:define|eval|file_get_contents|include|require|require_once|shell_exec|phpinfo|system|passthru|preg_\w+|execute|echo|print|print_r|var_dump|(fp)open|alert|showmodaldialog)\(xwork\.MethodAccessor(gopher|doc|php|glob|file|phar|zlib|ftp|ldap|dict|ogg|data)\:\/java\.lang\$_(GET|post|cookie|files|session|env|phplib|GLOBALS|SERVER)\[\(iframe|script|body|img|layer|div|meta|style|base|object|input)(onmouseover|onerror|onload)\=
直接对POST策略进行提交请求,通过curl-XPOST来进行提交POST请求
curl-XPOST''htmlheadmetahttp-equiv="Content-Type"content="text/html;charset=utf-8"/metahttp-equiv="Content-Language"content="zh-cn"/title网站防火墙/title/headbodyh1align="center"欢迎白帽子进行授权安全测试,安全漏洞请联系QQ:1111111。/body/html
如上命中规则,我们查看Openrestry日志,查看是否为POST请求
tail-1/usr/local/openresty/nginx/logs/[27/Jul/2020:18:21:32+0800]"POST/hello?aa=selectidfrommysqlHTTP/1.1"403313"-""curl/7.29.0"
☆END☆