信息系统 |阻止页面特定 url 除了特定的内部 IP 地址
IIS | Block page specific url except for specific internal IP address
我正在尝试阻止所有 IP 地址的 url 页面特定 (http://www.testdomain.com/login),内部管理 IP 地址除外。我没有阻止模式 login 的问题,但我想在本地进行测试以确保内部管理 IP 被排除在 /login url 的阻止规则之外。看看我到目前为止有什么......
<rewrite>
<rules>
<rule name="RequestBlockingRule1" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*login*" negate="false" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{HTTP_X_Forwarded_For}" pattern="92.102.130.65" />
</conditions>
<action type="None" />
</rule>
<rule name="RequestBlockingRule2" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{URL}" pattern="*login*" />
</conditions>
<action type="CustomResponse" statusCode="404" statusReason="File or directory not found." statusDescription="The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable." />
</rule>
我还想要复制相同的规则,但对于 http://www.testdomain.com/home.aspx?ctl=login
的查询字符串
<rule name="RequestBlockingRule3" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*ctl=login*" negate="false" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{HTTP_X_Forwarded_For}" pattern="93.107.170.85" />
</conditions>
<action type="None" />
</rule>
<rule name="RequestBlockingRule4" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{QUERY_STRING}" pattern="*ctl=login*" />
</conditions>
<action type="CustomResponse" statusCode="404" statusReason="File or directory not found." statusDescription="The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable." />
</rule>
</rules>
</rewrite>
我所做的是尝试排除特定模式的内部 IP,然后遵循实际的阻止规则。有谁知道 a) 更好的选择或 b) 看看我可能做错了什么或没有做错什么(理想情况下,我想在使用真实 IP 地址在实际服务器上使用它们之前在本地测试这些规则)。谢谢
我想建议使用一些不同的方式:
- 为列入白名单的 IP 列表使用重写映射
- 只使用两条规则,不使用
<action type="None" />
配置代码为:
<rewrite>
<rules>
<rule name="Block login page" stopProcessing="true">
<match url="^login$" />
<conditions>
<add input="{Authorised Admin IPs:{REMOTE_ADDR}}" pattern="1" negate="true" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="Block query string" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{Authorised Admin IPs:{REMOTE_ADDR}}" pattern="1" negate="true" />
<add input="{QUERY_STRING}" pattern="ctl=login" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
</rules>
<rewriteMaps>
<!-- This is your list of white-listed IP's-->
<rewriteMap name="Authorised Admin IPs">
<add key="92.102.130.65" value="1" />
<add key="93.107.170.85" value="1" />
<!-- local IPs-->
<add key="127.0.0.1" value="1" />
<add key="localhost" value="1" />
<add key="::1" value="1" />
</rewriteMap>
</rewriteMaps>
</rewrite>
此规则阻止所有用户对此 URL 的所有请求,这些用户具有未列入白名单的 IP
- http://www.testdomain.com/login
- 任何url,在查询字符串
中有ctl=login
在我上面的配置中,我使用的是 {REMOTE_ADDR}
。但您可能需要使用 {HTTP_X_Forwarded_For}
。这取决于您的网络基础设施(如果您有代理或负载平衡器)
您可以通过 adding/removing 您的本地 IP 表单重写映射
在本地测试此规则
我正在尝试阻止所有 IP 地址的 url 页面特定 (http://www.testdomain.com/login),内部管理 IP 地址除外。我没有阻止模式 login 的问题,但我想在本地进行测试以确保内部管理 IP 被排除在 /login url 的阻止规则之外。看看我到目前为止有什么......
<rewrite>
<rules>
<rule name="RequestBlockingRule1" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*login*" negate="false" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{HTTP_X_Forwarded_For}" pattern="92.102.130.65" />
</conditions>
<action type="None" />
</rule>
<rule name="RequestBlockingRule2" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{URL}" pattern="*login*" />
</conditions>
<action type="CustomResponse" statusCode="404" statusReason="File or directory not found." statusDescription="The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable." />
</rule>
我还想要复制相同的规则,但对于 http://www.testdomain.com/home.aspx?ctl=login
的查询字符串 <rule name="RequestBlockingRule3" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*ctl=login*" negate="false" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{HTTP_X_Forwarded_For}" pattern="93.107.170.85" />
</conditions>
<action type="None" />
</rule>
<rule name="RequestBlockingRule4" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{QUERY_STRING}" pattern="*ctl=login*" />
</conditions>
<action type="CustomResponse" statusCode="404" statusReason="File or directory not found." statusDescription="The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable." />
</rule>
</rules>
</rewrite>
我所做的是尝试排除特定模式的内部 IP,然后遵循实际的阻止规则。有谁知道 a) 更好的选择或 b) 看看我可能做错了什么或没有做错什么(理想情况下,我想在使用真实 IP 地址在实际服务器上使用它们之前在本地测试这些规则)。谢谢
我想建议使用一些不同的方式:
- 为列入白名单的 IP 列表使用重写映射
- 只使用两条规则,不使用
<action type="None" />
配置代码为:
<rewrite>
<rules>
<rule name="Block login page" stopProcessing="true">
<match url="^login$" />
<conditions>
<add input="{Authorised Admin IPs:{REMOTE_ADDR}}" pattern="1" negate="true" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
<rule name="Block query string" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{Authorised Admin IPs:{REMOTE_ADDR}}" pattern="1" negate="true" />
<add input="{QUERY_STRING}" pattern="ctl=login" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden" statusDescription="Forbidden" />
</rule>
</rules>
<rewriteMaps>
<!-- This is your list of white-listed IP's-->
<rewriteMap name="Authorised Admin IPs">
<add key="92.102.130.65" value="1" />
<add key="93.107.170.85" value="1" />
<!-- local IPs-->
<add key="127.0.0.1" value="1" />
<add key="localhost" value="1" />
<add key="::1" value="1" />
</rewriteMap>
</rewriteMaps>
</rewrite>
此规则阻止所有用户对此 URL 的所有请求,这些用户具有未列入白名单的 IP
- http://www.testdomain.com/login
- 任何url,在查询字符串 中有
ctl=login
在我上面的配置中,我使用的是 {REMOTE_ADDR}
。但您可能需要使用 {HTTP_X_Forwarded_For}
。这取决于您的网络基础设施(如果您有代理或负载平衡器)
您可以通过 adding/removing 您的本地 IP 表单重写映射
在本地测试此规则