

**推出 的新主控台體驗 AWS WAF**

您現在可以使用更新後的體驗，在主控台的任何位置存取 AWS WAF 功能。如需詳細資訊，請參閱[使用 主控台](https://docs.aws.amazon.com/waf/latest/developerguide/working-with-console.html)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# AND 規則陳述式
<a name="waf-rule-statement-type-and"></a>

AND 規則陳述式結合了巢狀陳述式與邏輯AND操作，因此所有巢狀陳述式都必須相符，AND陳述式才能相符。這至少需要兩個巢狀陳述式。

## 規則陳述式特性
<a name="and-rule-statement-characteristics"></a>

**可巢狀** – 您可以巢狀此陳述式類型。

**WCUs** – 取決於巢狀陳述式。

## 尋找此規則陳述式的位置
<a name="and-rule-statement-where-to-find"></a>
+ 主控台上的**規則建置器** – **如果請求**，請選擇**符合所有陳述式 (AND)**，然後填入巢狀陳述式。
+ **API** – [AndStatement](https://docs.aws.amazon.com/waf/latest/APIReference/API_AndStatement.html)

## 範例
<a name="and-rule-statement-examples"></a>

以下清單顯示使用 AND和 NOT 邏輯規則陳述式來消除 SQL Injection 攻擊陳述式相符項目的誤報。在此範例中，假設我們可以撰寫單一位元組比對陳述式，以符合導致誤報的請求。

AND 陳述式會比對不符合位元組比對陳述式且符合 SQL Injection 攻擊陳述式的請求。

```
{
      "Name": "SQLiExcludeFalsePositives",
      "Priority": 0,
      "Statement": {
        "AndStatement": {
          "Statements": [
            {
              "NotStatement": {
                "Statement": {
                  "ByteMatchStatement": {
                    "SearchString": "string identifying a false positive",
                    "FieldToMatch": {
                      "Body": {
                        "OversizeHandling": "MATCH"
                      }
                    },
                    "TextTransformations": [
                      {
                        "Priority": 0,
                        "Type": "NONE"
                      }
                    ],
                    "PositionalConstraint": "CONTAINS"
                  }
                }
              }
            },
            {
              "SqliMatchStatement": {
                "FieldToMatch": {
                  "Body": {
                    "OversizeHandling": "MATCH"
                  }
                },
                "TextTransformations": [
                  {
                    "Priority": 0,
                    "Type": "NONE"
                  }
                ]
              }
            }
          ]
        }
      },
      "Action": {
        "Block": {}
      },
      "VisibilityConfig": {
        "SampledRequestsEnabled": true,
        "CloudWatchMetricsEnabled": true,
        "MetricName": "SQLiExcludeFalsePositives"
      }
    }
```

使用主控台規則視覺化編輯器，您可以在 或 陳述NOT式下巢狀化非邏輯陳述式OR或AND陳述式。NOT 陳述式的巢狀化會顯示在先前的範例中。

使用主控台規則視覺化編輯器，您可以在邏輯規則陳述式下巢狀化最可巢狀的陳述式，例如先前範例中顯示的陳述式。您無法使用視覺化編輯器來巢狀化 OR或 AND陳述式。若要設定此類型的巢狀，您需要以 JSON 提供規則陳述式。例如，下列 JSON 規則清單包含 OR陳述式的巢狀AND陳述式。

```
{
  "Name": "match_rule",
  "Priority": 0,
  "Statement": {
    "AndStatement": {
      "Statements": [
        {
          "LabelMatchStatement": {
            "Scope": "LABEL",
            "Key": "awswaf:managed:aws:bot-control:bot:category:monitoring"
          }
        },
        {
          "NotStatement": {
            "Statement": {
              "LabelMatchStatement": {
                "Scope": "LABEL",
                "Key": "awswaf:managed:aws:bot-control:bot:name:pingdom"
              }
            }
          }
        },
        {
          "OrStatement": {
            "Statements": [
              {
                "GeoMatchStatement": {
                  "CountryCodes": [
                    "JM",
                    "JP"
                  ]
                }
              },
              {
                "ByteMatchStatement": {
                  "SearchString": "JCountryString",
                  "FieldToMatch": {
                    "Body": {}
                  },
                  "TextTransformations": [
                    {
                      "Priority": 0,
                      "Type": "NONE"
                    }
                  ],
                  "PositionalConstraint": "CONTAINS"
                }
              }
            ]
          }
        }
      ]
    }
  },
  "Action": {
    "Block": {}
  },
  "VisibilityConfig": {
    "SampledRequestsEnabled": true,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "match_rule"
  }
}
```