我正在尝试处理Web请求的REQUEST_BODY,其中包含Content-Type:text / xml和其中的一些XML。 假设我有以下要求:
curl -v -d " <?xml version="1.0" encoding="UTF-8"?> <methodResponse> <value> <struct> <member> <name>SomeName</name> <value>SomeValue</value> </member> </struct> </value> </methodResponse> " -H "Content-Type:text/xml" http://gryzli.info/some_url.php
我需要的是能够将REQUEST_BODY与“SomeName”或“SomeValue”匹配为纯文本string。
我已经尝试了以下几点:
1.尝试在阶段2上匹配以下关键字:
SecRule REQUEST_BODY "SomeValue" "phase:2, ....." - No success SecRule FULL_REQUEST "SomeValue" "phase:2, ....." - No success SecRule ARGS "SomeValue" "phase:2, ....." - No success
2.除了上面的规则,我试图以不同的组合激活这些规则:
SecRule REQUEST_HEADERS:Content-Type "text/xml" "phase:1,id:100000,t:lowercase,nolog,pass, ctl:requestBodyProcessor=MULTIPART"
要么
SecRule REQUEST_HEADERS:Content-Type "text/xml" "phase:1,id:100000,t:lowercase,nolog,pass, ctl:requestBodyProcessor=URLENCODED"
要么
SecRule REQUEST_HEADERS:Content-Type "text/xml" "phase:1,id:100000,t:lowercase,nolog,pass, ctl:forceRequestBodyVariable=On"
再次 – 没有成功 。
真正的问题是:
当我的客户端请求是Content-Type:text / xml时,有人知道如何在REQUEST_BODY中匹配一个简单的纯文本string吗?
另外,我更喜欢不使用可以parsing我的XML的XML引擎,因为我期望这样做会有很大的性能损失。
最后,我find了匹配XML内容types中的纯文本值的答案,这里是例子:
SecRequestBodyAccess On SecRule REQUEST_HEADERS:Content-Type "text/xml" "phase:1, nolog,pass,ctl:requestBodyProcessor=URLENCODED, id:2222" SecRule REQUEST_BODY "some_bad_string" "phase:2, t:none, deny,msg:'Matched some_bad_string', status:500,auditlog, id:3333"
这是它的作用:
在“阶段:1”(REQUEST_HEADERS阶段)中,如果Content-Type是“text / xml:”则匹配。 如果是,那么将身体处理引擎更改为“ URLENCODED ”
在“phase:2”(REQUEST_BODY阶段)中,匹配明文string“ some_bad_string ”,并阻止状态码为500的请求。