복잡한 사용자 지정 AWS WAF JSON 규칙을 생성하려면 어떻게 해야 하나요?

3분 분량
0

복잡한 사용자 지정 AWS WAF JSON 규칙을 생성하려면 어떻게 해야 하나요?

해결 방법

AWS WAF에 대한 사용자 지정 규칙을 추가할 때 규칙 JSON 편집기에서 복잡한 사용자 지정 규칙을 생성합니다. 규칙은 AWS WAF 콘솔웹 ACL규칙 그룹에 생성 및 관리합니다. 규칙이 정의된 규칙 그룹 또는 웹 ACL에서 이름으로 규칙에 액세스할 수 있습니다.

사용 사례에 AND, OR 또는 NOT 논리(중첩된 문)의 조합이 필요한 사용자 지정 규칙이 필요한 경우 JSON 편집기를 사용하여 규칙을 생성해야 합니다. 자세한 내용은 AWS WAF 규칙 문을 참조하세요.

: AWS WAF 콘솔에 있는 규칙 시각 편집기를 사용하여 사용 사례와 유사한 규칙 설명을 생성할 수 있습니다. 그런 다음 JSON 문을 보려면 **규칙 JSON 편집기(Rule JSON editor)**를 선택하고 JSON 편집기에서 필요한 사항을 변경합니다.

다음 예에서는 고유한 사용자 지정 규칙 논리를 만드는 데 사용할 수 있는 참조를 제공합니다.

예제 1

요청이 **미국(US)**에서 시작되고 URI가 /wp-admin/ 또는 **/wp-login/**인 경우 요청을 허용하는 사용자 지정 규칙 문입니다.

규칙 논리: 요청이 (미국에서 시작) AND URI가 (/a OR /b).

{
  "Name": "test",
  "Priority": 100,
  "Statement": {
    "AndStatement": {
      "Statements": [
        {
          "GeoMatchStatement": {
            "CountryCodes": [
              "US"
            ]
          }
        },
        {
          "OrStatement": {
            "Statements": [
              {
                "ByteMatchStatement": {
                  "SearchString": "/wp-admin/",
                  "FieldToMatch": {
                    "UriPath": {}
                  },
                  "TextTransformations": [
                    {
                      "Priority": 0,
                      "Type": "NONE"
                    }
                  ],
                  "PositionalConstraint": "CONTAINS"
                }
              },
              {
                "ByteMatchStatement": {
                  "SearchString": "/wp-login/",
                  "FieldToMatch": {
                    "UriPath": {}
                  },
                  "TextTransformations": [
                    {
                      "Priority": 0,
                      "Type": "NONE"
                    }
                  ],
                  "PositionalConstraint": "CONTAINS"
                }
              }
            ]
          }
        }
      ]
    }
  },
  "Action": {
    "Allow": {}
  },
  "VisibilityConfig": {
    "SampledRequestsEnabled": true,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "test"
  }
}

예제 2

BODY에 XSS 서명이 있는 경우 요청을 차단하지만 URI가 /test, /login, /admin인 경우 검사에서 제외하는 사용자 지정 규칙 문입니다.

규칙 논리: 요청이 (본문에 XSS 서명이 있다) AND URI가 NOT(/a OR /b OR /c).

{
 "Name": "XSS_Block_Allow_Uploads",
 "Priority": 100,
 "Statement": {
     "AndStatement": {
     "Statements": [
       {
         "XssMatchStatement": {
           "FieldToMatch": {
             "Body": {}
           },
           "TextTransformations": [
             {
               "Priority": 0,
               "Type": "NONE"
             }
           ]
         }
       },
   {
    "NotStatement": {
     "Statement": {
      "OrStatement": {
       "Statements": [
                 {
                   "ByteMatchStatement": {
                     "SearchString": "/test",
                     "FieldToMatch": {
                       "UriPath": {}
                     },
                     "TextTransformations": [
                       {
                         "Priority": 0,
                         "Type": "NONE"
                       }
                     ],
                     "PositionalConstraint": "EXACTLY"
                   }
                 },
                 {
                   "ByteMatchStatement": {
                     "SearchString": "/admin",
                     "FieldToMatch": {
                       "UriPath": {}
                     },
                     "TextTransformations": [
                       {
                         "Priority": 0,
                         "Type": "NONE"
                       }
                     ],
                     "PositionalConstraint": "EXACTLY"
                   }
                 },
                 {
                   "ByteMatchStatement": {
                     "SearchString": "/login",
                     "FieldToMatch": {
                       "UriPath": {}
                     },
                     "TextTransformations": [
                       {
                         "Priority": 0,
                         "Type": "NONE"
                       }
                     ],
                     "PositionalConstraint": "EXACTLY"
                   }
                 }
               ]
             }
           }
         }
       }
     ]
   }
 },
 "Action": {
   "Block": {}
 },
 "VisibilityConfig": {
   "SampledRequestsEnabled": true,
   "CloudWatchMetricsEnabled": true,
   "MetricName": "XSS_Block_Allow_Uploads"
 }
}

예제 3

사용자 지정 레이블 internal이 포함되어 있지만 호스트, IP 및 URI가 특정 조합이 아닌 경우 요청을 차단하는 사용자 지정 규칙 문입니다.

규칙 논리: 요청이 (레이블 포함) AND NOT(URI AND IP AND 호스트)인 경우 차단.

{
  "Name": "Block_internal_unauthorized",
  "Priority": 100,
  "Statement": {
    "AndStatement": {
      "Statements": [
      {
          "LabelMatchStatement": {
            "Scope": "LABEL",
            "Key": "internal"
          }
        },
        {
          "NotStatement": {
            "Statement": {
              "AndStatement": {
                "Statements": [
                {
                    "ByteMatchStatement": {
                      "FieldToMatch": {
                        "UriPath": {}
                      },
                      "PositionalConstraint": "EXACTLY",
                      "SearchString": "/test",
                      "TextTransformations": [{
                        "Type": "NONE",
                        "Priority": 0
                      }]
                    }
                  },
                  {
                    "IPSetReferenceStatement": {
                      "ARN": "arn:aws:wafv2:us-east-1:xxxxxxxxxxxx:regional/ipset/internal_IPs/xxx-xx-xxx"
                    }
                  },
                  {
                    "ByteMatchStatement": {
                      "FieldToMatch": {
                        "SingleHeader": {
                          "Name": "host"
                        }
                      },
                      "PositionalConstraint": "EXACTLY",
                      "SearchString": "example.com",
                      "TextTransformations": [{
                        "Type": "NONE",
                        "Priority": 0
                      }]
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  },
  "Action": {
   "Block": {}
 },
 "VisibilityConfig": {
   "SampledRequestsEnabled": true,
   "CloudWatchMetricsEnabled": true,
   "MetricName": "Block_internal_unauthorized"
 }
}

AWS 공식
AWS 공식업데이트됨 2년 전