random title

Entries in Category "Programming"

Anti-spam: Dual honey traps

Posted by Dave on December 22, 2004 at 03:17 PM | Comments (2)

While posting the first article in the redesign series I realised I was in the middle of a spam attack. I got quite a few spam comments on my own blog, and more than a few on both Claires and Captain Ds blogs.

I spent quite a while last night deleting them from my main blog, and most of this morning deleting them from my supporting blogs (like my link blog) and from all the other blogs I host for my friends from this install. Inconveniences like these will make you understand that spammers are, to put it mildly, scum.

While I was deleting them from my blog, I grabbed the IP address of each spammer, so that I could block them with a .htaccess file. I found that there was a low ratio of comments to IP addresses. These things were coming from everywhere.

I implemented the Comment Spam Quick Fix from over at Burningbird, but I thought it could be improved.

I've renamed mt-comments.cgi to zombocom.cgi, and updated my templates accordingly. Anything that hits mt-comments.cgi automatically gets their IP added to the blacklist. This is the first honey trap.

The second honey trap is in the new comments script. Anything that fails the Comment Spam Quick Fix test also gets added to the black list.

I don't have a clue if this will work with version 3 of MovableType, but I suspect it won't. All I'm certain of is that it works with my copy of MovableType 2.661, which is otherwise unhacked. It may be possible to adapt it to MT3. Use this at your own risk.

First steps

  • Download a copy of your mt.cfg file.
  • Download a copy of your mt-comments.cgi script.
  • Rename mt-comments.cgi to a different file name (I use zombocom.cgi in this example).

The new .htaccess file

Put this in a file called “.htaccess”:

  1. Order Allow,Deny
  2. Allow from all
  3. # Automatically added

Download this code (1.txt), or download my most recent htaccess file.

Renaming the comment script

You've already renamed the file, now you need to let MovableType know about it. Open up mt.cfg, and replace the line that reads:

# CommentScript mt-comments.pl

With:

CommentScript zombocom.cgi

Save your changes.

Rigging the first honey trap

Take this code and save it as mt-comments.cgi

  1. #!/usr/bin/perl -w
  2. use strict;
  3. # Tasty honey
  4. open(DENY, ">>.htaccess") or die "Tried to add host (" . $ENV{REMOTE_ADDR} . ") to deny list, but failed to open file\nError: " . $!;
  5. flock(DENY, 2); # <-- Lock the file
  6. print DENY "Deny from " . $ENV{REMOTE_ADDR} . "\n"; close(DENY) or die "Tried to close deny list but failed (Host: " . $ENV{REMOTE_ADDR} . ")\nError: " . $!;

Download this code (2.txt).

Rigging the second honey trap

Update your templates as per the Comment Spam Quick Fix, but instead of their edit of mt-comments.cgi use the following code in the same place in zombocom.cgi:

  1. use CGI qw(:standard);
  2. if ($ENV{'REQUEST_METHOD'} eq "POST") {
  3. my $data = param('snoop');
  4. unless ($data) {
  5. # Tasty honey
  6. open(DENY, ">>.htaccess") or die "Tried to add host (" . $ENV{REMOTE_ADDR} . ") to deny list, but failed to open file\nError: " . $!;
  7. flock(DENY, 2); # <-- Lock the file
  8. print DENY "Deny from " . $ENV{REMOTE_ADDR} . "\n";
  9. close(DENY) or die "Tried to close deny list but failed (Host: " . $ENV{REMOTE_ADDR} . ")\nError: " . $!;
  10. die;
  11. }
  12. }

Download this code (3.txt).

Installing the spam fix

  • Upload mt.cfg, zombocom.cgi and the .htaccess file. Make sure zombocom.cgi and .htaccess have the correct permissions.
  • Rebuild your site.
  • Upload the rigged mt-comments.cgi script.

Hopefully this is of some use to you. It seems to be working for me... I've already caught a few bots while writing this article. If anyone has any suggestions or bugfixes, please leave a comment.

Class choices

Posted by Dave on August 17, 2004 at 06:01 PM | Comments (0)

I'm looking at ways to implement a new backend system for the site. I originally planned to write it in Perl, but Ruby on Rails has definitely piqued my interest.

I'm trying to implement a system based on the Model-View-Controller design pattern. I'm trying to represent various things in the system as objects. I want Post objects to inherit from a base class of Record. Record would hold such details as the author and timestamp, attributes common to almost all records in the system. This would hopefully save me from a lot of duplicate code; access control is the same problem whether we're talking about Posts or Images.

Unfortunately, Class::DBI doesn't allow me to handle is a relationships very well. At the best case, I can probably mangle together something with a has a relationship. This isn't nice.

Rails may be able to help. I think I've seen inheritance used the way I need. I'm going to take a further look at Rails and hope to have some good news soon.

Update: I managed to get Rails installed and running on Minds, but something seems to be bust in mod_rewrite for Apache. Even the simplest rewrites don't work, but the module is being loaded and if I screw up a rewrite rule I get a Bad Request error. I spent about three hours trying to figure this one out. I think I'll just screw around with the network here and get a web connection up to my computer so I can use it in Fedora.

Copyright © 2003-2006 David Barrett. Valid XHTML & CSS.