Target
Configure proxying of HTTP and HTTPS traffic to the protected application via WAF.
Prerequisites
WAF installed in reverse proxy mode;
Secured web application accessible with WAF. Everywhere in the text below app_ip is its address, app_port is its port. Below it is suggested to use the vulnerable dvwa application on the same server where the WAF is installed. You can use any other web application instead;
SSH client (for example, Putty).
Result
The successful implementation of this work is the proxying of transactions to the protected application through the WAF.
Preparing a protected web application
Installing the DVWA web application on the WAF server.
sudo docker pull vulnerables/web-dvwa
Running a web application on port 8080.
sudo docker run --rm -d -p 8080:80 --name dvwa vulnerables/web-dvwa
For DVWA application:
app_ip = 127.0.0.1
app_port = 8080 login: admin password: password
To access a web application named dvwa, you need to add a line to the hosts file (client machine) to resolve the domain name locally: IP_WAF dvwa
The hosts file is located in the following paths:
On Unix systems - /etc/hosts
On Windows systems - C:\Windows\System32\drivers\etc\hosts
Procedure
General settings (optional)
Increase the upload file size limit in /etc/ibatyr-nginx/user/http.conf.
client_max_body_size 1024m;
Add the upstream HTTP proxy server address(es) to the trusted addresses in /etc/ibatyr-nginx/user/http.conf.
set_real_ip_from proxy_ip_address;
Disable LRB-CACHE in /etc/ibatyr-nginx/user/server.conf.
set $LRB_CACHE 0;
Proxying HTTP traffic.
Connect via ssh (putty) to the WAF server.
Make sure that the WAF server has network access to the protected application.
curl -vk http://app_ip:app_port
Delete the default configuration file ibatyr-nginx.
sudo rm /etc/ibatyr-nginx/sites-enabled/default
Open the ibatyr-nginx configuration file for editing in any text editor with superuser rights. For example,
sudo vim /etc/ibatyr-nginx/sites-enabled/dvwa
Enter settings for proxying HTTP traffic to the backend of the protected application. Example configuration file contents:
server { include static/server.conf; listen 80; server_name dvwa; # ibatyr WAF configuration. set $BACKEND http://app_ip:app_port; location / { include static/waf.conf; } }
After making changes, you need to check the correctness of the changes made and, making sure that there are no errors, apply the ibatyr-nginx configuration.
sudo ibatyr-nginx test sudo ibatyr-nginx reload
If there are no errors, after loading the new configuration, the port on which the ibatyr-nginx service listens for incoming connections from web application clients should be open. Figure 1 shows an example of the output of the ss -4lnt command.
Figure 1 - Command output
To check the settings you have made, you can make a request to the WAF using a browser or the console curl web client. An example of a request executed on the WAF server command line.
curl -H"host:dvwa" -v localhostTo diagnose problems, see APPENDIX 1. Guidelines for diagnosing network connection problems.
HTTPS traffic termination (optional)
Create a folder to store certificates and keys.
sudo mkdir /etc/ibatyr-nginx/ssl
Generate or receive from the application owner a key and certificate for SSL termination. An example command to generate a key and a self-signed certificate.
openssl req -x509 -newkey rsa:4096 -keyout key.pem -nodes -out cert.pem -days 365
Figure 2 shows the output of this command.
Figure 2 - Command output
Place the key and certificate in the created folder.
sudo mv cert.pem key.pem /etc/ibatyr-nginx/sslCreate another ibatyr-nginx configuration file.
sudo vim /etc/ibatyr-nginx/sites-enabled/dvwa_sslExample configuration file contents:
server { include static/server.conf; listen 443 ssl; ssl_certificate /etc/ibatyr-nginx/ssl/cert.pem; ssl_certificate_key /etc/ibatyr-nginx/ssl/key.pem; server_name dvwa; # iBatyr WAF configuration. set $BACKEND http://app_ip:app_port; location / { include static/waf.conf; } }Apply configuration.
sudo systemctl reload ibatyr-nginx.serviceCheck application availability via WAF.
curl -k -v -H"host: dvwa" https://localhost:443To diagnose problems, see APPENDIX 1. Guidelines for diagnosing network connection problems.
APPENDIX 1: Tips for diagnosing network connection problems
If the application is not accessible via WAF, it is recommended to check the correctness of the following aspects:
Network addressing.
ip a
Name resolution.
host example.com
Routing.
ip ro
Application availability directly.
curl -v http://example.com
curl -k -v https://example.com
Status of the ibatyr-nginx service.
sudo systemctl status ibatyr-nginx.service
List of open ports.
ss -lnt
sudo ss -4lntp
There are errors in the ibatyr-nginx service log.
sudo journalctl -xefu ibatyr-nginx
There are errors in the ibatyr-nginx configuration.
sudo ibatyr-nginx test
Link to a description of how nginx parses requests (if there are problems with specifying the web application name in the nginx configuration).

