Wie erstelle ich komplexe benutzerdefinierte AWS-WAF-JSON-Regeln?
Wie erstelle ich komplexe benutzerdefinierte AWS-WAF-JSON-Regeln?
Auflösung
Erstellen Sie komplexe benutzerdefinierte Regeln im Rule-JSON-Editor, wenn Sie eine benutzerdefinierte Regel für AWS WAF hinzufügen. Regeln werden in Web-ACLs und Regelgruppen in der AWS-WAF-Konsole erstellt und verwaltet. Sie können auf eine Regel anhand ihres Namens in der Regelgruppe oder in der Web-ACL zugreifen, in der sie definiert ist.
Wenn Ihr Anwendungsfall eine benutzerdefinierte Regel erfordert, die eine Kombination aus UND-, ODER- oder NICHT-Logik (verschachtelte Anweisungen) benötigt, müssen Sie die Regel mit dem JSON-Editor erstellen. Weitere Informationen finden Sie unter AWS-WAF-Regelanweisungen.
Tipp: Sie können den visuellen Editor für Regeln in der AWS-WAF-Konsole verwenden, um Regelanweisungen zu erstellen, die Ihrem Anwendungsfall ähnlich sind. Um dann die JSON-Anweisungen anzuzeigen, wählen Sie Rule-JSON-Editor und nehmen Sie die erforderlichen Änderungen im JSON-Editor vor.
Die folgenden Beispiele bieten eine Referenz, mit der Sie Ihre eigene benutzerdefinierte Regellogik erstellen können:
Beispiel 1
Dies ist eine benutzerdefinierte Regelanweisung, die eine Anfrage zulässt, wenn sie aus den USA stammt und URI /wp-admin/ oder /wp-login/ lautet:
Regellogik: Wenn eine Anfrage (aus den USA) ist UND URI ist (/a ODER /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" } }
Beispiel 2
Dies ist eine benutzerdefinierte Regelanweisung, die eine Anforderung blockiert, wenn sie XSS-Signaturen im BODY hat, aber die URIs /test,/login und /admin von der Prüfung ausschließt:
Regellogik: Wenn eine Anforderung (XSS-Signatur im Hauptteil) UND URI NICHT (/a ODER /b, ODER /c) ist.
{ "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" } }
Beispiel 3
Dies ist eine benutzerdefinierte Regelanweisung, die eine Anforderung blockiert, wenn sie ein benutzerdefiniertes Label intern enthält, Host, IP und URI jedoch keine spezifische Kombination sind:
Regellogik: Wenn Anfrage (enthält die Bezeichnung) UND nicht (URI und IP und Host), dann blockieren.
{ "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" } }
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor 2 Jahren
- AWS OFFICIALAktualisiert vor 2 Jahren
- AWS OFFICIALAktualisiert vor 2 Jahren
- AWS OFFICIALAktualisiert vor einem Jahr