在 IIS 中,我可以根据 url 或查询字符串设置请求过滤,这允许我阻止一些恶意 GET 请求,但这对发布数据不起作用。
Example:
如果我在 web.config 中设置它
<security>
<requestFiltering>
<filteringRules>
<filteringRule name="Stop spam" scanUrl="false" scanQueryString="true">
<denyStrings>
<clear />
<add string="spam" />
</denyStrings>
<scanHeaders>
<clear />
</scanHeaders>
<appliesTo>
<clear />
</appliesTo>
</filteringRule>
</filteringRules>
</requestFiltering>
</security>
查询字符串中包含“垃圾邮件”一词的请求将被阻止。但是,我还需要阻止包含该单词的 POST 请求(例如来自表单的请求)。我可以设置拒绝规则来根据 POST 数据过滤和拒绝请求吗?如果可以,我该怎么做?
这似乎无法在 IIS 中完成,但我确实设法在网站本身中找到了解决方法。将其添加到全局.asax似乎确实完成了这项工作:
protected void Application_BeginRequest(object sender, EventArgs e)
{
var sr = new System.IO.StreamReader(Request.InputStream);
string content = sr.ReadToEnd();
var rule = @"spam";
if
(
Regex.IsMatch(content, rule, RegexOptions.IgnoreCase) ||
Regex.IsMatch(Request.Url.Query, rule, RegexOptions.IgnoreCase)
)
{
// TODO: Do some logging here
throw new Exception("Get off my lawn!");
}
}
只是稍微抬起头。除非您知道自己在做什么,否则不要使用此功能。这将测试所有请求(并使用正则表达式),因此会减慢网站速度。它也不能解决所有恶意请求。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)