---
title: "WAF ACL Firewall Access Control SQS collector"
canonical: "https://docs.devo.com/space/latest/1097990179/WAF%20ACL%20Firewall%20Access%20Control%20SQS%20collector"
format: markdown
---
> Macro (toc)

## Purpose

An analyst wants to **detect malicious network traffic in web applications**.  Using **the WAF ACL SQS collector **to send firewall logs to Devo, the analyst will **find malicious IP activity**.  As a result, the analyst will use Access Control Lists to block the traffic, preventing attackers from cross-site scripting.

Devo recommends also logging AWS WAF actions using the [CloudTrail](https://docs.aws.amazon.com/waf/latest/developerguide/understanding-waf-entries.html) SQS Collector.

## Example tables

| **Table** | **Description** |
| --- | --- |
| cloud.aws.waf.logs | [Access Control List Traffic](https://docs.aws.amazon.com/waf/latest/developerguide/logging-fields.html) |

## Authorize It

1. [Authorize SQS Data Access](https://devodocs.atlassian.net/wiki/spaces/latest/pages/1098121229).
  1. For this service, the bucket name **must** start with `aws-waf-logs-`.
2. [Add data to the S3 bucket.](https://docs.aws.amazon.com/waf/latest/developerguide/logging-management-enable.html)
  1. In WAF, select a Web ACL.
  2. Select “Logging” and “Enable.”
  3. Set the destination to the S3 bucket previously authorized.

## Run It

In the Cloud Collector App, [create an SQS Collector instance](https://docs.devo.com/space/latest/409305131/Catalog#Create-an-instance).  **Remove **the default collector parameters and insert this parameters template, replacing the values enclosed in `< >`.

```
{
  "inputs": {
    "sqs_collector": {
      "id": "<FIVE_UNIQUE_DIGITS>",
      "services": {
        "aws_sqs_waf": {
          "routing_template": "cloud.aws.waf.logs.<YOUR_AWS_ACCOUNT_NUMBER>.<REGION>"
        }
      },
      "credentials": {
              "aws_cross_account_role": "arn:<PARTITION>:iam::<YOUR_AWS_ACCOUNT_NUMBER>:role/<YOUR_ROLE>",
              "aws_external_id": "<EXTERNAL_ID>"
      },
      "region": "<REGION>",
      "base_url": "https://sqs.<REGION>.amazonaws.com/<YOUR_AWS_ACCOUNT_NUMBER>/<QUEUE_NAME>"
    }
  }
}
```

The account number and region are entered three times each.  The account number and region entered into the routing template will appear in the ACCID and REGION fields of the cloud.aws.waf.logs table.  

## Secure It

### IP Evading [Reputation Block List](https://docs.aws.amazon.com/waf/latest/developerguide/aws-managed-rule-groups-ip-rep.html)

```
/*
It has been determined that a particular IP is malicious.
Check if the IP has contacted the firewall,
if it was allowed, if it was on Amazon's reputation list, 
and which terinating rules blocked the IP.

If the reputation list did not terminate the request, then the rules 
need improvement.
*/

from cloud.aws.waf.logs 
where eq(httpRequest_clientIp,233.252.0.0)//example IP
group by action, 
eq(terminatingRuleId,"AWS-AWSManagedRulesAmazonIpReputationList") as on_reputation_list
select collectdistinct(ruleGroupList_terminatingRule_ruleId_str) as terminating_rules
```

### Malicious WAF Rule Created

```
/*
A malicious user has gained access to WAF configuration.
The user has created a rule which has blocked critical traffic.
Identify new rules which are blocking lots of traffic so they can be removed.
*/
from cloud.aws.waf.logs 
where eq(action,"BLOCK")
group by terminatingRuleId
select count() as requests_blocked,
first(eventdate) as rule_started 
where rule_started>today()-7d //recently created rule
```

## Monitor It

Create an **[inactivity alert](https://docs.devo.com/space/latest/95126785/Inactivity+alert)** to detect interruptions of transfer of data from the source to the SQS queue using the query

```
from cloud.aws.waf.logs
where toktains(hostchain,"collector-") 
select split(hostchain,"-",1) as collector_id
```

Set the inactivity alert to keep track of the `collector_id`.


If protection of a particular URI is very important, it can be monitored individually for inactivity.

```
from cloud.aws.waf.logs 
//An alert is required if logging of requests to this important API stop.
where startswith(httpRequest_uri,"/api/")
```