modsecurity系列五:白名单

Whitelisting mechanics

Whitelisting rules need to be executed before all your other detection rules, which means they should always follow your configuration and system rules. It is a good idea to have a special file for this category of rule alone. That will make them easy to find, after a simple glance at the list of your configuration files. Most whitelisting rules will look at the remote address first, so let’s do just that. Let’s assume that there is a trusted employee to whom you want to give unrestricted access to your web site. The IP address of his workstation is 192.168.1.1. The whitelisting rule is as follows:
SecRule REMOTE_ADDR "@streq 192.168.1.1" \
phase:1,t:none,nolog,allow
Because you only need to work with one IP address you use the @streq operator. Upon detecting a request from the employee’s IP address, the allow action will interrupt the operation of the rule engine, skipping all phases except phase 5. ModSecurity does not have an operator designed specifically to work with IP addresses, so you’ll need to be creative if you are given several IP addresses to whitelist. Suppose you are given three IP addresses. You could write three seperate rules, but that is not only inelegant,but inefficient too. In most such cases, the @rx operator will do the job. For example:
SecRule REMOTE_ADDR "@rx ^192\.168\.1\.(1|5|10)$" \
phase:1,t:none,nolog,allow

The above example whitelists three IP addresses: 192.168.1.1, 192.168.1.5 and 192.168.1.10. As previously discussed, you should avoid using the allow action whenever you can. It is recommended to swith the rule engine to detection-only instead:
SecRule REMOTE_ADDR "@streq 192.168.1.1" \
phase:1,t:none,nolog,pass,ctl:ruleEngine=DetectionOnly

In the above rule, I replaced allow with pass (which won’t do anything else but move to the next rule once the current rule is done), and added an invocation of the ctl action with the instruction to change the operating mode of the rule engine. If you want to take my advice and require some form of authentication in order to activate your whitelisting rules, consider the following example where I also require a correct password to be placed in the User-Agent request header:
SecRule REMOTE_ADDR "@streq 192.168.1.1" \
phase:1,t:none,nolog,pass,ctl:ruleEngine=DetectionOnly,chain
SecRule REQUEST_HEADERS:User-Agent "@contains SECRET_PASSWORD"









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值