|
1 | 1 | # Step 2 - Customising and extending AWS WAF Security Automations Solution |
2 | 2 |
|
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 | + |
| 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 | + |
| 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 | + |
| 71 | + |
| 72 | +* Edit the event data to point to the new Query ID copied above; |
| 73 | + |
| 74 | + |
| 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) |
0 commit comments