high performance WAF platform with Naxsi and HAProxy

本文涉及的产品
Web应用防火墙 3.0,每月20元额度 3个月
简介: http://blog.exceliance.fr/2012/10/16/high-performance-waf-platform-with-naxsi-and-haproxy/Syn...

http://blog.exceliance.fr/2012/10/16/high-performance-waf-platform-with-naxsi-and-haproxy/

Synopsis

I’ve already described WAF in a previous article, where I spoke about WAF scalability with apache and modsecurity.
One of the main issue with Apache and modsecurity is the performance. To address this issue, an alternative exists:naxsi, a Web Application Firewall module fornginx.

So using Naxsi and HAProxy as a load-balancer, we’re able to build a platform which meets the following requirements:

  • Web Application Firewall: achieved by Apache andmodsecurity
  • High-availability: application server and WAF monitoring, achieved byHAProxy
  • Scalability: ability to adapt capacity to the upcoming volume of traffic, achieved byHAProxy
  • DDOS protection: blind and brutal attacks protection, slowloris protection, achieved byHAProxy
  • Content-Switching: ability to route only dynamic requests to the WAF, achieved byHAProxy
  • Reliability: ability to detect capacity overusage, this is achieved byHAProxy
  • Performance: deliver response as fast as possible, achieved by the whole platform

The picture below provides a better overview:

The LAB platform is composed by 6 boxes:

  • 2 ALOHA Load-Balancers (could be replaced by HAProxy 1.5-dev)
  • 2 WAF servers: CentOS 6.0, nginx and Naxsi
  • 2 Web servers: Debian + apache + PHP + dokuwiki

Nginx and Naxsi installation on CentOS 6

Purpose of this article is not to provide such procedue. So please read this wiki article which summarizeshow to install nginx and naxsi on CentOS 6.0.

Diagram

The diagram below shows the platform with HAProxy frontends (prefixed byft_) and backends (prefixed by bk_). Each farm is composed by 2 servers.

Configuration

Nginx and Naxsi


Configure nginx as a reverse-proxy which listen in bk_waf and forward traffic to ft_web. In the mean time, naxsi is there to analyze the requests.
01 server {
02  proxy_set_header Proxy-Connection "";
03  listen       192.168.10.15:81;
04  access_log  /var/log/nginx/naxsi_access.log;
05  error_log  /var/log/nginx/naxsi_error.log debug;
06  
07  location / {
08   include    /etc/nginx/test.rules;
09   proxy_pass http://192.168.10.2:81/;
10  }
11  
12  error_page 403 /403.html;
13  location = /403.html {
14   root /opt/nginx/html;
15   internal;
16  }
17  
18  location /RequestDenied {
19   return 403;
20  }
21 }

HAProxy Load-Balancer configuration


The configuration below allows the following advanced features:
  • DDOS protection on the frontend
  • abuser or attacker detection in bk_waf and blocking on the public interface (ft_waf)
  • Bypassing WAF when overusage or unavailable
001 ######## Default values for all entries till next defaults section
002 defaults
003   option  http-server-close
004   option  dontlognull
005   option  redispatch
006   option  contstats
007   retries 3
008   timeout connect 5s
009   timeout http-keep-alive 1s
010   # Slowloris protection
011   timeout http-request 15s
012   timeout queue 30s
013   timeout tarpit 1m          # tarpit hold tim
014   backlog 10000
015  
016 # public frontend where users get connected to
017 frontend ft_waf
018   bind 192.168.10.2:80 name http
019   mode http
020   log global
021   option httplog
022   timeout client 25s
023   maxconn 10000
024  
025   # DDOS protection
026   # Use General Purpose Couter (gpc) 0 in SC1 as a global abuse counter
027   # Monitors the number of request sent by an IP over a period of 10 seconds
028   stick-table type ip size 1m expire 1m store gpc0,http_req_rate(10s),http_err_rate(10s)
029   tcp-request connection track-sc1 src
030   tcp-request connection reject if { sc1_get_gpc0 gt 0 }
031   # Abuser means more than 100reqs/10s
032   acl abuse sc1_http_req_rate(ft_web) ge 100
033   acl flag_abuser sc1_inc_gpc0(ft_web)
034   tcp-request content reject if abuse flag_abuser
035  
036   acl static path_beg /static/ /dokuwiki/images/
037   acl no_waf nbsrv(bk_waf) eq 0
038   acl waf_max_capacity queue(bk_waf) ge 1
039   # bypass WAF farm if no WAF available
040   use_backend bk_web if no_waf
041   # bypass WAF farm if it reaches its capacity
042   use_backend bk_web if static waf_max_capacity
043   default_backend bk_waf
044  
045 # WAF farm where users' traffic is routed first
046 backend bk_waf
047   balance roundrobin
048   mode http
049   log global
050   option httplog
051   option forwardfor header X-Client-IP
052   option httpchk HEAD /waf_health_check HTTP/1.0
053  
054   # If the source IP generated 10 or more http request over the defined period,
055   # flag the IP as abuser on the frontend
056   acl abuse sc1_http_err_rate(ft_waf) ge 10
057   acl flag_abuser sc1_inc_gpc0(ft_waf)
058   tcp-request content reject if abuse flag_abuser
059  
060   # Specific WAF checking: a DENY means everything is OK
061   http-check expect status 403
062   timeout server 25s
063   default-server inter 3s rise 2 fall 3
064   server waf1 192.168.10.15:81 maxconn 100 weight 10 check
065   server waf2 192.168.10.16:81 maxconn 100 weight 10 check
066  
067 # Traffic secured by the WAF arrives here
068 frontend ft_web
069   bind 192.168.10.2:81 name http
070   mode http
071   log global
072   option httplog
073   timeout client 25s
074   maxconn 1000
075   # route health check requests to a specific backend to avoid graph pollution in ALOHA GUI
076   use_backend bk_waf_health_check if { path /waf_health_check }
077   default_backend bk_web
078  
079 # application server farm
080 backend bk_web
081   balance roundrobin
082   mode http
083   log global
084   option httplog
085   option forwardfor
086   cookie SERVERID insert indirect nocache
087   default-server inter 3s rise 2 fall 3
088   option httpchk HEAD /
089   # get connected on the application server using the user ip
090   # provided in the X-Client-IP header setup by ft_waf frontend
091   source 0.0.0.0 usesrc hdr_ip(X-Client-IP)
092   timeout server 25s
093   server server1 192.168.10.11:80 maxconn 100 weight 10 cookie server1 check
094   server server2 192.168.10.12:80 maxconn 100 weight 10 cookie server2 check
095  
096 # backend dedicated to WAF checking (to avoid graph pollution)
097 backend bk_waf_health_check
098   balance roundrobin
099   mode http
100   log global
101   option httplog
102   option forwardfor
103   default-server inter 3s rise 2 fall 3
104   timeout server 25s
105   server server1 192.168.10.11:80 maxconn 100 weight 10 check
106   server server2 192.168.10.12:80 maxconn 100 weight 10 check

Detecting attacks


On the load-balancer


The ft_waf frontend stick table tracks two information: http_req_rate and http_err_rate which are respectively the http request rate and the http error rate generated by a single IP address.
HAProxy would automatically block an IP which has generated more than 100 requests over a period of 10s or 10 errors (WAF detection 403 responses included) in 10s. The user is blocked for 1 minute as long as he keeps on abusing.
Of course, you can setup above values to whatever you need: it is fully flexible.

To know the status of IPs in your load-balancer, just run the command below:

echo show table ft_waf | socat /var/run/haproxy.stat - 
# table: ft_waf, type: ip, size:1048576, used:1
0xc33304: key=192.168.10.254 use=0 exp=4555 gpc0=0 http_req_rate(10000)=1 http_err_rate(10000)=1

Note: The ALOHA Load-balancer does not provide watch tool, but you can monitor the content of the table in live with the command below:

while true ; do echo show table ft_waf | socat /var/run/haproxy.stat - ; sleep 2 ; clear ; done

On the Waf


Every Naxsi error log appears in /var/log/nginx/naxsi_error.log. IE:
2012/10/16 13:40:13 [error] 10556#0: *10293 NAXSI_FMT: ip=192.168.10.254&server=192.168.10.15&uri=/testphp.vulnweb.com/artists.php&total_processed=3195&total_blocked=2&zone0=ARGS&id0=1000&var_name0=artist, client: 192.168.10.254, server: , request: "GET /testphp.vulnweb.com/artists.php?artist=0+div+1+union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1%2C2%2Ccurrent_user HTTP/1.1", host: "192.168.10.15:81"

Naxsi log line is less obvious than modsecurity one. The rule which matched os provided by the argumentidX=abcde.
No false positive during the test, I had to build a request to make Naxsi match it:) .

conclusion


Today, we saw it’s easy to build a scalable and performing WAF platform in front of any web application.
The WAF is able to communicate to HAProxy which IPs to automatically blacklist (throuth error rate monitoring), which is convenient since the attacker won’t bother the WAF for a certain amount of time ;)
The platform allows to detect WAF farm availability and to bypass it in case of total failure, we even saw it is possible to bypass the WAF for static content if the farm is running out of capacity. Purpose is to deliver a good end-user experience without dropping too much the security.
Note that it is possible to route all the static content to the web servers (or a static farm) directly, whatever the status of the WAF farm.
This make me say that the platform is fully scallable and flexible.
Thanks to HAProxy, the architecture is very flexible: I could switch my apache + modexurity to nginx + naxsi with no issues at all :) This could be done as well for any third party waf appliances.
Note that I did not try any naxsi advanced features like learning mode and the UI as well.

Related links

Links


目录
相关文章
|
应用服务中间件 nginx
WAF实战nginx+naxsi(转载)
https://www.cnblogs.com/stone-dan-dan/p/stone1.html 第一部分---安装nginx+naxsi       首先,我说一下我的环境是ubuntu14.04LTS版本,并且是在root用户下进行操作的,省去了很多麻烦,至于其他的版本也应该是大同小异的,区别也极有可能只是命令的不通而已。
1613 0
|
云安全 负载均衡 网络协议
阿里云waf简介和如何配置​
阿里云WAF(Web应用程序防火墙)是一种高效、智能的云安全服务,旨在保护Web应用程序免受各种网络攻击的威胁。它可防止诸如SQL注入、跨站点脚本(XSS)和跨站点请求伪造(CSRF)等攻击,有效保障了Web应用程序的安全性与稳定性。 阿里云WAF在Web应用程序与互联网之间构建一道安全屏障,通过拦截和检测恶意流量,防止攻击者对您的Web应用程序进行攻击。它不仅覆盖了常见的网络攻击类型,还针对新兴的攻击手段进行了防护设计,确保您的Web应用程序在面对各种威胁时都能得到全方位的保护。
|
4月前
|
安全 API 开发者
|
弹性计算 缓存 运维
【运维知识进阶篇】用阿里云部署kod可道云网盘(DNS解析+CDN缓存+Web应用防火墙+弹性伸缩)(三)
【运维知识进阶篇】用阿里云部署kod可道云网盘(DNS解析+CDN缓存+Web应用防火墙+弹性伸缩)(三)
215 0
|
6月前
|
SQL 监控 安全
【阿里云云原生专栏】云原生安全体系构建:阿里云云防火墙与WAF的应用
【5月更文挑战第27天】阿里云云防火墙和WAF是构建云原生安全体系的关键产品,提供网络、主机和Web应用多维度防护。云防火墙采用分布式架构抵御网络攻击,确保应用安全稳定;WAF专注Web应用安全,防止SQL注入、XSS和DDoS等威胁。简单部署配置,结合使用可实现全面安全防护,提升企业云上应用安全性,保障业务安全运行。未来,阿里云将持续强化云原生安全建设。
336 1
|
6月前
|
云安全 数据采集 安全
阿里云安全产品,Web应用防火墙与云防火墙产品各自作用简介
阿里云提供两种关键安全产品:Web应用防火墙和云防火墙。Web应用防火墙专注网站安全,防护Web攻击、CC攻击和Bot防御,具备流量管理、大数据防御能力和简易部署。云防火墙是SaaS化的网络边界防护,管理南北向和东西向流量,提供访问控制、入侵防御和流量可视化。两者结合可实现全面的网络和应用安全。
阿里云安全产品,Web应用防火墙与云防火墙产品各自作用简介
|
应用服务中间件
阿里云的WAF(Web应用防火墙)3.0的虚拟代理
阿里云的WAF(Web应用防火墙)3.0的虚拟代理
190 2
|
安全 网络安全
阿里云WAF
阿里云WAF
413 2
|
弹性计算 缓存 运维
【运维知识进阶篇】用阿里云部署kod可道云网盘(DNS解析+CDN缓存+Web应用防火墙+弹性伸缩)(二)
【运维知识进阶篇】用阿里云部署kod可道云网盘(DNS解析+CDN缓存+Web应用防火墙+弹性伸缩)(二)
200 0