¿Cómo creo reglas JSON de AWS WAF personalizadas y complejas?

4 minutos de lectura
0

¿Cómo creo reglas JSON de AWS WAF personalizadas y complejas?

Resolución

Cree reglas personalizadas complejas en el editor de reglas JSON al agregar una regla personalizada para AWS WAF. Las reglas se crean y administran en ACL web y grupos de reglas en la consola de AWS WAF. Puede acceder a una regla por su nombre en el grupo de reglas o la ACL web donde está definida.

Si su caso de uso requiere una regla personalizada que necesite una combinación de lógica AND, OR o NOT (instrucciones anidadas), debe crear la regla con el editor JSON. Para obtener más información, consulte AWS WAF rule statements (Declaraciones de reglas de AWS WAF).

Consejo: Puede usar el editor visual de reglas, que se encuentra en la consola de AWS WAF, para crear instrucciones de reglas similares a las de su caso de uso. A continuación, para ver las instrucciones JSON, elija Rule JSON editor (Editor de reglas JSON) y realice los cambios necesarios.

Los siguientes ejemplos proporcionan una referencia que puede usar para crear su propia lógica de reglas personalizada:

Ejemplo 1

Esta es una declaración de regla personalizada que permite una solicitud si se origina en Estados Unidos (EE. UU.) y el URI es /wp-admin/ o /wp-login/:

Lógica de reglas: si una solicitud es (de EE. UU.) Y el URI es ( /a O /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"
  }
}

Ejemplo 2

Esta es una declaración de regla personalizada que bloquea una solicitud si tiene firmas XSS en BODY, pero excluye los URI /test, /login y /admin de la inspección:

Lógica de reglas: si una solicitud tiene (firma XSS en el cuerpo) Y el URI NO es ( /a OR /b, O /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"
 }
}

Ejemplo 3

Esta es una declaración de regla personalizada que bloquea una solicitud si contiene una etiqueta personalizada interna, pero el host, la IP y el URI no son una combinación específica:

Lógica de regla: si la solicitud (contiene la etiqueta) Y no (URI e IP y host), bloquee.

{
  "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"
 }
}

OFICIAL DE AWS
OFICIAL DE AWSActualizada hace 2 años