AWS WAF의 HTTP 요청에 대한 XSS 또는 SQLi 검사에서 특정 URI를 제외하려면 어떻게 해야 하나요?

5분 분량
0

AWS WAF를 사용할 때 특정 HTTP 요청에서 SQL 인젝션(SQLi) 또는 크로스 사이트 스크립팅(XSS)에 대해 오탐지가 발생합니다. HTTP 요청에 대한 XSS 또는 SQLi 검사에서 특정 URI를 제외하고 싶습니다.

간략한 설명

AWS 관리형 규칙 및 사용자 지정 규칙에 대한 XSS 및 SQLi 규칙 검사 중에 오탐이 발생하는 경우가 있습니다. 오탐을 방지하려면 XSS 및 SQLi 검사에서 특정 URI 경로를 제외하세요. 이렇게 하려면 중첩된 명령문을 사용하여 예외가 포함된 차단 규칙을 작성하여 AWS WAF가 다른 모든 규칙을 기준으로 요청을 평가하도록 하세요.

해결 방법

HTTP 또는 HTTPS 요청의 예

http://www.amazon.com/path/string1?xss=%3Cscript%3E%3Cscript%3E&sql=UNION%20ALL%20SELECT%201

이 요청에서 URI 경로는 /path/string1입니다. 물음표(?) 다음에 오는 문자열은 쿼리 문자열입니다. 이 예제에서 쿼리 문자열은 xss=%3Cscript%3E%3Cscript%3E&sql=UNION%20ALL%20SELECT%201입니다.

XSS 또는 SQLi 검사의 특정 URI를 허용하는 예제 규칙

참고: 다음 예제 규칙 구성은 참조용입니다. PositionalConstraint, SearchString, TextTransformations 등에 대해 이러한 규칙을 사용자 정의하세요. 유사한 로직을 사용하여 특정 헤더, 쿼리 매개변수 등을 허용할 수 있습니다.

사례 1: AWS 관리형 규칙 사용

AWS 관리형 규칙 그룹 AWSManagedRulesCommonRuleSet에는 다음과 같은 규칙이 포함되어 있습니다.

  • CrossSiteScripting_COOKIE
  • CrossSiteScripting_QUERYARGUMENTS
  • CrossSiteScripting_BODY
  • CrossSiteScripting_URIPATH

AWSManagedRulesCommonRuleSet 규칙 그룹에는 요청의 해당 부분에서 XSS 공격 문자열을 검사하는 BLOCK 작업이 있습니다. 자세한 내용은 핵심 규칙 세트(CRS) 관리 규칙 그룹을 참조하세요.

마찬가지로 규칙 그룹 AWSManagedRulesSQLiRuleSet에는 SQLi 인젝션 공격 패턴에 대한 쿼리 파라미터, 본문, URI 경로 및 쿠키를 검사하는 규칙이 있습니다. 자세한 내용은 사용 사례별 규칙 그룹을 참조하세요.

요청이 이러한 규칙과 일치하면 AWS WAF가 해당 레이블을 생성합니다. 그러면 WEB ACL의 사용자 지정 규칙이 이러한 AWS 관리형 규칙 레이블을 사용하여 일치하는 규칙 서명에서 특정 요청을 선택적으로 제외할 수 있습니다.

특정 URI를 허용하려면 다음 단계를 완료하세요.

1. 카운트 모드에서 AWSManagedRulesCommonRuleSet 규칙 그룹의 다음 규칙을 유지하세요.

  • CrossSiteScripting_COOKIE
  • CrossSiteScripting_QUERYARGUMENTS
  • CrossSiteScripting_BODY
  • CrossSiteScripting_URIPATH

2. URI Path에 대한 예외를 제외하고 블록 액션이 포함된 규칙을 생성합니다. AWSManagedRulesCommonRuleSet의 우선 순위보다 낮은 우선 순위로 규칙을 구성합니다. AWS WAF 콘솔에서 낮은 우선 순위를 구성하려면 목록에서 규칙을 더 낮게 배치하세요. JSON에서 낮은 우선 순위를 구성하려면 더 큰 Priority 값을 사용하세요.

이 규칙은 다음 로직을 사용합니다.

(XSS_URIPATH or XSS_Cookie or XSS_Body or XSS_QueryArguments) AND (NOT allowlisted URIString) = BLOCK

다음 구성을 사용하세요.

{
  "Name": "whitelist-xss",
  "Priority": 10,
  "Statement": {
    "AndStatement": {
      "Statements": \[
        {
          "OrStatement": {
            "Statements": \[
              {
                "LabelMatchStatement": {
                  "Scope": "LABEL",
                  "Key": "awswaf:managed:aws:core-rule-set:CrossSiteScripting\_URIPath"
                }
              },
              {
                "LabelMatchStatement": {
                  "Scope": "LABEL",
                  "Key": "awswaf:managed:aws:core-rule-set:CrossSiteScripting\_Cookie"
                }
              },
              {
                "LabelMatchStatement": {
                  "Scope": "LABEL",
                  "Key": "awswaf:managed:aws:core-rule-set:CrossSiteScripting\_Body"
                }
              },
              {
                "LabelMatchStatement": {
                  "Scope": "LABEL",
                  "Key": "awswaf:managed:aws:core-rule-set:CrossSiteScripting\_QueryArguments"
                }
              }
            \]
          }
        },
        {
          "NotStatement": {
            "Statement": {
              "ByteMatchStatement": {
                "SearchString": "/path/string1",
                "FieldToMatch": {
                  "UriPath": {}
                },
                "TextTransformations": \[
                  {
                    "Priority": 0,
                    "Type": "NONE"
                  }
                \],
                "PositionalConstraint": "CONTAINS"
              }
            }
          }
        }
      \]
    }
  },
  "Action": {
    "Block": {}
  },
  "VisibilityConfig": {
    "SampledRequestsEnabled": true,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "whitelist-xss"
  }
}

참고: 이 예제에서 OrStatement는 웹 요청의 모든 레이블과 부분(본문, 헤더, URI 경로, 쿼리 인수)에서 특정 URI를 제외합니다. 이 예제에서는 웹 요청의 모든 부분에서 동일한 URI에 대해 오탐이 발생했다고 가정합니다. 하지만 쿼리 인수와 같이 웹 요청의 한 부분에서만 오탐이 발생할 수 있습니다. 이 경우 웹 요청의 한 부분과 일치하는 레이블에 대해서만 별도의 규칙을 만드는 것이 보안 모범 사례입니다. 이 개별 규칙의 경우 웹 요청의 모든 부분에서 특정 URI 경로를 제외하지 마세요.

AWSManagedRulesSQLiRuleSet의 경우 동일한 단계를 사용하되, 레이블을 AWSManagedRulesSQLiRuleSet에서 생성한 레이블로 교체하세요.

검사에서 제외하려는 URI가 여러 개 있는 경우 NotStatement 내에서 OrStatement를 사용하세요. 예를 들어 /path/string1 and /path/string2를 제외하려면 다음 NotStatement 명령을 사용하세요.

{
  "NotStatement": {
    "Statement": {
      "OrStatement": {
        "Statements": \[
          {
            "ByteMatchStatement": {
              "SearchString": "/path/string1",
              "FieldToMatch": {
                "UriPath": {}
              },
              "TextTransformations": \[
                {
                  "Priority": 0,
                  "Type": "NONE"
                }
              \],
              "PositionalConstraint": "CONTAINS"
            }
          },
          {
            "ByteMatchStatement": {
              "SearchString": "/path/string2",
              "FieldToMatch": {
                "UriPath": {}
              },
              "TextTransformations": \[
                {
                  "Priority": 0,
                  "Type": "NONE"
                }
              \],
              "PositionalConstraint": "CONTAINS"
            }
          }
        \]
      }
    }
  }
}

사례 2: 사용자 지정 XSS 및 SQLi 규칙 사용

이 규칙은 다음 로직을 사용합니다.

(XSS_URIPATH or XSS_Cookie or XSS_Body or XSS_QueryArguments) AND (NOT allowlisted URIString) = BLOCK

다음 규칙 구성을 사용하여 요청의 XSS 공격 문자열을 검사하고 특정 URI_PATH는 선택적으로 제외하세요.

{
  "Name": "xss-URI",
  "Priority": 10,
  "Action": {
    "Block": {}
  },
  "VisibilityConfig": {
    "SampledRequestsEnabled": true,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "xss-URI"
  },
  "Statement": {
    "AndStatement": {
      "Statements": \[
        {
          "OrStatement": {
            "Statements": \[
              {
                "XssMatchStatement": {
                  "FieldToMatch": {
                    "UriPath": {}
                  },
                  "TextTransformations": \[
                    {
                      "Priority": 0,
                      "Type": "NONE"
                    }
                  \]
                }
              },
              {
                "XssMatchStatement": {
                  "FieldToMatch": {
                    "Cookies": {
                      "MatchPattern": {
                        "All": {}
                      },
                      "MatchScope": "ALL",
                      "OversizeHandling": "CONTINUE"
                    }
                  },
                  "TextTransformations": \[
                    {
                      "Priority": 0,
                      "Type": "NONE"
                    }
                  \]
                }
              },
              {
                "XssMatchStatement": {
                  "FieldToMatch": {
                    "Body": {
                      "OversizeHandling": "CONTINUE"
                    }
                  },
                  "TextTransformations": \[
                    {
                      "Priority": 0,
                      "Type": "NONE"
                    }
                  \]
                }
              },
              {
                "XssMatchStatement": {
                  "FieldToMatch": {
                    "AllQueryArguments": {}
                  },
                  "TextTransformations": \[
                    {
                      "Priority": 0,
                      "Type": "NONE"
                    }
                  \]
                }
              }
            \]
          }
        },
        {
          "NotStatement": {
            "Statement": {
              "ByteMatchStatement": {
                "FieldToMatch": {
                  "UriPath": {}
                },
                "PositionalConstraint": "CONTAINS",
                "SearchString": "/path/string1",
                "TextTransformations": \[
                  {
                    "Type": "NONE",
                    "Priority": 0
                  }
                \]
              }
            }
          }
        }
      \]
    }
  }
}

SQLi 문을 사용할 때는 다음 절차를 따르세요.

참고: URI만 허용하는 우선 순위가 더 높은 규칙을 사용하는 것은 좋은 방법이 아닙니다. 이렇게 하면 허용된 URI_PATH를 포함하는 요청이 웹 ACL에 정의된 다른 모든 규칙에 대해 평가되지 않습니다.

관련 정보

규칙 설명 기본 사항

사이트 간 스크립팅 공격 규칙 설명

SQL 인젝션 공격 규칙 설명

AWS 공식
AWS 공식업데이트됨 8달 전