About This Guide
Test Drives are automated reference deployments that use Azure templates to deploy key technologies in the Azure Cloud, following Azure best practices.
This Test Drive deployment guide describes how to deploy a three-tier web application on the Azure Cloud and use the Barracuda Web Application Firewall to protect it from targeted and automated attacks. This guide is for IT infrastructure architects, administrators, and DevOps professionals who are planning to deploy or migrate web applications on the Azure Cloud.
More businesses are moving their web applications to the cloud in droves. Indeed, web applications are usually the first move businesses make when migrating their workloads to the cloud. It’s a perfect example of how to take advantage of the cloud’s key benefits: scalability, high availability, and faster development cycle.
Web application firewalls like the Barracuda Web Application Firewall for Azure, which is available on the Azure Marketplace, helps secure your web applications by inspecting inbound web traffic to block SQL injections, cross-site scripting, malware uploads, and application DDoS and other attacks. It also inspects the responses from the back-end web servers for Data Loss Prevention (DLP). Combined with the isolation and additional scaling provided by Azure, this provides an ideal environment to host business-critical web applications that need to withstand malicious requests and high-volume traffic.
In this Test Drive guide, step-by-step, you will:
- Set up a Docker environment in Azure using Docker VM extension;
- Deploy BadStore.net (a typical 3-tier vulnerable web application) as a Docker image;
- Deploy Barracuda Web Application Firewall from Azure Marketplace to protect the BadStore.net web app.
Note: If you have already deployed your web application in Azure, you can skip the first two steps and go directly to step 3
There are multiple ways to deploy a web application in Azure. In the “Extra” section, we also show you how to create a Python-based web apps using Azure App Service, which you can protect with Barracuda Web Application Firewall following the same guidelines.
To successfully perform all steps in this Test Drive, you need:
- Active Azure account with Azure Bash Cloud Shell and Azure CLI 2.0
- PC, Mac, or Linux machine with a browser
1. Set Up Docker environment in Azure
Docker is a popular container management platform that allows you to quickly work with containers on Linux. In Azure, there are various ways you can deploy Docker containers according to your needs. Here we focus on using the Docker VM extension and Azure Resource Manager templates with the Azure CLI 2.0 to set up BadStore.net, a typical three-tier web application. This self-contained web application was built from the ground up with typical security mistakes to serve as a platform for demonstration, security training, evaluation, and testing purposes.
The Azure Cloud Shell is a free Bash shell that you can run directly on the Azure portal. It has the Azure CLI 2.0 preinstalled and configured to use with your account. Click the Cloud Shell button on the menu in the upper-right of the Azure Portal. The button launches an interactive shell that you can use to run the steps in this topic:
The Azure CLI commands in this Test Drive are used in the Bash shell. If your default Azure Cloud Shell is PowerShell make sure to switch to Bash before you start:
Now let’s use an ARM template to create an Ubuntu VM that uses the Azure Docker VM extension to install and configure the Docker host in Azure. First in Azure Cloud Shell use the following command to create a resource group named TMEDockerGroup in the westeurope region (you need to pick your own name for your resource group and the Azure region accordingly):
Next, deploy a VM that includes the Azure Docker VM extension from this Azure Resource Manager template on GitHub. Provide your own unique values for newStorageAccountName, adminUsername, adminPassword, and dnsNameForPublicIP as follows:
It takes a few minutes for the deployment to finish. Once the deployment is finished, you can then view details about the Docker host status with az vm show. The following example checks the status of the VM named myDockerVM (the default name from the template - don’t change this name) in the resource group named TMEDockerGroup:
When this command returns Succeeded, the deployment has finished and you can SSH to the VM in the following steps.
To view DNS name of your newly deployed service, use az vm show:
2. Deploy a Web Application in Azure using Docker Container
Now let’s create the BadStore.net application using a Docker image. The image runs the Debian latest operating system, Apache web server, a CGI (Common Gateway Interface) application, and full MySQL interaction with multiple database tables: an architecture commonly known as LAMP (Linux, Apache, MySQL, PHP) and presents an application environment that uses real coding methods. Not a simulation, BadStore.net operates in the same way as many commercial websites, albeit with a high concentration of application security vulnerabilities.
To run the BadStore.net application, simply pull and build the image into a Docker host. After boot, BadStore.net acts as a networkaccessible server that clients may interact with using a Web browser. This educational playground exists for you to break. And, best of all, when you reboot, everything is back to where you started! There’s no need to rebuild after successful“hacks” that screw everything up.
From your Azure Cloud Bash Shell, SSH to your new Docker host. Provide your own DNS name as follows:
Once logged in to the Docker host, let’s pull and run the BadStore.net App:
To see your web app in action, open a web browser and enter the DNS name of your Docker host, you should have your own BadStore.net up and running:
Now you can open the BadStore.net User Manual from the “Reference” link and start exploring and exploiting this highly hackable web application. For example, when you try to login using email address admin’ or ‘x’=’x with any password, you can get in as the Master System Admin, a typical SQL Injection hack!
3. Use Barracuda WAF to protect your web application in Azure
By now you should have created a resource group on Azure with the DockerVM that hosts your BadStore.net web application. You can add the Barracuda WAF to this resource group within the same VNET:
As a reverse proxy, WAF can protect App Services and Websites in the same way it can protect IaaS VM’s within the same VNET. Following self-guiding and easy to follow steps defined in Deploying and Provisioning the Barracuda Web Application Firewall in the New Microsoft Azure Management Portal, you can spin up a Barracuda WAF PAYG instance from the Azure Marketplace.
In the Azure Marketplace, search for Barracuda Web Application Firewall (WAF) – PAYG, and select the Resource Manager deploymentmodel:
When configure the basic settings of your Barracuda WAF virtual machine, make sure to use Password as Authentication type and use your existing Resource Group where you deployed the BadStore app:
Use the smallest available VM size. If you see the alert that indicates the need to resize and use SSD, that is fine. Use your existing VNET, and leave everything unchanged and deploy your WAF VM:
Here is what your resource group looks like when your WAF VM deployment is DONE:
The Barracuda Web Application Firewall Test Drive - Microsoft Azure provides step-by-step guidelines on how to configure your newly deployed WAF. Here we use the steps listed below that are required for this Test Drive:
- Note the Public IP address of the newly deployed Barracuda Web Application Firewall. Open the browser and enter the noted IP with port 8000 for HTTP: http://IP-Address:8000
- Use “admin” and the password you set up in the “configure the basic settings to log into your WAF. On the WAF GUI go to Advanced, System Configuration and set Show Advanced Settings to Yes.
On the WAF GUI go to Basic, Services and create a new service for your web app. You need to provide: a service name, select the type and port, and for the moment put a dummy IP (like 220.127.116.11) into the Real Servers box:
After this step, you should see your service listed as below:
Once the service and server have created then click “Edit” alongside the Server that was created. Change the identifier to
“Hostname” and fill in the domain name of your Azure web app into the Hostname field. The WAF will resolve this to IP’s and will
monitor for any changes to them.
If your web app is using SSL then in addition to changing the port above to 443, scroll down to the SSL (Server) settings and set “Server uses SSL” to Yes:
After this step, you will see green status checkmark. Now your BadStore app is protected by Barracuda WAF:
Try the SQL Injection hack in Chapter 1 again, this time you won’t be let in. System shows “UserID and Password not found!”
You can fine tune the security policies for HTTP/HTTPS traffic, the link to Barracuda Campus provides a whole list of configuration setups. For example, request limits define the validation criterion for incoming requests by enforcing size limits on HTTP request header fields. Properly configured limits mitigate buffer overflow exploits, preventing Denial of Service (DoS) attacks.
Request limits defaults can be modified if the Service or the server may have problems lengths smaller than the defaults. When Action is set to Deny and Log or Deny with no Log for a Service under URL : Allow/Deny Rules on the WEBSITES > Allow/Deny page, the Barracuda Web Application Firewall continues to examine the request till it hits the default length configured. Smaller limits therefore lead to a slight performance improvement since a smaller number of bytes is parsed before denying requests. The defaults can be changed to bigger values if the original defaults result in false alarms.
Steps To Configure Request Limits:
- Go to the SECURITY POLICIES > Request Limits page.
- Select the policy from the Policy Name drop-down list for which you want to modify request limits settings.
- In the Request Limits section, specify values for the following fields:
- Enable Request Limits - When set to Yes, size limit checks are enforced on request headers.
- Max Request Length - Enter the maximum allowable request length. This includes the Request Line and all HTTP request headers (for example, User Agent, Cookies, Referer etc.) The Request Length limit does not include the request body, which is typically present for POST requests. Any request, whose length exceeds this limit, will be denied.
- Max Request Line Length – Enter the maximum allowable length for the request line. The request line consists of the method, the URL (including any query strings) and the HTTP version. Example: GET /index.cgi?page=home HTTP/1.1 In the above request line, GET is the method, /index.cgi?page=home is the URL and HTTP/1.1 is the version. The length of the entire line is considered when checking for request line length.
- Max URL Length – Enter the maximum allowable URL length including the query string portion of the URL.
- Max Query Length – Enter the maximum allowable length for the query string portion of the URL.
- Max Number of Cookies – Enter the maximum number of cookies to be allowed.
- Max Cookie Name Length – Enter the maximum allowable length for cookie name.
- Max Cookie Value Length – Enter the maximum allowable length for a cookie value. Requests with Cookie values that are larger than the defined setting are denied.
- Max Number of Headers – Enter the maximum number of headers in a request. If there are more headers than this limit in the request, the request is denied.
- Max Header Name Length – Enter the maximum allowable length for header name.
- Max Header Value Length – Enter the maximum allowable length for any request header. A request header could either be a HTTP protocol header such as “Host,” “User-Agent” and so on, or a custom header such as “IIS Translate”. A request may contain any number of these headers.
- Click Save.
This setting does not apply to Cookies. Cookie lengths are instead controlled by the Cookie related parameters, Max Cookie Name Length and Max Cookie Value Length.
Extra: Create a web application using Azure App Services
Azure App Service is Microsoft’s Platform-as-a-Service (PaaS) offering. It provides a highly scalable, self-patching web hosting service. This link has details on how to develop and deploy a web app to Azure Web Apps using different frameworks (.NET/PHP/JAVA/Node.js/Python/ etc). Here we use Python as an example to show how to create a web app with the Azure Cloud Shell and use Git to deploy the sample Python code to your web app. You can follow the steps below using a Mac, Windows, or Linux machine.
Create a deployment user:
In the following command, replace <username> and <password> with a new user name and password. The user name must be unique. The password must be at least eight characters long, with two of the following three elements: letters, numbers, symbols.
Create a resource group:
The following command creates a resource group named TMEResourceGroup in the West Europe location
Create an Azure App Service plan:
The following command creates an App Service plan named TMEAppServicePlan in the Free pricing tier:
Create a web app:
In the following command, replace tmewebapp with a unique name. The default URL of the web app is https://tmewebapp.azurewebsites.net.
Now you should be able to see your App Service and App Service Plan in the Resource Group you just set up, and you’ve created an empty new web app in Azure:
Configure to use Python:
Use the az webapp config set command to configure the web app to use Python version 3.4.
Configure local Git deployment:
In the following command, replace <app_name> with your web app’s name.
The output has the following format:
Push to Azure using Git:
In your local terminal window, run the following command to clone the sample app repository to your local machine (You can also use your own Python-based web app like I did using the Flask framework):
Here is a link that covers details on how to use Local Git Deployment to Azure App Service.
Change to the directory that contains the sample code.
In the local terminal window, add an Azure remote to your local Git repository.
Push to the Azure remote to deploy your app with the following command. When prompted for a password, make sure that you enter the password you created in Configure a deployment user, not the password you use to log in to the Azure portal.
The Python sample code is running in an Azure App Service web app.
Congratulations! You’ve deployed your first Python app to Azure App Service. Now you can proceed with the same steps in section 2 to deploy a Barracuda WAF to protect this web application.
Configuring a Web Application Firewall (WAF) for App Service Environment
Local Git Deployment to Azure App Service