【发布时间】:2020-12-01 21:12:56
【问题描述】:
我希望阻止来自用户的http://anything.com/something.php?hack_attempt=select * 之类的请求。
为此,我在 .htaccess 中执行此操作
RewriteCond %{QUERY_STRING} ^.*(md5|benchmark|union|select|insert|cast|set|declare|drop|update).* [NC]
问题是这条规则也符合http://anything.com/update.php
据我所知,%{QUERY_STRING} 应该只在 ? 之后包含 get params 字符串,但它会命中 URI。
谁能建议问题出在哪里?
更新:完整规则
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^.*(localhost|loopback|127\.0\.0\.1).* [NC,OR]
#RewriteCond %{QUERY_STRING} ^.*(\.|\*|;|<|>|'|"|\)|%0A|%0D|%22|%27|%3C|%3E|%00).* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*/ban_url/ [NC,OR]
#RewriteCond %{QUERY_STRING} ^.*(md5|benchmark|union|select|insert|cast|set|declare|drop|update).* [NC]
RewriteCond %{QUERY_STRING} ^.*(md5|benchmark|union|insert|cast|set|declare|drop).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*\?.*(md5|benchmark|union|select|insert|cast|set|declare|drop|update).* [NC]
RewriteRule ^(.*)$ - [R=400,L]
</IfModule>
如果我取消注释
RewriteCond %{QUERY_STRING} ^.*(md5|benchmark|union|select|insert|cast|set|declare|drop|update).* [NC]
那么 Apache 将阻止 www.anything.com/update.php 但它应该只阻止www.anything.com/something.php?param=update
更新 2:完整配置
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^.*(localhost|loopback|127\.0\.0\.1).* [NC,OR]
#RewriteCond %{QUERY_STRING} ^.*(\.|\*|;|<|>|'|"|\)|%0A|%0D|%22|%27|%3C|%3E|%00).* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*/ban_url/ [NC,OR]
#RewriteCond %{QUERY_STRING} ^.*(md5|benchmark|union|select|insert|cast|set|declare|drop|update).* [NC]
RewriteCond %{QUERY_STRING} ^.*(md5|benchmark|union|insert|cast|set|declare|drop).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*\?.*(md5|benchmark|union|select|insert|cast|set|declare|drop|update).* [NC]
RewriteRule ^(.*)$ - [R=400,L]
RewriteCond %{REQUEST_URI} ^.*wp-* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*www\.zip* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*backup\.zip* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*public_html\.zip* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*\.tar\.gz* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*administrator* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*admin\.php* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*admin/index\.php* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*elrekt\.php* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*_adminer* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*accesson* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*agentui* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*trackback* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*wp-login* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*router\.php* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*AspCms_AdminAdd* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*public/js/wind* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*include/calendar/calendar-cn* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*app-ads* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*vendor/phpunit/* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*utility/* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*blackhat* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*data/admin/allowurl* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*js/varien* [NC,OR] #magento
RewriteCond %{REQUEST_URI} ^.*js/mage* [NC,OR] #magento
RewriteCond %{REQUEST_URI} ^.*magento_version* [NC,OR] #magento
RewriteCond %{REQUEST_URI} ^.*db_z\.php* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*functions\.php* [NC,OR]
RewriteCond %{REQUEST_URI} ^.*lottery-index* [NC]
RewriteRule ^(.*)$ - [R=400,L]
</IfModule>
这个 conf 文件被应用在站点 conf 中
<VirtualHost *:80>
Include /var/www/url_blacklist.conf
ServerName ...
DocumentRoot ...
ErrorLog ...
</VirtualHost>
【问题讨论】:
-
请发布您的
RewriteRule并更具体地说明您遇到的问题。 -
@AmitVerma 更新
-
@MykolaMykolayovichDolynskyi,字符串
hack_attempt=是您查询字符串中真实字符串的样本之一(如果不是,请提及样本中可能存在的任何内容)?请确认一次。 -
@RavinderSingh13 不真实,我只想搜索仅在获取参数(?符号之后)中的任何禁用词,但实际上它也在 URI 中找到它们。我不能使用示例,因为我不知道下次会部署哪种攻击机器人
-
“更新:完整规则” - 这是你现在的完整重写配置,还是你也在做其他事情?你所说的正在发生,不能用你目前所展示的来解释,像htaccess.madewithlove.be这样的测试工具也同意。
标签: apache .htaccess mod-rewrite url-rewriting