Notice: Trying to get property 'post_excerpt' of non-object in /home/n3svtp4r09fz/technet.vn/wp-content/themes/darknews/single.php on line 43
Lab Details
- This lab walks you through the steps to block web traffic with a WAF (web application firewall) in AWS.
- Duration: 1 Hour
- AWS Region: US East (N. Virginia)
Introduction
WAF (web application firewall)
- AWS WAF is a web application firewall that helps you to protect your web applications against common web exploits that might affect availability and compromise security.
- AWS WAF gives you control over how traffic reaches your applications by enabling you to create security rules that block common attack patterns like SQL injection and cross-site scripting.
- It only allows the request to reach the server based on the rules or patterns you define.
- Users create their own rules and specify the conditions that AWS WAF searches for in incoming web requests.
- The cost of WAF is only for what you use.
- The pricing is based on how many rules you deploy and how many web requests your application receives.
- For example, you can deploy AWS WAF on Amazon CloudFront with an Application Load Balancer in front of your web servers or servers running on EC2.
Features of WAF
Web traffic filtering using custom rules
- You can create your own rules, depending on your requirements, whether to block or allow the incoming and outgoing request. You can also customise the string that appears in your web request.
Blocking malicious requests
- You can also configure rules in AWS WAF to identify and block web requests threats like SQL injections and cross-site scripting.
Tune your rules and monitor traffic
- AWS WAF also allows us to review our rules and customize them to prevent new attacks from reaching the server.
Lab Description
Bastion Server
- A bastion host is a system that is exposed to the internet launched in a public subnet.
- In terms of security, Bastion is the only server which is exposed to the internet and should be highly protective to attacks.
- Bastion host is also known as a Jump Box. It is a computer that acts like a proxy server and that allows the client machine to connect to the remote server.
- It usually resides outside the firewall.
- The Bastion server filters the incoming traffic and prevents the unwanted connections entering the network thus acting like a gateway.To maintain the security of bastion hosts, all unnecessary software, daemons and users are removed.
Application Load Balancer (ALB)
- Load Balancer, a service that allows you to distribute the incoming application or network traffic across multiple targets, such as Amazon EC2 instances, containers, and IP addresses, in multiple Availability Zones.
- ALB is used to route the HTTP and HTTPS traffic across the targets based on the rules attached with the target group.
- Rules determine what action is taken when a rule matches a client request.
- The target group is used to route requests across registered targets as part of an action rule. Target groups consist of a protocol and target port. We can also configure health checks to monitor the status of the target group. A single ALB can route traffic to multiple target groups.
- Targets consist of EC2 instances that are registered with the ALB as part of a target group.
Web servers
- Two web servers are launched in the Private subnet to handle the web request.
- The request the to web servers are shared using the ALB.
- Web servers are attached to the ALB Target group.
- Servers are pre-installed with HTTPD on both servers and have the test pages RESPONSE COMING FROM SERVER 1 and RESPONSE COMING FROM SERVER 2 respectively.
- They are attached to a security group via port 22 that allows the SSH connection only from Bastion server and port 80 that allows the web traffic coming from ALB.
Architecture Diagram
Lab Tasks
- In this lab, we will launch two web servers with an HTTPD service installed in them.
- An Application Load Balancer (ALB) with the target group routing the traffic to the load balancer.
- Creating an IP set in WAF i.e list of IPs to block. Here we are adding our IPv4 by getting it from https://www.whatismyip.com/.
- Creating an ACL rule in WAF using the IP set created in the above step.
- Testing the Response of the Load balancer without applying the WAF ACL.
- Applying WAF rule to the Application Load Balancer.
- Testing the working of the ALB.
Steps
Creating Security group for Load balancer
- Navigate to the EC2 Dashboard and scroll down to
. In the left menu, click on
- Configure the security group as follows:
- Security group name: LoadBalancer-SG
- Description : Security group for Load balancer
- VPC : Leave as default
-
Click on
and add the port as follows
- Port : 80
- Protocol : HTTP
- Source : 0.0.0.0/0
- Port : 80
- Once you provide the above details, click on
and the security group for the load balancer will be created.
Steps to create the Web-servers
- Click on
.
- Choose an Amazon Machine Image (AMI):
- Instance Type : t2.micro
- Configure Instance Details:
- Number of instances : 1
- Auto-assign Public IP : Select Enable
- Click on
.
-
Under the User data section, enter the following script to create an HTML page served by an Apache HTTPD web server.
#!/bin/bash
yum install httpd24 -y
service httpd start
chkconfig httpd on
echo “RESPONSE COMING FROM SERVER A” > /var/www/html/index.html
- Now click on
- Add Storage: No need to change anything in this step, click on
- Add Tags: Click on
- Now click on
- Key : Enter Name
- Value : Enter webserver-A
- Click on :
- Configure Security Group:
- Name : Enter webserver-SG
- Description : Type security group for webserver
-
To add SSH
- Choose Type : Select
- Source : Choose
- Choose Type : Select
-
To add HTTP
- Choose Type : HTTP
- Source : Choose LoadBalancer-SG
- Choose Type : HTTP
- After that, click on
- Key Pair : Create a new key pair named webkey and click on
. The key pair will be downloaded to your local system. After that, click on
.
- After a few minutes, you will see new instance named webserver-A running along with Bastion-server created in the earlier step.
- Repeat the above steps to create Webserver-B by selecting the existing security group webserver-SG providing the following details:
#!/bin/bash yum install httpd24 -y service httpd start chkconfig httpd on echo “RESPONSE COMING FROM SERVER B” > /var/www/html/index.html |
- Name: webserver-B
- Security Group name: webserver-SG
- Key Name: webkey.
- Navigate to the EC2 Dashboard to find the two instances (webserver-A and webserver-B) running.
Creating a Load balancer
- In the EC2 console, navigate to
in the left side panel.
- Click on
on top left to create a new load balancer for our web servers.
- On the next screen, choose
since we are testing the high availability of our web application.
- In configure the load balancer, provide the following details:
- Name : Enter Web-server-LB
- Scheme : Select Internet-facing
- Ip address type : Choose ipv4
- Listener : Default (Http:80)
-
Availability Zones
- VPC : Choose Default
- Availability Zones : Select All Availability Zones ,
(Note: we must specify the availability zones in which the load balancer needs to be enabled so it can route the traffic only to the targets launched in those availability zones. You must include subnets from a minimum of two Availability zones to make our Load balancer Highly Available.)
- VPC : Choose Default
- Once filling in all the details above, ignore the warning and click on
- Configure Security Settings:
-
Select an existing security group and chose the security group LoadBalancer-SG that we created in the above step.
- configure Routing
-
Target Group: Select New target group (default)
- Name : Enter web-server-TG
- Target Type : Select Instance
- Protocol : Choose HTTP
- Port : Enter 80
- Note: The target group is used to route requests to one or more registered targets
- Name : Enter web-server-TG
-
Health check:
- Protocol : Choose HTTP
- Path :Enter /index.html
- Click on
- Note: The load balancer periodically sends pings, attempts connections, or sends requests to test the EC2 instances. These tests are called health checks.
- Create an index.html file the default Apache document root /var/www/html of web servers to pass the health check. This can be done by navigating to the route and executing the command: echo “hello world” > index.html
- Protocol : Choose HTTP
- Registering Targets
-
Choose the two web instances, click on
and click on
.
- Once you reviewed the settings, click on
.
-
You have successfully created the Application Load balancer. Wait for 2 to 3 minutes for the Load balancer to become Active.
Testing the Load Balancer
- Navigate to
and select the load balancer that you created. Click on
, copy the
and paste it in the browser
- Refresh the browser a few times and you will see the request is serving from both servers. You will see the output as RESPONSE COMING FROM SERVER A & RESPONSE COMING FROM SERVER B. This shows that load is shared between the two web servers via Application Load Balancer.
Creating an IP set
- Click on
and select
under the
section.
- Select
in the right side menu and click on
- On the next screen, fill out the following details under Create IP set.
-
IP set details:
- IP set name : MyIPset
- Description : IP set to block my public IP
- Region : US EAST (N.Virginia )
- IP Version : IPv4
- IP address : IP of your local network/32 from https://www.whatismyip.com/.
- Note: You have to give /32 after the IP is pasted or else you won’t be able to create an IP set.
- IP set name : MyIPset
- Once you have provided the above details, click on
Creating a web ACL
- Web ACL details
- Navigate to the AWS WAF dashboard and select
. Click on
to create a new web ACL.
-
Configure the ACL as below:
-
Web ACL details
- Name : MywebACL
- Description : ACL to block my public IP
- CloudWatch metric name : Leave Default
-
Resource type : Regional resources (Application Load Balancer and API Gateway)
- Region : US EAST (N.Virginia)
- To associate an AWS resource, click on
- In Add AWS resources select Application Load Balancer and select the name of ALB. Click on
- Name : MywebACL
-
- Lastly click on
.
- Add rules and rule groups
- Under Rules click on
and select
in the drop-down menu.
-
In Rule type select IP set as shown below and fill the details as given below:
- Rule type : IP set
- Name : MywebACL-rule
- IP set : select the IP set created Above ( MyIPset )
- Action : Block
- Rule type : IP set
- Once you provide the above details, click on
.
- Lastly click on
.
- Set rule priority
- Leave as default and click on
.
- Configure metrics
- Leave as default and click on
.
- Review and create web ACL
- Review all your inputs and click on
- Wait for 1 or 2 minute until you will see that your web ACL is successfully created.
- You have successfully created a web ACL for ALB with the help of an IP set created with your public IP.
Testing the working of the WAF
- To test the WAF, navigate to
from the EC2 left menu under the sub-heading Load balancing
- Under the Load balancer section, select the Application load balancer awf-alb.
- Copy the DNS name under Description and paste it in your desired browser.
- You will get a 403 forbidden error showing that WAF blocked your connection to ALB.
Unblocking the IP
- To unblock the IP, navigate to
and click on MyIPset. Select your public IP and then click on
- Enter your IP followed by CIDR /32 from the link: https://www.google.com/search?client=firefox-b-d&q=what+is+my+ip/
- Type delete in the confirmation box and click on
.
- You have successfully removed the IP from WAF.
- Wait for a few minutes.
- Navigate to
from EC2 left menu under the sub-heading Load balancing
- Under the Load balancer section, select the Application load balancer awf-alb.
- Copy the DNS name under Description and paste it in your desired browser.
- You will get the response from the web servers either stating RESPONSE COMING FROM SERVER 1 or RESPONSE COMING FROM SERVER 2 as shown below:
Completion and Conclusion
- You have successfully created an IP set using your public IP.
- You have successfully created a web ACL rule using an IP set and application load balancer (ALB).
- You have successfully tested the working of the ALB after implementing a WAF, blocking the web request to the ALB from your local network.
- You deleted the IP set and tested the working of the ALB.