今回はURIに特定の文字列を含むリクエストをブロックするルールを作成して実際にブロックされるか確認してみましょう。検知する文字列は”test.txt”にします。
目次
Conditionの作成
1.AWS WAFのコンソール画面にて [ String and regex matching ] をクリックします。
2.[ Create condition ] をクリックします。

3.「Name」には任意の名前を入力します。 今回は ”test_txt”とします。「Filter settings」内の「Part of the request to filter on」でリクエスト内のフィルターをかける部分を「URI」にします。次に「Matching type」を「Contains」にし、「Transformation」は「None」にします。最後に「Value in match」に “test.txt”と入力したら [Add filter] をクリックします。

4.入力が完了しましたら最後に [ Add filter ] をクリックしてConditionを追加します。「Filters in this string match condition」へのフィルター追加が確認できましたら [ Create ] をクリックして作成します。

これでConditionの作成ができました。
Ruleの作成
1.メニューから[ Rules ]をクリックします。

2.Rules設定画面が表示されたら [ Create rule ] をクリックし、Rule(“TEST_TXT_RULE”)の作成を行います。

3.先ほど、作成したCondition(“test_txt”)を設定します。「What a requests」リクエストがConditionと一致している場合に適用する「does」、一致していない場合に適用する「does not」を選択します。

4.フィルタリングの種類を「match at least one of filters in the string match condition」にします。Conditionの一覧から該当するCondition(“test_txt”)を選択して追加を確認したら [ Create ] をクリックします。

これでRuleの作成が完了しました。
ACL( Access Control List )への追加
1.[ Web ACLs ] をクリックします。先程作成した Rule を追加したいACLをクリックします。 私は“RULE_TEST”というWeb ACLにします 。

2.[ Rules ] のタブをクリックして、[ Edit web ACL ] をクリックします。[ Rules ] のプルダウンで今回作成したRuleを選択し、[ Add rule to web ACL ] をクリックすると「If a request matches all the conditions in a rule, take the corresponding action」に追加されます。今回はブロックをしたいため「Action」は「Block」をチェックします。

3.続いて「Default action」を「Allow」にチェックをいれ [ Update ] をクリックします。Default actionは検知対象外のリクエストを「許可」または「拒否」どちらにするかを設定する項目になりますのでここを「Block」にするとRuleで許可されたリクエスト以外は全てブロックされてしまいます。ご注意ください。

これでWeb ACLにRuleを追加できました。

では実際にテストを行ってみます。このRuleを適用した状態でブラウザで「http://example.com」へアクセスすると以下の画面が表示されます。example.com は環境に応じて適宜変更してください。下記のような画面が出てきたので、問題なくアクセスできました。

では次に「http://example.com/test.txt」にアクセスしてみると “403” のエラーが返ってきました。

このようにルールを設定すると即時で適用され、ブロックすることができます。とても簡単なルールですが、AWS WAFでURIに特定の文字列が含まれるリクエストをブロックする方法をご紹介しました。WAFに興味のある方は是非一度試してみてください。
