What is a WAF and how to use it? We'll demonstrate this using a vulnerable web application as an example.

META

Activist
SUPREME
MEMBER
Joined
Mar 1, 2026
Messages
118
Reaction score
378
Deposit
0$
Over the past few years, web application security

has become a key issue in IT. For companies, system stability is crucial to their reputation and the avoidance of unnecessary costs. Annual statistics from large information security companies indicate an increase in the number and quality of attacks. In an earlier article , I discussed protecting web applications using IDPS-class systems. Today, I'd like to share information on working with a WAF. In this article, I'll begin with theory and move on to configuration. We'll be running two servers, one for attack and the other for protection using a WAF. I hope this article will be an accessible introduction for engineers who haven't previously considered working with a WAF due to its unfamiliarity with this type of system. Interested? Then welcome!

If you've already set up a WAF, please share your experience in the comments! Tell us about the system's strengths and weaknesses.

Use the navigation if you don't want to read the full text:

Where it all comes from: web service vulnerabilities
Introduction to open-appsec
Testing open-appsec
Conclusions

Where the roots come from: web service vulnerabilities​


First, let's define what we'll be working with. As we know, information security incidents follow this chain: System → Intruder → Threat → Vulnerability → Vulnerability Exploitation.

  • The system is our potential web application.
  • The offender is the criminal.
  • A threat is the potential for harm to our system.
  • A vulnerability is a flaw in a system that can be exploited to implement a threat.
  • Vulnerability exploitation is the use of an exploit to implement a threat.

The emergence of a web application vulnerability is usually not a sudden problem, but rather a subtle issue waiting to be discovered. There are several reasons why it occurs.

Reason 1. Poor application architecture​


If the application is monolithic or consists of microservices that are not separated by a DMZ/do not validate transmitted data, then impacting some components will affect the operation of others.

Reason 2. The architecture simply does not take information security issues into account​


The most common case is a lack of validation of the data being sent. This problem can lead to a wide range of injections—essentially, to any imaginable outcome.

Reason 3. Intentional introduction of vulnerabilities​


Untrustworthy employees/partners can also cause vulnerabilities in service components. There are even "Blockbuster" stories where particularly sophisticated hacktivists, guided by the principle of "Keep your friends close, but your enemies closer," infiltrate an organization and deliberately cause harm.

Reason 4. Insufficient competencies in the technology stack​


Developing applications without industry best practices, taking into account previous experience, or vendor recommendations can significantly reduce the information security level of the future application. It's advisable to have an expert on hand at all times—or outsource it .

Reason 5. Poor and insufficient tests​


Adding static and dynamic code analysis tools to your pipeline will definitely be beneficial. Moreover, it will help identify potential security issues before publishing the service.

Reason 6. Vulnerabilities in third-party services​


You can write a fairly secure application, but misconfigure the environment or fail to patch services in a timely manner. This will lead to exploitation of vulnerabilities. The posts at https://www.exploit-db.com/ confirm this.

Reason 7. Vulnerabilities in third-party services​


Attacks like SSRF can easily overtake your application if you handle requests to third-party resources without proper validation. On your end, exploits may appear as legitimate requests and not be blocked by any components.

If you're interested in how to categorize web vulnerabilities, check out the current edition of the OWASP Top 10 .

As you can see, the above-mentioned vulnerability causes give rise to all the hacking methods found in the OWASP rankings. Of course, it's impossible to control everything. Sooner or later, a vulnerability will appear at some point, waiting for its—at best—bug hunter. What to do? Spoiler alert: use a WAF!

WAF as a protector against vulnerability exploitation​


A WAF (Web Application Firewall) is a class of solutions that provides security at the Layer 7 level of the OSI model. In short, a WAF "looks" at application-layer protocols, such as HTTP, and—depending on the method content, URI, headers, and request body—decides whether to allow or reject the request.

The evolution of WAFs is usually described in three generations:

1. WAFs based on regular expressions,

2. WAFs with special expressions (tokens) for each type of attack,

3. WAFs based on machine learning methods.





Introduction to open-appsec​


There's a wealth of information online about popular open-source WAF systems. There are quite a few solutions, including ModSecurity, Coraza, IronBee, WebKnight, Shadow Daemon, OctopusWAF, and others. Some of these solutions haven't had their repositories updated in a while, but they're still actively used to protect a large number of web applications.

ModSecurity has been the most widely written about, so in this article, we'll look at one of the interesting alternatives: open-appsec from CheckPoint. Incidentally, this is a third-generation WAF technology: it uses an ML engine, which allows for quite effective protection with a minimal barrier to entry. So, sit back and relax.

The core functionality of open-appsec—a community version based on three WAG agents—is available for free and is well suited for protecting small web services. The solution is available for deployment in one of three scenarios: Kubernetes Ingress, Nginx Add-On, or Kong API Gateway Add-On—and is managed via a configuration file or a web portal .

Using a configuration file ensures complete autonomy, while the portal provides a user-friendly control panel and dashboards out of the box. Incidentally, a Google or GitHub account is sufficient for portal authorization. The community version includes the following security components:

  • Web Application Attack Mitigation (ML-based WAF),
  • Web API Attack Mitigation (ML-based WAF),
  • IPS Engine with Snort 3.0 Support,
  • Rate Limiting,
  • Custom Source Identifiers (IP and XFF only).

The following control options are also available:

  • Declarative code based deployment and configuration (DevOps style),
  • Web-based Management of Protected Assets & Policy (SaaS),
  • Web-based Event Management & Dashboards (SaaS),
  • Log Storage in the Cloud.

In this case, support is limited to the forum, but you can study the WAF deployment instructions for various scenarios and configurations for free. Detailed instructions are available in the official documentation .

Open-appsec testing​


Preparing the target scheme​


In this article, we'll look at how to improve the security of a web application using open-appsec. We'll deploy the vulnerable system in a Docker container using the repository , and the WAF on a separate virtual machine with Nginx installed. The attacker will be hosted on a separate server.

We'll use OWASP JuiceShop as the vulnerable web application. It's an excellent "colander" for testing, as it already contains vulnerabilities in the XSS, CSRF, SSRF, SSTI, XXE, SQL Injection, and other categories.

Creating a virtual machine

: 1. Log in to the my.selectel.ru control panel . From the Cloud Platform , navigate to Servers and click Create server . Configure the configuration to complete server creation.

d1d7766c4fec901eb4027e913e714527.png


2. Copy the server's IP address and password, connect via SSH, install Docker, and deploy the Docker image:

apt install docker.io -y



docker pull bkimminich/juice-shop



3. Let's launch the container, specifying the application access port 8080, and check the availability of the web application:

docker run --rm -p 8080:3000 bkimminich/juice-shop



curl http://localhost:8080



db29d61fb494f9cff12933fa859247ab.png


Creating an attacker host:

1. Log into the my.selectel.ru control panel . From the Cloud Platform , navigate to Images and click Create Image . Select Kali Linux, installed from the official website , as the image —it has all the necessary tools.

048296ef3c224ba65e43d7776e862c21.png


2. From the Cloud Platform , go to Servers and click Create Server . Select the uploaded image as the operating system:

19e1b78319df447963153bea3ac32ed9.png


Setting up a cloud firewall

. A vulnerable application has been published. To prevent anyone but us from hacking it, we'll restrict internet access using a cloud firewall. The solution is free for all cloud platform users.

1. Log in to the my.selectel.ru control panel . From the Cloud Platform, go to Firewalls and click Create Firewall . 2. Add Inbound traffic

rules to restrict access to the testbed. Allow connections only from trusted white IP addresses and reject all other requests.

33908c86160fc546f1ede1dd9ca77e47.png


Incoming traffic rules.

3. Only the NAT network in which the booth hosts are located is allowed to access the internet.

dcd74ff6ddf132a5eed58c2c9741aab7.png


Outgoing traffic rules.

Great—the setup is ready, we'll install the WAF later.

b7231f74feaa1e6447190af2d3ecaa8b.png


Analysis of application hacking techniques​


Now I'll show you how to exploit web application vulnerabilities included in the OWASP Top 10. JuiceShop has a section with a list of vulnerabilities—you can find it at /score-board.

29276f917a1ad0768b3b534564e5939b.png


The section with the list of vulnerabilities.

I'll take three tasks with different types of vulnerabilities and apply them to the application.

1. DOM XSS. In the search field, add an iframe tag with an alert:

<iframe src=”javascript”:alert(‘xss!’)”>



a95440c1fd219ce779de4fba8b94f1e7.png


We see that XSS is indeed present and ready for exploitation.

2. Login Admin. In the login form, we'll write a simple SQL injection to bypass authorization and log in as the administrator. As we can see, this wasn't particularly difficult:

6f776ec30832493748afb0f9e88d4bad.png


9927030ca6c7144eda82300b37f02442.png


3. Password Strength. Next, let's try logging in as the administrator without using injections—obviously, we'll need to brute-force the password. In Burpsuite, I intercept the login attempt and send it to Intruder:

91da805b40c0f26b05630d0c71f77357.png


I set the email parameter to [email protected], and I'll brute-force the password with a list of passwords . The value admin123 worked, allowing me to log in as an admin without injections:

7217f3b56e230b96f87d9bfcc9826dc1.png


As we can see, the application is breaking. Now we need to take steps to close these vulnerabilities using a WAF.

Setting up a WAF for protection​


The hacking techniques are clear. Let's imagine that the application developers, for obvious reasons, haven't patched the vulnerabilities, and the application can't be left in this state. In this case, open-asspec will help.

1. Similar to the application host, go to the my.selectel.ru control panel . From the Cloud Platform , go to Servers and click Create Server . Configure the configuration to complete the server creation.

2. Copy the server's IP address and password, connect via SSH. Install nginx:

apt install nginx -y



3. Publish the application via nginx. To do this, create a juiceshop.conf file and add the following configuration:

nano /etc/nginx/sites-available/juiceshop.conf



server {
listen 80;
server_name juiceshop.test;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://192.168.0.3:8080
}
location ~ /\. {
deny all;
}
}



4. Create a link to the configuration and install the open-appsec agent:

ln -s /etc/nginx/sites-available/juiceshop.conf /etc/nginx/sites-enabled/juiceshop.conf



wget https://downloads.openappsec.io/open-appsec-install && chmod +x open-appsec-install



open-appsec for NGINX, Kong and APISIX Installer v1.2245.1
For release notes and known limitations check:
Searching local NGINX…
nginx version found: 1.18.0-0ubuntu1.4
Downloading open-appsec NGINX attachment... stored in '/tmp/open-appsec'
Downloading open-appsec agent... stored in '/tmp/open-appsec'
Add your email to receive important security updates and so you can approach us with technical questions (enter IGNORE to ignore):
IGNORE
Installing open-appsec for NGINX...
Updating NGINX server configuration...
Starting open-appsec installation...
Successfully installed open-appsec...
For release notes and known limitations check: https://docs.openappsec.io/release-notes
For troubleshooting and support: https://openappsec.io/support



Now the open-appsec agent directories and files are accessible from /etc/cp/.

5. Next, you need to connect open-appsec to the portal. To do this, log in to the portal at https://www.openappsec.io and create an agent. Go to Getting Started , and in the Central Management section , select " Managed → Linux Embedded Agent Profile ." Enter "Test Agent" as the name, set "Manual" to "Agent Upgrade ," and select "NGINX application security" for Deployment :

3812d195d310a9e03557426ad808d36a.png


6. In the Management section, select "This management" as the method for setting policies and defining agents. Then, on the Nginx virtual machine, run two commands to connect the agent to the portal:

Uploading local policy configuration to cloud...
...
Registering open-appsec Nano Agent to Fog..
open-appsec Nano Agent is registered to https://inext-agents.cloud.ngen.checkpoint.com
Orchestration mode changed successfully



If everything went well, you'll receive a notification like this, and the Agents section will contain information about the instance:

61e76b5d1869b3ea7070f65841ad7938.png


Notification.

321352553d190c5aa6fb4c44898c0f2d.png


Instance information.

6. Next, enable log sending to the portal. A new resource appears in the Assets section after connecting the agent. Go to its properties. The linked profile is visible in General → Basic :

f16ba9a97362836ff666d8ed797684c4.png


In General → Web Application , it is specified that the agent will pass traffic to all resources published via HTTP:

eac08d250088d0fe759603f6660e92b4.png


In General → Source Identity and Trusted Sources, you can change the methods for determining connection sources to protected resources, as well as specify trusted sources:

921b4ee7685d5704aa9e2ba1d77c9d1a.png


In the Threat Prevention section , you can manage application protection components by specifying learning/detection or prevention mode. We'll leave everything in learning mode initially, and then change it to prevention. The Learn

section currently shows that there has been no traffic yet. In Rate Limit , you can set bandwidth limits for accessing the protected application, and in Triggers , a policy was created after connecting the agent. WAF training is performed using an ML model, which is available in Account → Download advanced ML model . If you need to add custom rules, you can do so in Assets → Custom rules and exceptions . Important: APIs can also be protected by creating separate resources in the Assets section . 7. Apply the policy to the agent. In the Behaviors section , you can configure custom response pages when access to the protected resource is denied by the open-appsec agent. In this policy, we enable sending logs to the portal, as well as advanced logging of URL path, URL query, HTTP headers, and Request body.







07b127039fb63894d623e007ac6e4954.png


8. Scan the application using scanners in Kali Linux.

Now you can access the vulnerable application from the Kali virtual machine in two ways: directly at http://192.168.0.3:8080 or through nginx with open-appsec ( http://juiceshop.test ).

To train the WAF, you need to generate different types of traffic. To do this, add the following entry to /etc/hosts on the Kali virtual machine:

192.168.0.100 juiceshop.test



Let's run a scan using nikto, an example of which I wrote about earlier in the article :

nikto -h http://juiceshop.test –output report.html



A message about the resource's start of training should appear in the web panel:

49484e6368399242f6e519f151a88430.png


You can track your progress in the Assets → Learn section . The ML engine training process itself is described in detail on the open-appsec website .

Additionally, we'll generate traffic using nmap and skipfish:

nmap -sV --script=http-enum juiceshop.test



skipfish -o res http://juiceshop.test



Meanwhile, during the scan, JuiceShop reports the successful completion of the tasks:

123452f8d1e9f2ff3a817f5920d3cb1b.png


Next, I'll run a scan using the wonderful commix tool:

a7949fecd63056519a314398dff4f227.png


The same can be done from the console:

commix -u http://juiceshop.test --level 3



As a result, the WAF has certain statistics that can be further developed:

9b9005512b6679c87454ea100f50fdeb.png


Re-testing of vulnerability exploitation​


It's time to repeat the same attacks on the trained WAF. First, in the Assets → Threat Prevention section , switch the mode from Learn/Detect to Prevent for the Web Attacks and Intrusion Prevention parameters . Next, apply the policy and re-attack the test application via http://juiceshop.test and observe the results.

1. DOM XSS. The WAF detects XSS in the POST request:

13dbc89655a20b5e4d7477bc3d3ce037.png


2. Login Admin. Repeated attempts to bypass authorization are unsuccessful, and the following events have appeared in the Monitoring section:

9226614673fd0e0075d0ebbbea1f5896.png


The incident card contains a lot of useful information, including the source, the payload used, and the attack indicator that was triggered:

667057138320dd33894717d0a92bfb7c.png


Attempts to bypass the WAF using alternative requests are also blocked:

53b64fd09cfbf86a91988de7cd5cac5e.png


e609a752969ae2c8785e5176455faebc.png


f6834865ad4244a72783d7e087f65889.png


Attempts to transmit payloads in BASE-64 are also blocked. The WAF decodes the payload and also detects the attack:

c79f575deb53834e6351319e76790898.png


Open-appsec periodically requests clarification on whether requests from sources are classified as legitimate or malicious activity:

a295b9102cb629e5347a671acae144ec.png


This allows for more efficient training with fewer false positives.

3. Password Strength. To prevent brute-force attacks, you can, for example, create a rule in the Rate Limit section:

726b2031b311ce5399562fd37524aa59.png


Collecting statistics on repelled attacks​


For clarity, I'll run a rescan using Commix with the WAF running in Prevent mode. If I sniff incoming traffic on the interfaces of the server running the WAF and the server running the containerized application, I'll see that ARP requests aren't reaching the second host.

You can view statistics on repelled attacks in the Monitoring section of the portal :

d83ea28c217b325332012db51fecead4.png


As I mentioned above, you can find detailed information about the source, attack type, and payload used for each event. You can also manage the agent locally. Here are a few commands.

Viewing the policy:

open-appsec-ctl -vp



View logs:

open-appsec-ctl -vl



WAF bypass testing​


Great—the out-of-the-box WAF detects and mitigates attacks after a short training period (without high-quality signatures). But let's try bypassing it using waf-bypass .

1. Clone the repository and run the solution locally on Kali Linux:

# git clone https://github.com/nemesida-waf/waf_bypass.git /opt/waf-bypass/
# python3 -m pip install -r /opt/waf-bypass/requirements.txt
# python3 /opt/waf-bypass/main.py --host='example.com'



2. Launch waf-bypass:

python3 /opt/waf-bypass/main.py –host=’juiceshop.test’



3. We will conduct testing in two stages: Learn/Detect and Prevent modes.

20ab0e87ef659f72641391ad7d1f07cb.png


Learn/Detect Test.

07e6825143fcb9fe47d17f06f0ecea2e.png


Prevent test.

As you can see, there is some result, but it's not 100%. To fix this, you can switch to an advanced AI model , continue training the model, or add custom rules.

Conclusions​


As we can see, the open-appsec WAF doesn't guarantee 100% success out of the box, but it significantly improves the application's security. In most cases, the solution will address web application security flaws, but you can't afford to relax and neglect the architecture.

Open-appsec can add a fairly robust security layer with minimal effort. However, for more effective protection, fine-tuning is required, taking into account the set of allowed requests for your service.
 
Amazing tutorial, going to try this out right now. Very high-quality, well-written and easy-to-follow. Nice to see some quality content!

Great job!
 
Top Bottom