Jump to content

Protect Applications in Google Cloud Platform (GCP) using Azure WAF


Recommended Posts

Guest tobiotolorin
Posted

Azure Web Application Firewall (WAF) provides centralized protection of your web applications from common exploits and vulnerabilities. You can deploy WAF on Azure Application Gateway or WAF on Azure Front Door Service.

 

This blog provides the steps to validate the deployment of a sample coffeeshop application in GCP and how to apply Azure WAF to implement security controls for access to the application. The Coffeeshop application has been modified from the online sample SQL injection application

 

 

 

In this blog post:

 

  1. We will deploy our Coffeeshop application into GCP
  2. We will then publish this application via the Azure App Gateway
  3. Next, we will restrict access to the application in Google Cloud to only requests coming from App Gateway’s public IP address
  4. We then test for SQL injection and XSS attacks.
  5. Finally, we observe the events in our logs.

 

 

 

largevv2px999.png.67c05b2e3a2baed28aed5fc2ccf55868.png

 

 

As shown in the diagram above, there are two paths to access the Coffeeshop app, delineated by the amber and green arrows. The amber arrow is direct access to the web app in GCP (to be denied in the 3rd phase) and the green path provides access through the App Gateway/WAF with DDoS protection enabled on the host VNet.

 

 

 

Deploy the application in Google App Engine (Step 1):

 

  1. Go to Google cloud. Sign up/Login (trial account works) and go to Console. Create a new project. We called this project SampleappGCP.


    1. Go to the Cloud shell and run a command e.g.
      gcloud projects list
      You will be required to Authorize access for the first time. Authorize the access.
      1. Enable the API for App Engine.
        a. Go to the left blade and search for APIs and Services.
        b. In the "+ Enables APIs and Services bar, search for App Engine(admin) API and enable it
         
        mediumvv2px400.png.490e353dae28a60e188e8fe3dd68cebd.png

      [*]

      Go back into the GCP Shell and make sure you are in your project directory. If you are not in the directory, use the following commands to see the projects ID and then navigate into the project (Coffeeshop in this case) directory:

       

      gcloud projects list

       

      gcloud config set project <Project ID obtained from the list above>

    • Go into the task bar.
    • Search for App Engine.
    • Click “Create application” and select a region to use.

 

mediumvv2px400.png.a143f7d53b9165e95ee6d8d02a841fa8.png

 

 

 

Now that the app has been created, we need to deploy our code into the app. Go to the Cloud shell and clone the Coffeeshop app from Network Security Github

 

 

 

 

 

git clone GitHub - tobystic/sql-injection-demo: A simple mockup of a webshop to demonstrate the sql injection vulnerability.

 

 

 

 

 

largevv2px999.png.c6fa67caf09101791f37a16b1ac67d28.png

 

 

 

Go into the repository that you have just cloned and deploy using the app.yaml file. Click yes to follow the prompt. This will take some few minutes

 

 

 

olotolor@cloudshell: ~ gcloud app deploy app.yaml

 

 

 

If all go well, the code should be deployed in the app created and you would be presented with a URL to access the application. e.g., https://sampleappgcp.wl.r.appspot.com. If you modify your code or yaml file, you have to run this command again to redeploy the app.

 

 

 

largevv2px999.png.43f5953e40156ae542e3dc2f9c16d947.png

 

 

 

Create the SQL connection for the Coffeeshop application (Step 2)

 

 

Enable SQL database and use the database information in the readme page (also updated in the yaml file) to create a database in Cloud SQL. (You can ignore this step and just create a custom rule to test WAF if you do not need SQLi and XSS tests)

 

  • Go to the left blade and Select Cloud storage.
  • Create a bucket(sampleappsql).
    • Upload the database files from the SQL folder of the app files (from Network Security Github) into the sampleappsql bucket in your Cloud storage.
       
      largevv2px999.png.4c1be32ef5f08693457c4ced12c054f9.png
       

    [*]Go to the left blade and click SQL

    [*]Create MySQL instance (Coffeeshop) and set up the password (optional). (Make sure to update the instance name in the DB_host and Cloud SQL instance parameters in your yaml file). Also, ensure the cloud instance path is updated in the connnectdb.php file in the mysqli_connect string.

    [*]Select region and dev env. When done, click “Create instance”, this will take some minutes .

    [*]From the menu pane, create a database “inject_demodb

    [*]Create user “sql_injection

    [*]Click “Import” to import the databases from your Cloud bucket

 

You can confirm the status of your SQL API by using the describe command on instance name in the shell.

 

 

 

$ gcloud sql instances describe coffeeshop

 

 

 

largevv2px999.png.bc480c5626af986396407e3aae07e519.png

 

 

 

Confirm connection using your root account.

 

 

 

gcloud sql connect coffeeshop --user=root –quiet

 

 

 

Go back to the cloud shell and redeploy your app using gcloud app deploy app.yaml . You should now see the coffee options populated

 

 

largevv2px999.png.9800e64221be2560e9d1de4ff07b2008.png

 

 

Publish Application via Azure App Gateway

 

 

(You may use the app gateway in the Netsec lab)

 

  1. Create an App Gateway with a HTTP listener GCPlistener.
  2. Add back-end host: GCPbackendpool (Target type: insert GCP <appUrl>)
  3. Add a rule to route access from the HTTP listener GCPlistener to the GCP backend target GCPbackend
  4. Confirm access to Coffeeshop app via App Gateway using App Gateway Public IP.

 

(If you get a Bad Gateway error, ensure the probe test is successful and the back-end setting has the right path to your app URI)

 

 

Restrict access to Coffeshop application to App Gateway public IP only (Step 3)

 

 

You can control your ingress traffic to your application. You can use the App Engine Firewall in GCP to restrict access to your apps. Open the firewall rules in the Google Cloud Console and you'll see a default rule that allows all traffic to your app.

 

  • Add a new rule to allow only traffic from the public IP address from your App Gateway
  • Then, update the default rule to Deny all traffic.

 

mediumvv2px400.png.920e3ac905ea31c376544beed0adbed9.png

 

 

 

  • Confirm that access using the original URL is now denied and app is only accessible via the App Gateway Public IP address.
     
    largevv2px999.png.f83dc439885e9a63f304704154d83336.png

Test for SQL injection prevention with Azure WAF. (Step 4)

 

 

Now that we have access to the application through the App Gateway, we can attempt to login with our SQL injection query.

 

Login with username “test” and password “test” and confirm a successful login access. (This is a user in the users.sql database that was imported.)

 

Now log out and refresh on the page. Attempt to use the injection query “ ' OR 1=1-- ” for both username and password. Confirm access denied by App Gateway WAF.

 

mediumvv2px400.png.b849fcf8aa74b24534555c3f74edcf38.png

 

 

Test for Cross Site scripting attack

 

 

You can also try other attacks such as injecting the following script in the filter box

 

 

 

<script>alert("You are being attacked")</script>

 

 

 

mediumvv2px400.png.a69762e8d75a209225c830530782a7cb.png

 

 

 

This should give a denied access page just like the case for the SQLi above. (If access is not restricted, you should confirm that your Policy is in Prevention mode)

 

You can further test and permit direct access in the GCP firewall and then test again. This time, the XSS attack should be successful, and a JavaScript alert shown as below.

 

 

 

largevv2px999.png.76412483b2e3840bd4d4b427d631bb7d.png

 

 

 

Click OK and click on “Recreate table” to rebuild your coffee order table.

 

 

 

Log review

 

The images below show the logging information about the attacks we have just carried out including their signature IDs. You can observe the prevention action in the message column, pattern match, the source request uri among others

 

 

 

largevv2px999.png.74a12b315f900d4e9a457aebebfa3360.png

 

 

 

Let's look at the XSS attack. We can see the signature ID in ruleId_s , action_s which shows the match action and other details messages.

 

largevv2px999.png.db985ac4f2fdc5c0bb400f46cb5295f7.png

 

 

 

In conclusion, you can use Azure Web Application Firewall to protect workloads in non-Azure cloud environment and apply existing security benchmarks to ensure your applications are protected from illegitimate access based on predefined compliance and security strategy in your organization. You can perform a similar proof of concept with Amazon Web Services by following instructions in the protect workloads in AWS blog.

At the end of this exercise, do not forget to disable the App Engine and SQL instances to manage the cost associated with this deployment tasks.

 

Continue reading...


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...