使用 IIS 重写模块阻止来自特定 IP 的请求

Tho*_*que 2 iis blocking

我正在尝试阻止向我的博客发送大量垃圾邮件的一系列 IP。我无法使用此处描述的解决方案因为它是共享主机,我无法对服务器配置进行任何更改。我只能访问远程 IIS 中的几个选项。

我看到 URL Rewrite 模块有一个阻止请求的选项,所以我尝试使用它。我的规则如下web.config

            <rule name="BlockSpam" enabled="true" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REMOTE_ADDR}" pattern="10\.0\.146\.23[0-9]" ignoreCase="false" />
                </conditions>
                <action type="CustomResponse" statusCode="403" />
            </rule>
Run Code Online (Sandbox Code Playgroud)

不幸的是,如果我把它放在重写规则的末尾,它似乎不会阻止任何东西……如果我把它放在列表的开头,它会阻止一切!似乎没有考虑到条件。

在 UI 中,该stopProcessing选项不可见,true默认情况下。将其更改为falseinweb.config似乎没有任何效果。

我不知道现在该怎么办……有什么想法吗?

Joh*_*Siu 6

#1 WP 插件

Wordpress,查看以下内容,您可能需要也可能不需要插件

  1. 阅读此链接讨论各种 WP 反垃圾邮件插件和调整 WP 设置,以便您不需要插件。
  2. 前 10 名 WP 反垃圾邮件插件
  3. Wordpress 插件页面

由于您确实可以控制 Web 服务器,因此安装插件应该没有问题。

#2 IIS Web.config

可以使用 IIS Web.config 完成 IP 基础阻止,以下是允许所有但阻止特定 IP 的示例

<security>
   <ipSecurity allowUnlisted="true">    <!-- this line allows everybody, except those listed below -->            
       <clear/>     <!-- removes all upstream restrictions -->                
       <add ipAddress="83.116.19.53"/>     <!-- blocks the specific IP of 83.116.19.53  -->                
       <add ipAddress="83.116.119.0" subnetMask="255.255.255.0"/>     <!--blocks network 83.116.119.0 to 83.116.119.255-->                
       <add ipAddress="83.116.0.0" subnetMask="255.255.0.0"/>     <!--blocks network 83.116.0.0 to 83.116.255.255-->                
       <add ipAddress="83.0.0.0" subnetMask="255.0.0.0"/>     <!--blocks entire /8 network of 83.0.0.0 to 83.255.255.255-->                
   </ipSecurity>
</security>
Run Code Online (Sandbox Code Playgroud)

链接中的更多信息。

#3 IIS Web.config 重写

在这里找到以下内容,也许您可​​以尝试一下。

<!-- Heading for the XML File -->
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <!-- This is where the rules start, this one will block EVERYTHING on your site with the <match url=".*" /> -->
            <rules>
                <rule name="Blocked Users" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <!-- This will just go to the 'Bad Ips' rewriteMap below and compare it to the REMOTE_ADDR which is the requesting IP -->
                        <add input="{Bad Ips:{REMOTE_ADDR}}" pattern="1" />
                    </conditions>
                    <!-- Actions can be Custom Rewrite, Redirect, or Just Abort Request, uncomment examples as needed -->
                    <action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
                    <!-- This one will rewrite url to specified file
                    <action type="Rewrite" url="error.html" appendQueryString="false" /> -->
                    <!-- This on will redirect to another site
                    <action type="Redirect" url="http://www.google.com" appendQueryString="false" /> -->
                    <!-- This one will just Abort
                    <action type="AbortRequest" /> -->
                </rule>
            </rules>
            <!-- This rewrite Map is where you choose your blocked IP's, values with 1 are blocked, all others are ignored, simple add your keys -->
            <rewriteMaps>
                <rewriteMap name="Bad Ips">
                    <!-- This one will use wildcards -->
                    <add key="108.166.*.*" value="1" />
                    <!-- This one wil use static IP -->
                    <add key="12.13.15.16" value="1" />
                </rewriteMap>
            </rewriteMaps>
        </rewrite>
    </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)