As a blogger, everyday I’m receiving hundreds of spam comments. I was very curious about how spammers can sends so many automated comments to thousands of blogs. Here's an exemple which demonstrate how to spam blogs using PHP and Curl.

This article is for educationnal purposes only. It was written to help bloggers knowing one of the technics used by spammers to spam their blog, not to encourage spam of any sort.
Blog spamming is useless, anyways: Most blogs have the Akismet antispam and manually moderate comments.

Part 1: getting info

The first thing the spammer will have to know, is how your comments form works. Most Wordpress comment forms works exactly the same manner, and this is probably why spammers can spam so many blogs easily.
Here’s a “basic” Wordpress comment form:

<form action="wp-comments-post.php" method="post" id="commentform">
 <p>
    <input type="text" name="author" id="author" value="" size="30" tabindex="1" />
    <label>Name <span class="required">
    (required)    </span> </label>
  </p>
  <p>
    <input type="text" name="email" id="email" value="" size="30" tabindex="2" />
    <label>Email <span class="required">
    (required)    </span></label>
  </p>
  <p>
    <input type="text" name="url" id="url" value="" size="30" tabindex="3" />
    <label>Website</label>
  </p>

<p>
    <textarea name="comment" id="comment" cols="100%" rows="10"></textarea>
</p>
<p>
    <input type="image" src=submit.png"/>
    <input type="hidden" name="comment_post_ID" value="524" />
    <input type="hidden" id="_wp_unfiltered_html_comment" name="_wp_unfiltered_html_comment" value="0d870b294b" />
</p>
</form>

To submit a comment throught that form, we must fill the following fields:

  • Name (author)
  • Email (email)
  • Website (url)
  • Comment (comment)

There’s also 2 hidden fields:

  • comment_post_ID
  • _wp_unfiltered_html_comment

Part 2: Creating the script

Now that we have the required info, we can start to code our spam-script, using PHP and Curl. We are going to define an array ($postfields) containing the info that we’d like to pass to the page.

<?php
$postfields = array();
$postfields["action"] = "submit";
$postfields["author"] = "Spammer";
$postfields["email"] = "spammer@spam.com";
$postfields["url"] = "http://www.iamaspammer.com/";
$postfields["comment"] = "I am a stupid spammer.";
$postfields["comment_post_ID"] = "123";
$postfields["_wp_unfiltered_html_comment"] = "0d870b294b";
//Url of the form submission
$url = "http://www.ablogthatdoesntexist.com/blog/suggerer_site.php?action=meta_pass&id_cat=0";
$useragent = "Mozilla/5.0";
$referer = $url; 

//Initialize CURL session
$ch = curl_init($url);
//CURL options
curl_setopt($ch, CURLOPT_POST, 1);
//We post $postfields data
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
//We define an useragent (Mozilla/5.0)
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
//We define a refferer ($url)
curl_setopt($ch, CURLOPT_REFERER, $referer);
//We get the result page in a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//We exits CURL
$result = curl_exec($ch);
curl_close($ch);

//Finally, we display the result
echo $result;
?>

All right. Now the spammer just have to call the script, and it will automatically post the message.
Of course, a real spammer will not manually type the blog post url in his script, but loop throught a csv file, or even google results, but I’m not going to say much about that since this code is only an exemple, and definitely not a functionnal spam bot.

This tutorial was inspired from this excellent article from French website www.seoblackout.com.

Related Posts

No related posts.
 

36 Comments

  1. Posted September 9, 2008 at 9:10 am | Permalink

    That is really interesting. I get hundreds of pieces of spam every day and it is driving me crazy. Is there anyway in which you can easily stop spam from ever reaching your filter?

  2. Posted September 9, 2008 at 9:18 am | Permalink

    Captcha stops spam efficiently, but I hate solving captchas so I’m not going to do that on my own blogs. Personally, I use Akismet (Which works great) and manual moderation.
    I heard about a hack to stop 90 percent of spam without a captcha, I should talk about it in a future article!

  3. Posted September 9, 2008 at 11:20 am | Permalink

    Great post! I never new how it was done (not that i want to do it myself but it’s interesting non the less.. )

    Akismet is great, but one that I’m using on my Wordpress MU installation is Monty Spam which is proving to be fantastic. It’s only for MU at the moment but i believe it’s going to be coming to the single install of WP

  4. Posted September 9, 2008 at 11:28 am | Permalink

    Thank you Jamie. Indeed, spamming is not a good thing and no-one can have real benefits from it.
    Nice info about Monty Spam, i’ll forward to it!

  5. ton
    Posted September 9, 2008 at 4:55 pm | Permalink

    “There’s also 3 hidden fields:” Umm…didn’t you mean ‘There’s also 2 hidden fields’. From looking at the html that’s what I found. Also, it seems that only the ‘Name’ and the ‘Email’ fields are required from looking at the html.

  6. Posted September 9, 2008 at 5:07 pm | Permalink

    @Ton: You’re right about hidden fields, there’s only two. Thanks for correcting my mistake.
    Yes, only name and email are required, but in case of spamming, you have to provide an url.

  7. Posted September 9, 2008 at 5:40 pm | Permalink

    Based on this post, here are some ideas. These are specific to Wordpress but could be adapted to work with other blogging engines.

    1 – Rename wp-comments-post.php to something that is specific to the site. This would force potential spammers to do more work to figure out the name of the program to invoke.

    2 – Similar to #1, rename some of the input fields in the form.

    3 – Emit a random “magic cookie” value inside of a hidden form field. Then refuse to post the comment unless this value is present.

  8. Posted September 9, 2008 at 5:49 pm | Permalink

    @Jeff Barr:
    Good ideas here. Another antispam that I created for another blog was to create a new hidden field, and then, verify if this fields is empty.
    As robots tends to fill all fields they can find, if the field is filled, you can say it’s spam.
    That worked quite well on a small blog, but some spams managed to bypass it.

  9. Posted September 9, 2008 at 10:33 pm | Permalink

    On my blog the name of the form fields are randomised, stored in a session variable, and regenerated within a specific timeframe, so grabbing the form and using the form variables only works if you are accessing it within the same session and within a set period of time.

  10. Posted September 9, 2008 at 10:40 pm | Permalink

    @Andrew: Really nice idea. You should develop a WP plugin, I’m pretty sure many people will enjoy it!

  11. Posted September 9, 2008 at 11:35 pm | Permalink
  12. Posted September 10, 2008 at 1:10 am | Permalink

    Andrew : great idea! i’m going to give your plugin a shot :)

  13. Posted September 10, 2008 at 6:12 am | Permalink

    I’m relatively new to blogging (WP) and already the target of too much spam, some of which I’ve been able to combat with IP blocking (but I know that’s a losing battle).

    I like the sound of adding an additional hidden field and verifying it’s empty. Would anyone care to share how it’s implemented?

  14. Posted September 10, 2008 at 7:22 am | Permalink

    @Web designer: The idea of adding a hidden field sounds great, but to apply it you have to modify WordPress core, which isn’t recommended. Why not trying Andrew’s plugin first? It sounds very promising!

  15. Posted September 11, 2008 at 9:51 am | Permalink

    Good point jbj – checking out Andrew’s plug now. Thanks.

  16. Posted September 11, 2008 at 11:31 am | Permalink

    It would be nice if you could turn things around on spammers. I get so annoyed but Akismet catches and stops about 98% of the spam I get, maybe more. I do have one site that I get two spam comments that get through every day. Which is better than having the hundreds that get stopped from coming trhough.

  17. Posted September 12, 2008 at 11:32 pm | Permalink

    I “had” a blog that at some point received so much spam, no matther the filter I was using that I went crazy and deleted it. What was even worse is that I would receive the exact same comment from the exct same person hundreds of times per day!!! You know those moments when you do idiot things.
    Anyway, it si good to know how they do it

    I dont have a blog right now, dont have time with all the work I have at this website but eventually I will start a new one.

    http://www.chico-chihuahua.com

  18. Posted September 18, 2008 at 10:14 pm | Permalink

    i wish a curse for spammers they really polute blogosphere and kill the reputation of some real commenters and its really good to know how they start spamming and nuke a website.

  19. Posted September 19, 2008 at 3:15 am | Permalink

    Aha! so that’s how they do it, those little rats.

  20. Posted September 20, 2008 at 10:47 am | Permalink

    i really hate automatic comment spam, that was very great idea.

  21. Posted September 20, 2008 at 1:52 pm | Permalink

    I used to always wonder how they should waste time and effort on spam…now I know better. They have automated the whole thing…No wonder they are so persistent and irritating.

  22. Posted October 3, 2008 at 4:05 am | Permalink

    I get so many of these always about jewellery, and I’ve always wondered how they can do this, and how many other sites they do it to.

  23. Posted October 3, 2008 at 8:37 pm | Permalink

    interesting. i keep on hearing about automated spam posts, but i never really had an idea of how they go about it.

  24. Posted November 2, 2008 at 1:12 am | Permalink

    Yeah, we get spammed every day, all day. A pox on their house I say!

  25. Posted November 9, 2008 at 8:01 pm | Permalink

    Man there are just so many ways and forms to spam. I’m starting to get text spams on my cell too.

    I use primarily TypePad for blogging — they handle most of the spam for me, but I still need to manually delete the odd comment

  26. Posted November 13, 2008 at 7:38 am | Permalink

    @ Andrew (#11)

    Thanks for mentioning that plugin. It’s pretty much EXACTLY what I’ve been looking for :)
    And, of course, thanks to jbj for the original post :P

  27. Posted December 16, 2008 at 8:16 pm | Permalink

    Thanks, now Im gonna go out and spam the world! Nah I really don’t like spammers so much. I was wondering how in the world they did manage to do that, so thanks for the insight. And thank god for Akismet!

  28. Posted December 30, 2008 at 11:25 am | Permalink

    There are also automated programs that blog spam such as Blog Slammer

  29. Posted January 4, 2009 at 7:47 pm | Permalink

    BlogSlammer does not spam blogs… I am the owner of this and want to reiterate it does not spam other people’s blogs.

    It just allows you to post content accross multiple blogs and automates this process. The blogs it posts to are blogs the user owns.

  30. Posted January 14, 2009 at 8:02 pm | Permalink

    ;]

  31. Posted January 23, 2009 at 2:41 am | Permalink

    ahahahahahahahaha

  32. Posted February 9, 2009 at 11:32 am | Permalink

    The good thing here is that Akismet is doing a good job against those spamers. If you just try that piece of code for sure Akismet will be very glad to catch you, so there is no need to change to Typepad or any other blogging system, Wordpress is fine.

  33. Posted February 20, 2009 at 2:56 pm | Permalink

    ReCaptcha works fine for me. Automatic spamming wordpress forms is quite easy but if you change your code just a bit robots will fail. Giving just a small change ruins bots efforts.
    Just install Akismet & captcha & change your code a bit and you’ll have 100% of automatic spam rejected.

  34. Posted July 5, 2009 at 9:03 am | Permalink

    The spam amounts can get crazy. Captcha helps a lot!.
    Be careful not to delete a whole list of comments in frustration as there may be a some legitimate ones too, if not this will block these users posting on ALL blogs with Akismet.
    This filter is creating issues for many good bloggers too.

  35. Posted August 12, 2009 at 10:12 pm | Permalink

    We have a problem on our site – someone puts a word called array on the comments page of our blogs which in turn hides all the comments that readers leave – is there a way we can prevent this from happening. Most of the bloggers face this problem in their comments field which makes it very annoying. Will appreciate any advice.

    Thank you

  36. Posted January 29, 2010 at 11:36 pm | Permalink

    in spite of time then this post was wrote, its a good information! But spammers have found how to come through the Akismet.
    Only hope is manual moderation! )

4 Trackbacks

  1. By Findings 9.18.08 | 8164 on September 19, 2008 at 6:00 am

    [...] How Spammers Spams Your Blog Comments – A great article on how spamming is done. [...]

  2. [...] por supuesto, el script anterior es solo un ejemplo, a efectos ilustrativos, no un script de spam realmente [...]

  3. By 10 awesome things to do with cURL on June 29, 2009 at 5:26 pm

    [...] a previous article, I have discussed how spammers spams your WordPress blog. To do so, they simply have to fill the $postfields array with the info they want to display and [...]

  4. [...] a previous article, I have discussed how spammers spams your WordPress blog. To do so, they simply have to fill the $postfields array with the info they want to display and [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting

  • Smashing Network
WordPress Appliance - Powered by TurnKey Linux