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
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.
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 thehttp 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 isblocked 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 astatic 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
naxsi
HTTP request flood mitigation
Use a load-balancer as a first row of defense against DDOS