Implementing a Sand Trap
I've been reading my site error log nearly daily recently and have noticed a lot of calls to scripts which no longer exist. Since I was getting hit with a huge amount of comment and trackback spam, I often renamed those scripts but the spammers are still trying to access them.
Annoying Old Guy has written code to thwart the spammers that I've tried using a couple of variations.
My first attempt was to create a couple of files called mt-comments.cgi and mt-tb.cgi (since the real scripts now have an fcgi extension it's okay), and copy the following code into them. Give 755 permissions, and next time they're requested, the spammer get sucked into the sand trap.
#!/usr/bin/perl -w
use strict;
local $|=1; # Disable buffering
print <<HTML;
Content-Type: text/html
<body>
<div style="font-size:200%;
text-align:center;
background:red;
color:white;
margin-bottom:1ex;
">
Invalid Access
</div>
<p style="border:2px solid red;padding:1ex;">
There is no reference to this script from anywhere else on the Internet.
You can only have accessed this script by guessing its name.
There is no legitimate reason for doing that.
Cease your annoying abuse.
</p>
HTML
sleep 30;
print "</body>\n";
This works perfectly, and there's nothing else to do except sit back and let the script do it's thing. I found myself creating a third cgi for a send to friend script I deleted a few weeks ago and realised I could have half a dozen of these scripts when I saw the error log and realised the spammers were trying all the names I called my scripts.
Another approach, which I now have implemented, is to create a PHP file, and write a redirect into the .htaccess file in the root directory.
<body>
<div style="font-size:200%;
text-align:center;
background:#822;
color:white;
border:2px solid red;
padding:1ex;
margin-bottom:1ex;
">
Sand Trap
</div>
<p style="border:2px solid red;
padding:1ex;
">
You have been redirected to this script because
you have used an obsolete resource to which
no references exist on this website. This makes
you presumably a junker, and therefore your
session has been bogged down with this webpage.
</p>
<?php
ob_flush();
flush();
sleep(30);
?>
<p style="text-align:center;
border:2px solid red;
padding:1ex;
margin-top:1ex;
">
If you are going to abuse me, I will abuse you right back.
</p>
</body>
Name the file sand-trap.php and place in the root directory of your site. Edit the .htaccess (or create one) and enter the following lines, changing the names of the files:
RewriteEngine On RewriteRule ^cgi-bin/mt/mt-comments.cgi /sand-trap.php [last] RewriteRule ^cgi-bin/mt/mt-tb.cgi /sand-trap.php [last] RewriteRule ^cgi-bin/mt/death-to-spammers.fcgi /sand-trap.php [last] RewriteRule ^cgi-bin/mt/mt-friend-holler.cgi /sand-trap.php [last]
I have several more lines in the .htaccess file but this gives you an example. The script works fine. You can test it here.
You'll find these instructions and more on the Solid Wall of Code website.



Leave a comment