WordPress:Combating Comment Spam/Denying Access

来自站长百科
Fludlen讨论 | 贡献2008年6月17日 (二) 14:27的版本
跳转至: 导航、​ 搜索



While denying access to comment spammers may be seen as drastic action, there are ways to prevent access to spammers while still allowing comments to be posted.

虽然拒绝使用评论spammers被看做是过激的行为,仍然有许多种方法可以阻止使用spammers,但是仍然允许发表评论。

Keep in mind that most spammers use random IPs. Blocking spammers by their IP does break up spam floods, but it also increases the chance of blocking legitimate users.

要牢记大多数垃圾邮件发送者使用随意的IPs。通过垃圾广告者的IP来阻止他们,会阻止垃圾广告的泛滥,但是也会增加阻止合法用户的机率

Deny Access to Spammer IPs

否认使用垃圾广告发送者的IPs

When a comment is sent to your weblog, the IP address is included in the packet of information that travels with that comment across the internet. Think of it as a phone number, and the WordPress comment moderation acts like call display to show you where the comment is coming from.

当一个评论发送到你的网络博客上的时候,IP地址包含在一个信息包中,这个信息包与评论一起出现在网络上。将这IP地址看作是一个电话号码,WordPress评论审核就如一个呼叫显示,向你显示这个评论是源于哪里的。

It should be noted that spammers are notorious for hijacking IP addresses, so it is possible that the IP address attached to a spam item is, in fact, "stolen" from a legitimate internet-connected device.

应该注意发送垃圾广告者因为偷劫IP地址,而臭名昭著,因此有可能一个垃圾广告上的IP地址,事实上,可能是从一个合法连接的因特网服务上"偷"来的。

If you watch the IP addresses carefully, you may notice that there is only a slight variation in some of the numbers. For example, you might see:

如果你正确地观看了IP地址,你可能注意到只有某些数字,有一些差异。例如,你可能看到:

  • 192.168.0.1
  • 192.168.0.2
  • 192.168.0.3
  • 192.168.0.1
  • 192.168.0.2
  • 192.168.0.3

And other sequential or similar number orders. You have the ability to add a simpler IP address to your comment spam word list by dropping one or more of the IP numbers, thusly: 192.168 -- in this way, any IP address that starts with 192.168 will be screened as spam regardless of the numbers that appear with this "wildcard". It saves you having to type in lots of individual numbers. Be careful with how generic you make your wildcard IP numbers though, because just using 192. would probably eliminate legitimate IP addresses to comment.

其它连续的或者相似的数字顺序。通过去除一个或者更多的IP数字,如:192.168,你能够给你的评论垃圾广告词列表添加上一个更加简单的IP数字—这样,任何以192.168开始的IP地址都会被筛选为垃圾广告,不管这个与这个"通配符"一起出现的数字是什么。这样省去了你输入许多单个数字的麻烦。要注意你是用的通配IP数字是哪类的,因为只使用192.可能会消除评论上合法的IP地址。

The .htaccess file - which also controls your permalinks - can be used to completely block an IP from even seeing your site. You can place this either in your site root, or the directory where your blog is (if they are different).

.htaccess文件-也控制了你的permlinks-可以用来完全地阻止一个IP来访问你的站点。你可以将这个文件放到你的网站的根目录上,或者网站的博客所在的目录上(如果博客所在目录与根目录不同)。

Below is an example of the .htaccess that is present in the root directory of a website.

下面是呈现在网站根目录上.htaccess的一个例子。

order allow,deny
deny from 123.123.123.123
deny from 456.456.456.*
deny from 789.789.*.*
allow from all


order allow,deny
deny from 123.123.123.123
deny from 456.456.456.*
deny from 789.789.*.*
allow from all
deny from 123.123.123.123
Access is denied to that IP alone

;否认123.123.123.123:只否认使用这个IP

deny from 456.456.456.*
Access is denied to ALL users whose IPs start with 456.456.456
否认456.456.456.*:否认使用所有的IPs以456.456.456开始的用户。
deny from 789.789.*.*
Again, anyone at all with an IP that starts 789.789 is blocked.

否认:789.789.*.* :任何人的IP以789.789开始,都会被阻止。

So a total of 256*256 unique IP addresses are blocked

因此所有256*256唯一IP地址都被阻止了。

If you do start blocking IPs, then a blocked visitor will see a 403 error page. Try to make sure that such a page has your contact details listed. Check your hosting to see how to make a custom 403 (or see below too).

如果你真的开始阻止IPs,那么一个被制止的访客会看到一个403 错误网页。要确定这样的一个网页上列出了联系你的详细信息。查看你的主机来看看怎样制作一个自定义403(或者看看下面的内容)。

If you start blocking IPs with the * wildcard, at least give someone the chance to email you to say you may have made a mistake.

如果你开始使用*通配符来阻止IPs,那么至少给被阻止的用户一次向你发送电子邮件的机会,向你申明,你可能弄错了。

If you want to check that someone is blocked, get a friend's IP, tell them what you are doing, and block them (until you know it works).

如果你想要核实受阻止的人,要得到一个朋友的IP,告诉他们你在执行什么,并且阻止他们(你要知道是可以这样做的,才行)。

Deny Access to No Referrer Requests

否认使用没有链接的请求

When your readers comment, the wp-comments-post.php file is accessed, does its thing, and creates the post. The user's browser will send a "referral" line about this.

当你的读者评论的时候,wp-comments-post.php文件得到了调用,执行,并且创建文章。用户的浏览器会发送一个关于这个的"推举"行。

When a spam-bot comes in, it hits the file directly and usually does not leave a referrer. This allows for some nifty detection and action direct from the server. If you are not familiar with Apache directives, then write the following in your root directory .htaccess file::

当一个spam-bot进入的时候,会直接地袭击文件并且通常不会留下一个链接。这使得服务器能够有意地侦查,并且直接执行。如果你对Apache指令还不熟悉,那么在你的根目录.htaccess file文件上写上以下内容::

RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourdomain.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]


RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourdomain.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

This will: 这样会:

  1. Detect when a POST is being made
  2. 观察什么时候文章写好了
  1. Check to see if the post is on wp-comments-post.php
  1. 查看文章是否在wp-comments-post.php
  1. Check if the referrer is in your domain or if no referrer
  1. 查看referrer是不是在你的域名上,还是没有 referrer
  1. Send the spam-bot BACK to its originating server's IP address.
  1. 将spam-bot发送回到它原来的服务器的IP地址上。
NOTE 1: In the 4th line, change yourdomain.com to your domain.xxx without the www or any prefix for that matter.
NOTE 1:在第四行中,将你的domain.com改为你的domain.xxx没有www或者任何的前缀。
NOTE 2: There is a slim chance that someone's browser will not send the referral, but this is extremely rare.
注 2:有可能某个人的浏览器不会发送referral,但是这种情况很少。

This essentially deflects the spam-bot back on itself.

这本质上是在它自身上偏转了 spam-bot back。

TIP: If you want to see this work, and you know the absolute path to your root directory, then do this:

贴士:如果你想看看这个内容,而且你知道你的根目录的绝对路径,你可以这样做:

RewriteEngine On
RewriteLog /absolute/path/to/your/wwwroot/public_html/rewrite_log.txt
RewriteLogLevel 2

When the RewriteRule is activated, you will get something like this in rewrite_log.txt:

65.197.28.xxx- - [06/Feb/2005:10:59:34 --0500] [yourdomain.com/sid#80054890][rid#804b6a50/initial] (2) init rewrite engine with requested uri /wp-comments-post.php
65.197.28.xxx- - [06/Feb/2005:10:59:34 --0500] [yourdomain.com/sid#80054890][rid#804b6a50/initial] (2) rewrite /press/wp-comments-post.php -> http://65.197.28.xxx/
65.197.28.xxx- - [06/Feb/2005:10:59:34 --0500] [yourdomain.com/sid#80054890][rid#804b6a50/initial] (2) explicitly forcing redirect with http://65.197.28.170/
65.197.28.xxx- - [06/Feb/2005:10:59:34 --0500] [yourdomain.com/sid#80054890][rid#804b6a50/initial] (1) escaping http://65.197.28.xxx/ for redirect
65.197.28.xxx- - [06/Feb/2005:10:59:34 --0500] [yourdomain.com/sid#80054890][rid#804b6a50/initial] (1) redirect to http://65.197.28.xxx/ [REDIRECT/301]

Taken from an actual log




在RewriteEngine On
RewriteLog /absolute/path/to/your/wwwroot/public_html/rewrite_log.txt
RewriteLogLevel 2

当重写规则得到了激活,你可以在rewrite_log.txt上得到以下的内容:

65.197.28.xxx- - [06/Feb/2005:10:59:34 --0500] [yourdomain.com/sid#80054890][rid#804b6a50/initial] (2) init rewrite engine with requested uri /wp-comments-post.php
65.197.28.xxx- - [06/Feb/2005:10:59:34 --0500] [yourdomain.com/sid#80054890][rid#804b6a50/initial] (2) rewrite /press/wp-comments-post.php -> http://65.197.28.xxx/
65.197.28.xxx- - [06/Feb/2005:10:59:34 --0500] [yourdomain.com/sid#80054890][rid#804b6a50/initial] (2) explicitly forcing redirect with http://65.197.28.170/
65.197.28.xxx- - [06/Feb/2005:10:59:34 --0500] [yourdomain.com/sid#80054890][rid#804b6a50/initial] (1) escaping http://65.197.28.xxx/ for redirect
65.197.28.xxx- - [06/Feb/2005:10:59:34 --0500] [yourdomain.com/sid#80054890][rid#804b6a50/initial] (1) redirect to http://65.197.28.xxx/ [REDIRECT/301]

Taken from an actual log

Note: As easy as it is to block IP addresses, it is ineffective against spambots which use compromised machines to spread their spam for two reasons:

注:虽然阻止IP地址非常容易,针对使用折中的机器,因为两个原因散步他们的垃圾广告的spotshot, 这种方法是无效的:

1. The original owners of the machine are still accessing the machine and are most likely decent people who don't deserve to be blocked

1.机器的最初所有者仍然在使用机器而且很可能是有分寸的,不应该被阻止的。

2. The sheer number of such machines will overwhelm anyone trying to block by IP

2.任何人试着被IP阻止,大量这样的机器会泛滥。

Deny Access Referrer Spammers

否认使用 Referrer 垃圾广告发送者

Many bloggers show referrer's to their site or links from which people came to visit their site. Spammers exploit this and indiscriminately spam blogs (even bloggers who do not have this feature enabled) with referral links pointing to their spammy sites. They end up wasting your resources, polluting your legitimate referrer's list and slowing down access for your readers.

许多人在他们的站点上或者链接上显示referrer,这样人们就可以访问他们的站点。发送垃圾广告者侵犯了这个并且不加选择的在博客上发送垃圾广告(即使写博客的人没有这个功能),用referral链接指向他们的spammy站点。他们不再浪费你的资源,弄坏你的合法的referrer的列表,并且降低你的读者访问速度。

In an effort to economize their resources, spammers often send out comment spam bots with their spam referrers for that two-in-one-shot effect. Consequently, you can block quite a few comment spam bots by blocking the referrer spam.

为了节省资源,发送垃圾广告者通过用他们的垃圾广告referres来发送评论垃圾广告bots,得到two-in-one-shot的效果。因此,你可以通过阻止referrer垃圾广告来阻止一些评论垃圾广告。

Once you know which referrer URL you'd like to block, and believe me you'll know, you can keep them out by adding the following into your .htaccess file:

如果你知道了你想要阻止哪个referrer URL,相信我,你就会知道,通过将以下的内容添加到你的.htaccess文件中,你可以阻止那个referrer URL。

SetEnvIfNoCase Via evil-spam-proxy spammer=yes
SetEnvIfNoCase Referer evil-spam-domain.com spammer=yes
SetEnvIfNoCase Referer evil-spam-keyword spammer=yes
SetEnvIfNoCase Via pinappleproxy spammer=yes
SetEnvIfNoCase Referer doobu.com spammer=yes
SetEnvIfNoCase Referer poker spammer=yes

Order allow,deny
allow from all
deny from env=spammer


SetEnvIfNoCase Via evil-spam-proxy spammer=yes
SetEnvIfNoCase Referer evil-spam-domain.com spammer=yes
SetEnvIfNoCase Referer evil-spam-keyword spammer=yes
SetEnvIfNoCase Via pinappleproxy spammer=yes
SetEnvIfNoCase Referer doobu.com spammer=yes
SetEnvIfNoCase Referer poker spammer=yes

Order allow,deny
allow from all
deny from env=spammer


The aforementioned .htaccess rules were brought to you by Tom Raftery, who originally used regular rewrite conditions and later decided that "using SetEnvIfNoCase instead of RewriteCond - seems to be quite effective (especially for referrers)."

上述的.htaccess规则是由Tom Raftery带给你,Tom Raftery最初使用有规则的重写条件,后来决定"使用 SetEnvIfNoCase 来代替RewriteCond – 似乎很有用(特别对referrers而言)。"

Plugins for blocking Referrer Spam can be found on the Official WordPress Plugin Directory.

阻止Referrer垃圾广告的插件可以在官方 WordPress 插件目录中找到。

Using a Custom 403

使用一个自定义 403

It's a regular webpage, and again using .htaccess you tell the server to show your page, not the default one.

这是一个通常的网页,使用.htaccess你命令服务器显示你的网页,而不是默认的网页。

The .htaccess should have this:

.htaccess应该有:

ErrorDocument 403 /errors/403.html
ErrorDocument 403 /errors/403.html


Create a directory called "errors", for example, and put your custom 403 message into that.

例如,创建一个称为"错误"的目录,并且将你的自定义403信息放到这个目录。

Again, to test, block a friend and ask for feedback.

要测试这个,阻止一个朋友并且索要反馈信息。

You create a custom 404 the same way.

你以相同的方式创建一个自定义404。

Caution: Read any and all documentation that your host has regarding use of custom pages - your server requirements may differ from the above suggestions! If in doubt, contact your host directly for assistance.
警告:阅读你的主机所有的任何和所有的关于使用自定义网页的文件-对于上述的建议,你的服务器要求可能有所不同!如果有疑问,直接地联系你的主机,寻求帮助。

Using PHP Code to Block

使用 PHP 编码来阻止

You can add this to the top of any PHP page, putting the actual IP address where the xxx or yyy is.

你可以将这个添加到任何PHP网页的顶上方,在xxx或者yyy的位置输入真正的IP地址。

<?php
$block = array("xxx.xxx.xxx.xxx", "yy.yy.y.yyy");


<pre>
<?php
$block = array("xxx.xxx.xxx.xxx", "yy.yy.y.yyy");


if (in_array ($_SERVER['REMOTE_ADDR'], $block)) {
    header("Location: http://google.com/");
    exit();
}
?>


if (in_array ($_SERVER['REMOTE_ADDR'], $block)) {

   header("Location: http://google.com/");
   exit();

} ?>

Resources

资源