AWS WAF で16進数を用いた文字列一致ステートメントが想定通りの挙動にならない場合の解消方法を教えてください

AWS WAF で16進数を用いた文字列一致ステートメントが想定通りの挙動にならない場合の解消方法を教えてください

Clock Icon2024.05.20 00:22

困っていた内容

AWS WAF の WebACL で16進数で始まる通信を許可する文字列一致ステートメントを用いたルールを作成したところ、期待通りに通信が許可されませんでした。どのようにすれば期待通りの挙動に設定できるでしょうか。

具体的な解決方法

例えば、16進数「42444D」を表す「BDM」のような単純な文字列の場合は、AWS WAF コンソール上で指定することが可能です。しかしながら、「C2CECD」のような16進数の場合、それを表す文字列を入力することが困難な場合があります。

単純な文字列で表すことが難しい16進数「C2CECD」のようなバイナリデータを文字列一致ルールステートメントで検査したい場合、対象の16進数をBase64エンコードし、AWS CLIを用いて update-web-acl コマンドから対象のBase64エンコードされた文字列を検査対象として SearchString を設定することで、ルールを作成できます。

update-web-acl

ByteMatchStatement -> (structure)
A rule statement that defines a string match search for WAF to apply to web requests. The byte match statement provides the bytes to search for, the location in requests that you want WAF to search, and other settings. The bytes to search for are typically a string that corresponds with ASCII characters. In the WAF console and the developer guide, this is called a string match statement.

SearchString -> (blob)
A string value that you want WAF to search for. WAF searches only in the part of web requests that you designate for inspection in FieldToMatch . The maximum length of the value is 200 bytes.
...
If you're using the WAF API
Specify a base64-encoded version of the value. The maximum length of the value before you base64-encode it is 200 bytes. For example, suppose the value of Type is HEADER and the value of Data is User-Agent . If you want to search the User-Agent header for the value BadBot , you base64-encode BadBot using MIME base64-encoding and include the resulting value, QmFkQm90 , in the value of SearchString . If you're using the CLI or one of the Amazon Web Services SDKs
The value that you want WAF to search for. The SDK automatically base64 encodes the value.
...

※注意:16進数「C2CECD」のように単純な文字列で表すことが難しい16進数をAWS CLIで設定した後、AWS WAF コンソールからルールを変更すると、「String to match」の変更を行わなくても検査対象が変わる可能性があります。そのため、ルールアクション等を変更したい場合は、AWS CLI から設定してください。

参考情報

この記事をシェアする

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.