modsecurity系列三:规则2-Operators

Operators
In the examples so far the assumption was that we are always going to use regular pattern matching against input. While regular expressions are very useful, there are often times when you want to do something else. That is when operators come to play. The truth is that ModSecurity always uses an operator, but that it assumes that you want to use regular patterns matching unless you specify an operator in a rule. So, to start with, here’s a rule that explicitly specifies an operator- -the regular pattern matching one!
SecRule ARGS:username "@rx ^(admin|root)$"
The above rule which checks if the requested username is admin or root. You may have
noticed a few things:
• Operators begin with a @ character.
• Operators are always placed at the beginning of the second SecRule token.
• There’s always a space after an operator. Whatever follows the space is the single operator
parameter. In the case of the @rx operator, the parameter is a regular expression.
• When you have a rule with an explicit operator you’ll need to use double quotes

around the token, because there’s always going to be a space character


String matching operators
String matching operators all take a string on input and attempt to match it to the provided
parameter. The @rx and @pm operators are the ones commonly used, because of their versatility
(@rx) and speed (@pm), but the remaining operators are also useful, especially if you
need variable expansion, which neither @rx nor @pm support.

常用的操作符如下

@beginsWith Begins with
@contains Contains
@endsWith Ends with
@rx Regular pattern match
@pm Parallel matching 相识匹配
@pmFromFile (@pmf in v2.6) Parallel matching, with arguments from a file
@streq String equal to
@within Within


Numerical operators
Numerical operators, in Table 5.10, “Numerical operators” make comparing numerical values
easy (previously you had to resort to using complex regular expressions).

Operator Description
@eq Equal
@ge Greater or equal
@gt Greater than
@le Less or equal
@lt Less than


Validation operators
Validation operators, in Table 5.11, “Validation operators”, all validate input in some way.

Operator Description
@validateByteRange Validates that parameter consists only of allowed byte values
@validateDTD Validates XML payload against a DTD
@validateSchema Validates XML payload against a Schema
@validateUrlEncoding Validates an URL-encoded string
@validateUtf8Encoding Validates an UTF-8 encoded string


Miscellaneous operators  其他操作
And, finally, there’s the miscellaneous category (Table 5.12, “Miscellaneous operators”),which offers some very useful functionality.

Operator Description
@geoLookup Determines the physical location of an IP address
@inspectFile Invokes an external script to inspect a file 调用外部脚本来检查一个文件
@rbl Looks parameter against a RBL (real-time block list)
@verifyCC Checks if the parameter is a valid credit card number 是否是有效的信用卡号码




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值