bobafifi has asked for the wisdom of the Perl Monks concerning the following question:

I've got spammers from India, Pakistan and Nepal who have taken my add form and are remotely posting their ads to my site. I'd like to modify my Perl script so that only my form (my domain, my IP address) can post. Anybody know how to do that?

Many thanks in advance,

-Bob

Edit by tye, linkify link

Replies are listed 'Best First'.
Re: Spammers and my form
by Ovid (Cardinal) on Apr 28, 2003 at 17:02 UTC

    Domains and IP addresses can be spoofed. What you need to do is create an authentication system. Passive authentication just doesn't work. The obvious caveat is that passive authentication is better than no authentication and crackers typically go after low hanging fruit. However, if they already have handy tools to spoof that information, then they'll use them.

    If you show us your code, we may be able to offer some suggestions.

    Cheers,
    Ovid

    New address of my CGI Course.
    Silence is Evil (feel free to copy and distribute widely - note copyright text)

Re: Spammers and my form
by LAI (Hermit) on Apr 28, 2003 at 18:27 UTC

    From what I've seen, one of the most reliable ways of ensuring that a human is filling out a form and not a bot is to have one of those warped, ocr-proof images which display a word that the user has to enter into a text field. If you've never seen it before, register a bogus account on Yahoo. If I remember correctly they use that.

    Of course, keep in mind that that is not completely spam-proof. I have seen code that will read words from those images. However, it is very unlikely that the people spamming your site know about that, or are willing to put the effort into implementing it.

    The other possibility, which is more effective and easier, is to have every upload mail the admin before it can be activated. When you get 20 requests in a row from spampot.np you can ignore them.
    Benefit: you have full control over your system.
    Drawback: you have to keep on authorizing uploads.

    Update: As Abigail-II pointed out, the text-in-image thing is not exactly uber-Accessible (in the 'I'm impaired and I need access' sense). So, rather than use the gimmick, I'd say go for the admin mail. It's a simple enough system to implement, and its simplicity contributes to its effectiveness.

    LAI

    __END__
      From what I've seen, one of the most reliable ways of ensuring that a human is filling out a form and not a bot is to have one of those warped, ocr-proof images which display a word that the user has to enter into a text field. If you've never seen it before, register a bogus account on Yahoo. If I remember correctly they use that.
      Yes, I have the code to do that in one of my columns, and code was posted here by jcwren to spoof it, because I didn't work very hard at making it OCR-proof. {grin}

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        I figured I had probably read it in one of your columns, but I was too bogged down with RL work at the time to do a search. Thanks for the clarification and links :o)

        LAI

        __END__
      You would also very effectively lock out blind users. Depending on your jurisdiction and the service you provide, you may actually violate a law doing so.

      Abigail

Re: Spammers and my form
by benn (Vicar) on Apr 29, 2003 at 00:37 UTC
    As a flautist myself, I've browsed your site often (dreaming, mainly), and a possible solution to your 'spam' problem may be found in simply improving the whole shebang - categorisation of the DB immediately springs to mind (piccolos, wooden flutes, feet, flutes wanted etc.) , rather than a single page of 500 adverts (and a page like that full of 'real' mail addresses is a spambot's delight - an 'I'm interested' button could solve that).

    If the 'place an advert' process were a little more 'specialist' - dropdown categories, price ranges etc., especially when combined with some of the ideas above, then your spammers may well not bother. I'd be glad to help with this as a side project if you liked - it's something I've meaning to contact you about for a while anyway, by happy coincidence :) Msg me for contact details.

    Cheers,
    Ben.

      Hi Ben, Thanks for your offer to help out. I'm always open to hearing from people who use the site so please feel free to drop me a note.
      Thanks again,

      -Bob
Re: Spammers and my form
by Improv (Pilgrim) on Apr 28, 2003 at 17:43 UTC
    One very simple way to do it would be to, every hour, have a passphrase generate that is needed to write to your database. Your form could query the database for that passphrase, and drop it into an <INPUT TYPE=hidden> form field and the script recieving the actual post could then check the passphrase. It's simple, but it might be enough to dissuade the spammers.
Re: Spammers and my form
by pzbagel (Chaplain) on Apr 28, 2003 at 17:59 UTC

    If you have control of your httpd server's configs, you can modify them to only allow your subnet, IP, domain, etc. from even accessing the cgi script to begin with. In this way, you let the httpd server do the ip-based authentication rather than reinventing the wheel in your script.

    Good luck

      As Ovid correctly points out above, IP addresses and domains can be spoofed, so this won't add much security at all. The only reliable way for this to work would be on an intranet behind a firewall -- which would render the OP's question moot.

        Limiting access by IP address will add enough security for his purposes. Sure, a determined hacker could spoof IP addresses and access the script. But a spammer's bot isn't that sophisticated. Blocking by IP address will stop them and is easy to implement. It should be implemented with web server access control instead of in the script.

        Similarly, basic authentication would be helpful and easy to get working. Won't stop sniffing or brute-force search, but it will provide a little more security for leaving it open to the world.

        He is using a Matt Wright script is probably a good idea too. Lack of access controls means anyone can post messages. Bad code can mean that anyone can do violenc to his machine.

      I'm not familiar with "httpd server's configs," but am already using .htaccess to block IP addresses. Can I use .htaccess "to only allow your subnet, IP, domain, etc. from even accessing the cgi script to begin with"? If so, how? Many thanks, -Bob
Re: Spammers and my form
by perrin (Chancellor) on Apr 28, 2003 at 18:12 UTC
    May I suggest switching to the FormMail script from NMS?
Re: Spammers and my form
by bobafifi (Beadle) on Apr 29, 2003 at 02:00 UTC
    Thanks everybody for all your thoughts on this. :-) I'll look into what I can here and see if I can apply it. Thanks again, -Bob