Skip to content
This repository was archived by the owner on May 29, 2024. It is now read-only.

Commit 66b3efb

Browse files
committed
Merge branch 'master' of github.com:aws-samples/aws-waf-workshop into rezabekf/patch-01
2 parents 1e539df + 77d3bb4 commit 66b3efb

File tree

10 files changed

+131
-4
lines changed

10 files changed

+131
-4
lines changed

docs/2-00-http-flood-config.png

48.5 KB
Loading

docs/2-01-athena-saved-queries.png

62.2 KB
Loading

docs/2-02-log-parser-cw-event.png

95.5 KB
Loading

docs/2-03-cw-event-output.png

89.9 KB
Loading
2.4 MB
Binary file not shown.
67.4 KB
Binary file not shown.

docs/step-0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ Step by step instructions:
4040
* On the final page, check the box at the bottom allowing AWS CloudFormation to create IAM resources with custom names.
4141
* Click the orange "Create stack" button at the bottom-right of the page to deploy the stack into your account.
4242

43-
# [Next step](step-2.md)
43+
# [Next step](step-1.md)

docs/step-1.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
11
# Step 1 - Getting Started with AWS WAF Security Automations Solution
22

3-
# [Next step](step-2.md)
3+
## 1.1 Associate the solution's AWS WAF Web ACL with your ALB
4+
5+
After deploying the Web App, look at the [CloudFormation Exports](https://console.aws.amazon.com/cloudformation/home?#/exports). You should have a value called `site-url`. That is the address of the Application Load Balancer sitting on top of the Web App. Take note of that URL.
6+
7+
Next, you need to associate the solution's AWS WAF Web ACL with your ALB. For that:
8+
* Go to the [AWS WAF console](https://console.aws.amazon.com/wafv2/home?#/webacls)
9+
* Check if the region drop-down filter (not the one on the top, the one in the page) is selected with your region as value. For instance, "EU (Ireland)"
10+
* Select the solution's WebACL - for instance "AWSWAFSecurityAutomations"
11+
* On the right panel, select the "Rules" tab
12+
* Scroll down to "AWS resources using this web ACL" section and click the "Add association" button
13+
* On the "Resource type" drop-down, select "Application load balancer"
14+
* On the "Resource" drop-down, select the ALB you've created
15+
* Finally, click the "Add" button.
16+
17+
18+
## 1.2 SQL Injection and XSS
19+
20+
Access the `site-url` endpoint and include bad signatures to the requests. You can use, for example:
21+
22+
* SQL Injection: `<your-endpoint>/?username=1'%20or%20'1'%20=%20'1&password=1'%20or%20'1'%20=%20'1'`
23+
* XSS: `<your-endpoint>/?<SCRIPT>alert(“Cookie”+document.cookie)</SCRIPT>`
24+
25+
## 1.3 HTTP Flood (AWS Lambda log parser)
26+
27+
To test HTTP Flood, you can simulate an WAF log file deliver event. For that:
28+
29+
* Go to the CloudFormation stack's `Outputs` tab and search for the value defined for `WafLogBucket`
30+
* Go to S3, and upload [this file](files/waf-access-log-sample.gz) to the `WafLogBucket` bucket
31+
* Wait a few seconds (while the log parser function processes the new WAF log file)
32+
* Check if the file `<stack_name>-waf_log_out.json` was added to the `WafLogBucket` bucket
33+
* Go to [AWS WAF console](https://console.aws.amazon.com/wafv2/home?#/webacls) and check if `HTTP Flood` rule contains any IP listed
34+
35+
## 1.4 Scanners & Probe (Amazon Athena log parser)
36+
37+
To test Scanners & Probe, you can simulate a CloudWatch event running a query in a bucket that contains a sample access log file.
38+
For that:
39+
* Go to the S3 bucket that you set as Access Log Bucket. If you don't remember, go to stack's `Outputs` tab and search for the value defined for `AppAccessLogBucket`
40+
* Create a new folder and name it AWSLogs and upload [this file](files/alb-access-log-sample.gz) to it
41+
42+
This file will be processed during the next scheduled *Scanner and Probe* scan. Rather than wait, we will run it on demand.
43+
44+
* Go to the [AWS Lambda console](https://console.aws.amazon.com/lambda/home)
45+
* Open the `<stack_name>-LambdaLogParserFunction-<ID>` lambda function
46+
* Follow the link related the CloudWatch scheduled event
47+
* Copy the event data and create a Lambda test event with that information
48+
* Run the lambda function using the same event data used by the scheduled event
49+
* Wait a few seconds (while Athena processes the data, save the result back on S3 and the log parser function is called again to process the result file)
50+
* Go to [AWS WAF console](https://console.aws.amazon.com/wafv2/home?#/webacls) and check if `Scanners & Probes` rule contains any IP listed
51+
52+
# [Next step](step-2.md)

docs/step-2.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,81 @@
11
# Step 2 - Customising and extending AWS WAF Security Automations Solution
22

3-
# [Next step](step-3.md)
3+
4+
## 2.1.1 Customise HTTP Flood Protection (AWS Lambda Log Parser)
5+
6+
The HTTP Flood log parser comes with some extensions points, they are:
7+
8+
* Request Threshold: the maximum acceptable requests per five minutes per IP address.
9+
* Block Period: the period (in minutes) to block applicable IP addresses.
10+
* Ignored Suffixes: requests accessing this type of resource will not count to request threshold. By default, this list is empty.
11+
* URI List: use this to define a custom request threshold and block period for specifics URLs. By default, this list is empty.
12+
13+
The goal now is to apply customizations and check how it affects the log parser behavior.
14+
15+
16+
### 2.1.2 Customising the Parser
17+
18+
* Go to the S3 bucket used for WAF Logs Bucket. To check it's name, go to stack's Outputs tab and search for the value defined for WafLogBucket;
19+
* Download the configuration file `<stack_name>-waf_log_conf.json`;
20+
* Make your changes (ex: change requestThreshold to 100);
21+
* Overwrite the configuration file on S3 bucket by uploading the new `<stack_name>-waf_log_conf.json` back to WAF Logs Bucket.
22+
23+
Here is a sample of changed file:
24+
25+
![http-flood-config](2-00-http-flood-config.png)
26+
27+
28+
### 2.1.3 Testing the new rules
29+
Let's test your HTTP flood protection. We will use [Apache AB](https://httpd.apache.org/docs/2.4/programs/ab.html).
30+
31+
> ⚠️ **Warning**: Do not run the benchmarking tool from your local machine!
32+
33+
We will use [Systems Manager Session Manager](https://console.aws.amazon.com/systems-manager/session-manager/start-session) to connect to the instance and run the `ab` benchmarking tool.
34+
35+
Run against your endpoint 50,000 requests, with concurrency 100.
36+
```bash
37+
# Note the trailing slash
38+
ab -n 50000 -c 100 <your-endpoint>/
39+
```
40+
41+
* After a couple of minutes (time necessary to ALB deliver the access logs to S3), go to AWS WAF console and check if HTTP Flood rule contains your EC2 instance IP listed.
42+
43+
* Try to access <your-endpoint> from the instance you've sent the requests:
44+
```bash
45+
curl -s -o /dev/null -w "Return Code: %{http_code}\n" <your-endpoint>
46+
```
47+
48+
## 2.2 Customising Scanners and Probes
49+
50+
51+
52+
Now we will customise our Scanner and Probe rules. These use Amazon Athena.
53+
The solutions refer to the Athena by a saved query ID. As Athena don't allow you to change saved queries, the process to apply customizations to Athena query is by creating a new query and updating the Athena log parser event to use the new query ID.
54+
55+
### 2.2.1
56+
* Navigate to the Amazon Athena console, select the Saved Queries tab;
57+
* Select the query you want to customize (ScannersProbesLogParser);
58+
59+
![athena-saved-queries](2-01-athena-saved-queries.png)
60+
61+
* Apply your changes (ex: change from `COUNT(*)>=50` to `COUNT(*)>=500`);
62+
* Save the new Athena Query and copy the new query ID.
63+
64+
65+
> NOTE: The query ID is part of the URL when you access the saved query (https://console.aws.amazon.com/athena/home?force#query/saved/**_query_id_**). Alternatively, you can use the `get-named-query CLI command`;
66+
67+
68+
* Navigate to LogParser events and select the corresponding event (ScannerProbe);
69+
70+
![log-parser](2-02-log-parser-cw-event.png)
71+
72+
* Edit the event data to point to the new Query ID copied above;
73+
74+
![cw-event-rule](2-03-cw-event-output.png)
75+
76+
Save the new event data;
77+
78+
The Log Parser will now process logs using your new Athena Query.
79+
80+
Done? Great work! Continue to the last challenge
81+
# [Next step](step-3.md)

templates/main.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
AWSTemplateFormatVersion: '2010-09-09'
22
Description: Workshop about AWS WAF and WAF Security Automations Solution (uksb-1q1gt3g5d)
33
Metadata:
4-
Version: '0.2'
4+
Version: '0.3'
55
AWS::CloudFormation::Interface:
66
ParameterGroups:
77
- Label:

0 commit comments

Comments
 (0)