Link & Comment Spamming – A possible solution.

Outsmart Malicious Hackers

Recently one of the sites I am developing for my self was link spammed. Some unpleasant individual decided that it would be fun to post 160 ‘comments’ spread over all the blog posts. All the comments contained was URL’s. Even more stupid they used BB tags, but as I wrote the site it doesn’t use them.

Any way, obviously this isn’t some thing I want, so I deleted them all with a quick bit of SQL. No one else has posted a comment to the site because like I said, its still under development.

However, it happened once so there is no reason to think it wont happen again. I thought about the problem for a while, and the only solution is to incorporate some kind of humanity check. Because lets face it, its not like some one sat there and entered them all in. Its was some kind of bot.

Now, I don’t really like the ones that ask you to type the letters from some hard to read image. I can do that, no problem but they look ugly, and if the user was colour blind, or any other sight related issue, then you buggered.

So, I have come up with a different solution. The idea is to ask a random question, some thing that’s so easy any every one will know the answer, but unless you can read, you wont know what the answer is.

While I was busy implementing this solution, and believe me it didn’t take very long, another 20 comments of a very similar nature where posted. How annoying is that?

The solution seems to work for now. There have been no more comments since I completed the changes, but then maybe its only time until the bot gets adjusted, time will tell. But I thought other might benefit from having it so here goes, how to add random questions to your site.

Oh, one thing, I am not going to list my questions here, for a start it took me a shockingly long time to think of 30 really really easy questions, and I also don’t want to give a list of the question text and answers away.

So – on with the show. First off you will need 2 tables, one for the questions and one to keep track of what questions you have asked each user.

The questions table is easy, 3 coloums. Question_id, question and answer. The question id is just a unique number, the question and answer are both varchar.

Then we have the table used to store the asked questions. This is even less complicated. All you need is 2 fields, one for the question that was asked ID, and one to store the users Session ID.

So far, that’s all easy enough. You fill in the question table with as many questions as you can think of, along the lines of “is the sky blue” with an answer of “yes” or perhaps “What is 25 + 30” answer, obviously “55”.

Of course you can create the tables and this isn’t going to do a hell of a lot. So, you’ll need a class to deal with it all. This is a copy of the code, though you will notice the use of the functions “performQuery” and “fetchRow”, these are from my own DB layer. They replace the standard MySQL commands by using a wrapper. It makes it easy to port code from one RDBMS to the other. I personally like this solution because its light weight and simple. But it’s a bit beyond the scope of this post.

So, the class? Its got 2 methods: getQuestion and getAnswer. They both take the a single parameter of ‘sid’. This is the session id, but for compatibility it is passed in to the function so it can basically be any thing.

How do you use it? Well, when your page displays the form you make a call to getQuestion and display it. For a while I thought about putting the question ID into the page, but only for a couple of seconds as I realised any half decent attempt to beat the system would just replace the ID with one with a known answer, infact as I suspect that the form is not used, simple data “posted” to the page, then it wouldn’t even matter.

That’s why we keep that information in the database.

Any way, once the form is submitted you then ask the class to get the answer for the current session, and compare what the user entered to the correct answer. I’d suggest forcing lower case, or upper case if you want, but basically make the comparison case insensitive.

If the answers don’t match then the person is, well an idiot or a bot. If no answer is available, then some ones messed with the session, or never even used the form. Doesn’t matter which, either way its an error.

I don’t think I will bother to explain the code it self, its really not that complicated. I think maybe the only bit that might seem a bit strange is the sql used to select a question:

This simply selects a random record from the table, because its ordered by “rand”. This basically means that for each record in the table a random number is generated, and then the records are ordered by the value. Because we only want one question we use the limit to only select the first record, how ever because each time the records are selected they will be in a different order, each time you get a different record cool ha? :-)

I hope this proves to work over time. I’ll have to keep any eye on it. Just to see how it goes. If any one can see any thing wrong with it, well, let me know.

Digg This Article

Posted in: Hacking News, Spammers & Scammers, Web Hacking

Latest Posts:

snallygaster - Scan For Secret Files On HTTP Servers snallygaster – Scan For Secret Files On HTTP Servers
snallygaster is a Python-based tool that can help you to scan for secret files on HTTP servers, files that are accessible that shouldn't be public and can pose a s
Portspoof - Spoof All Ports Open & Emulate Valid Services Portspoof – Spoof All Ports Open & Emulate Valid Services
The primary goal of the Portspoof program is to enhance your system security through a set of new camouflage techniques which spoof all ports open and also emulate valid services on every port.
Cambridge Analytica Facebook Data Scandal Cambridge Analytica Facebook Data Scandal
One of the biggest stories of the year so far has been the scandal surrounding Cambridge Analytica that came out after a Channel 4 expose that demonstrated the depths they are willing to go to profile voters, manipulate elections and much more.
GetAltName - Discover Sub-Domains From SSL Certificates GetAltName – Discover Sub-Domains From SSL Certificates
GetAltName it's a little script to discover sub-domains that can extract Subject Alt Names for SSL Certificates directly from HTTPS websites which can provide you with DNS names or virtual servers.
Memcrashed - Memcached DDoS Exploit Tool Memcrashed – Memcached DDoS Exploit Tool
Memcrashed is a Memcached DDoS exploit tool written in Python that allows you to send forged UDP packets to a list of Memcached servers obtained from Shodan.
QualysGuard - Vulnerability Management Tool QualysGuard – Vulnerability Management Tool
QualysGuard is a web-based vulnerability management tool provided by Qualys, Inc, which was the first company to deliver vulnerability management services as a SaaS-based web-service.

6 Responses to Link & Comment Spamming – A possible solution.

  1. blah August 29, 2006 at 1:56 pm #


  2. Pedro Pinheiro August 29, 2006 at 6:23 pm #

    Two comments:
    1) If the questions are mainly of the yes/no type, a brute force attack will overcome the difficulty. And the “what is 20+5” and similar questions are subject to be answered by systems like google (try to type “what is 10 times 5” on google), which the boots could use;
    2) What happens exactly when you get it wrong? Does it give you immediately another chance to answer another question correctly? If so, it would also make it more vulnerable to brute force attacks.

    I personally like the system implemented on WordPress. You can set several parameters regarding the number of links in the comment, or if to allow only comments from users that have already had comments aproved before (identified through the e-mail given, no e-mail confirmation is sent).

  3. Nounours August 29, 2006 at 7:09 pm #

    You are not the only one to have this problem. I did not experiment by myself but it seems to work.
    The idea is to make people recognize pictures like kitten or others animals.

    Hope it can help you

    Good luck :p

  4. Missi August 30, 2006 at 3:40 am #

    Hi, i have an additional field in my weblog against commentspam and a rule in my htaccess against trackbackspam. This rule blocks the direct acess on wp-trackback.php.
    (RewriteRule ^wp-trackback\.php.*$ – [F,L]) It works perfect.

    (Sorry for my english, my german is much better. :o) )

  5. kevin February 22, 2007 at 3:59 am #

    Hi Missi, I use the same php code you use it works very well for me as well.

  6. missi February 22, 2007 at 1:02 pm #

    Kevin, additional rename the whole trackbackmachine. I post it here in german, here is a google-translate.

    This ist a simple fix and i´m 100% spamfree. :)

    (Btw. Haydies, i need to turn on Cookies for this challenge, this is bad. :\ )