Tag: spam

  • find-a-bot.sh – a nice little script to ID bots bugging your website site

    a nice little script to ID bots bugging your websiteOriginally published on May 30, 2008, made some modifications & bumped it up in the display queue.

    Already demonstrating earlier this week how to block spambots and rogue spiders. Today I’m completing the lesson with a nice little bash script sample that can help you identify some of these non-browser ‘candidates’ by parsing your access logs and placing the results in an easy-to-read text file.

    In other words, this script will selectively find most non-browser user agents that appear in your access logs like this:

    24.190.239.220 - - [29/May/2008:05:16:19 -0700] "GET /about HTTP/1.1" 200 628 "-" "Java/1.6.0_06"
    79.71.205.134 - - [29/May/2008:00:56:34 -0700] "GET / HTTP/1.1" 200 12888 "-" "Site Sniper Pro"

    And turns it into a slightly saner and sorted output like this:

    24.190.239.220 [29/May/2008:05:16:19 "Java/1.6.0_06"
    79.71.205.134 [29/May/2008:00:56:34 "Site Sniper Pro"

    Here is what your bash script might look like on a site running WordPress on shared host like DreamHost … I’ll explain some of the mechanics afterwards:

    #!/bin/bash
    #
    # step 1 - modify these so you get paths like this:
    #   /home/YOURROOT/YOURDOMAIN.coM/...
    #
    myroot="YOURROOT"
    mydomain="YOURDOMAIN.COM"
    
    #
    # step 2 - leave alone if these days & formats work for you:
    #
    TERM=linux
    export TERM
    tdy=`date +%d%b%y`
    ydy=`date -d '1 day ago' +%Y-%m-%d`
    dby=`date -d '7 day ago' +%Y-%m-%d`
    logfile="access.log.$ydy"
    
    #
    # step 3 - modify if you're using something other
    #           than  WordPress on DreamHost
    #
    outfile="/home/$myroot/$mydomain/findabot"
    logpath="/home/$myroot/logs/$mydomain/http/"
    csspath="/home/$myroot/$mydomain/wp-content"
    
    #
    # step 4 - mother of all parsing statements, parse to taste
    #	(note this version DOES sort)
    #
    # 	remember \ at the very end of line equals
    #	bash line continuation of a command set
    #
    grep "$csspath" -v $logpath$logfile | \
      egrep " \"(Mozilla|Opera)\/[0-9]| \"BlackBerry[0-9]{4}" -v | \
      perl -l -a -n -e 'print $F[0]," ",$F[3]," ",$F[11]," ",$F[12]," ",$F[13]' | \
      sort -n > $outfile/$ydy.txt
    
    #
    # step 5 - maintain a manageable archive
    #
    if [ -e $outfile/$dby.txt ]; then
    	mv -f $outfile/$dby.txt $outfile/bak.txt
    fi
    

    Okay, step 1 basically means you login to your site either SSH or even FTP and before navigating anywhere, issue the “pwd” command so you can determine your YOURROOT and YOURDOMAIN (though the latter may likely be your website’s url).

    Step 2 is how we get date stamps for our input and output files. I found a nice simple example of date variable formatting of these over on an ExpressionEngine manual – but they’ll work in your bash script just fine.

    Also, that line containing “7 day ago” can be modified to indicate how many days worth of logs you want to keep active. Similarly, the prior line containing “1 day ago” means you want to parse yesterday’s logs.

    Step 3 is basically how I use variables to define file and directory paths based on what I coded for steps 1 and 2.

    Step 4 combines all the elements from the above steps and taking a page out of my April 2nd article entitled ‘How to quickly check your error logs for oddities‘ issues a consecutive stream of grep and/or egrep commands.

    Sometimes leveraging the ‘-v’ command to exclude elements, most noteably when I’m excluding known user agent strings for browsers.

    This done, a bit of PERL command line magic is used to parse out the fields we want, where afterwards the selected data is sorted and piped into the output file defined in step 3.

    Step 5 takes into account that logs can get big, so this is where we manage an archive … based on step 2 … for 7 days worth of entries.

    find-a-bot gets into the bits and bytes of web site bottageIf you’re not familiar with creating bash scripts, you may encounter situations where you need to “chmod” or even “chown” the file to get it to work.

    The next step – though not documented above – is to test the script and when you’re sure it’s working, modify your crontab file so your batch runs every night, like say 2:15 AM while you and everyone else are sleeping. Here’s what my crontab entry looks like:

    15 2 * * * /home/YOURROOT/find-a-bot.sh > /dev/null

    I’ve provided a .txt version of the file you can simply download from here.

    Moreover, I’ve created a slightly more complex version to download of the above for use on a system running a something like vBulletin on a root or virtual private server operating with Fedora or RedHat.

    The point is, while the above appears a bit complex, I can assure you it’s worth running as it can help you quickly discern over the course of a few days:

    • how often and how hard spambots are sniffing your system
    • how much of your bandwidth is consumed by feed readers versus browsers
    • which feed readers are hammering away at your site, ignoring your <skiphours /> and/or <skipdays /> data
    • how much bandwidth you might save by exporting your sermon’s RSS feeds to a service like FeedBurner
    • what spiders are ignoring your robots.txt file
    • tips on unusual visitors from interesting places from unique user agents
    • whether or not some of the comment spam is via “Mozilla-like”agents who botch their user agent string
    • how many of your visitors are infected with spyware
    • how many of your visitors are trying to hide their tracks by visiting you with an anonymous proxy firing blank user agent strings
    • how many spamblogs are leaching your compelling content

    Like I said, it will require just a little bash script know how, so with that, I leave you with these tutorials:

    Oh and if you’re nice and leave a comment, I might even email you a link to my own archive of greatest bot hits over the past few days.

    Especially if you share your own scripting recipes for spotting bots.

  • 5 things more things about Christian spam email bombing runs

    Ever get that annoying email from a church, friend, and/or family member who ‘accidentally‘ sent a rant to everyone in their address book and/or a group-related email directory? With the recent election, my wife and I have been getting more than our fair share.

    And while I’ve written about how to address ‘Christian SPAM‘ in the recent past, I wanted to share with you my most recent response to what I sub-categorize as Christian SPAM email bombing runs (CSEBRs):

    – – – § – – –

    Hi {name withheld to protect the guilty};

    Next time we get together, make sure I spend about 5 minutes on my laptop showing you 5 cool — and free — things about the web that don’t rock like it’s 1995. For example:

    • Twitter – a “microblog” mechanism that lets you post 140 characters on any topic you want as often as you want. This is especially great as you’re standing around bored, upset, amused, and/or excited about things while equipped with nothing more than your cell phone. For an example, check mine out at http://twitter.com/deanpeters – no great shakes, but I’ve got enough subscribers whom seem interested.
    • Facebook – a social networking service where friends and families can subscribe where you can post thoughts like the ones below and then engage people in dialog and/or banter as they can post comments, etc .. It’s also a nice place to throw out some family pix. If you’d like, I can also show you how to “plug-in” a Facebook app that update to your “wall” every time you post on Twitter (synchronization is an amazing thing). Here’s a link to my profie http://is.gd/6MgW … note how I used the http://is.gd mechanism to shorten the URL.
    • Blogger.com – now I know Twitter and FaceBook have obviated bloggery to some degree, but I still love it as it allows me to venture deep into topics I enjoy such as healing church websites and the Hashemite Kingdom of Jordan. Moreover, less constraints on what I can post – and if you like, you can make some buck$ via instruments like Google’s adsense. Oh BTW, I’ve got my WordPress-driven blogs set up with the ‘twitter tools plugin‘ to update my Twitter and Facebook pages when I post. Best thing, again, people can subscribe to your blog’s RSS feed to keep up to date.
    • Google Reader – note I’ve mentioned subscribe 3 times now. All of the above allow individuals to subscribe either through the site’s syndication feed (RSS) and/or through email alerts with links to the juicy and compelling content. And not just from annoying friends like me, but any blog, news wire, newspaper, microblog and/or social network to which you’re inclined to observe.
    • BCC – finally … and I can’t stress this enough … if you must use email, that’s cool. But please, do me and others on your distribution one favor – use the BCC mechanism to distribute the email. Blind Carbon Copy is cool in that it’ll protect your friends, family and loved ones from nasty spammers and idiots like me from exposing their email addresses “into the wild.“Oh, and if you use a free email service like gMail, you can create categories for both incoming and outgoing email addresses – which is really handy when you quickly send out email broadcats to select groups of your address book (using BCC of course).

    Anyway, have a great Sunday – and give  {spouse name withheld to protect the innocent} a hug from us.

    Your (annoying) friend;

    Dean

    – – – § – – –

    Feel free to use any portion of this email to respond to Christian SPAM email bombing runs aimed in your direction. Or better yet, just send them a link here.

    I’ll be glad to respond to their rationalizations and excuses by explaining how the are endangering the tax exempt status of their church by dumping a political kvetch on the Sunday school rolls.

  • How to lovingly respond to Christian spam

    Is there anything worse than spam from fellow Christians ?Who knew joining a new church or Bible study could be so dangerous? That was my thought at my last church after I mistakenly shared my email with other members of the Sunday morning Bible study – as no sooner than I had gotten home I began to receive emails about how Madalyn Murray O’Hair is conspiring with space aliens from the grave to take images of the Cross off the airwaves.

    And no sooner had I responded, nicely and in Christian love to please stop forwarding me such ‘hoax mail‘ did I receive a scathing reply accusing this died-in-the-wool conservative of being a commie pinko, tax-n-spend liberal whose Christianity was called into question for even for a second considering any and all such messages to be urban legends … let alone spam.

    I think I still have some on file that I need to dig up just for grins … but I digress.

    The point is, most members of the HYCW audience are in the same camp as I. That is:

    1. We prefer to get our latest and greatest news updates from our feed aggregators, not email. We assume this of our friends as well;
    2. We tend to not believe everything we read but instead take Paul’s advice to the 1 Thessalonians 5:21 and “test everything” against the snopes urban legend database;
    3. We believe that there is no need to cut-and-paste any article that is on the web when it is far more considering to write a single original sentence describing why the content is so compelling that ends with the URL of online article;
    4. We get really, really grumpy when we see our email addresses exposed with several hundred in the others by an individual forwarding a message without the benefit of using or understanding the purpose and benefits of their email program’s BCC feature; and
    5. We’ve received enough of this Christian spam that we don’t even bother to read it before summarily pressing the delete button.

    so ask yourself - how do you teach, rebuke, correct & train your Christian spammy friendsBut enough about ‘we’ as this unfortunate but all-to-common occurrence raises the uncomfortable question “how does one go about teaching, rebuking, correcting &/or training such a ‘friend’ in righteous email netiquette?

    Glad you asked.

    As I recall the numerous instances where I was excoriated for:

    • asking nicely not to be included in such distributions;
    • informing the sender that the content was probably false;
    • that exposing my email address in such distributions potentially exposed me to professional spammers further down the chain; and
    • anything worth cutting and pasting is probably already posted as a page on the web;

    I realize that there’s no need for this messenger to continually expose himself to such emotional gunfire when there are already a number of web pages and services that will do the dirty work for me.

    Most recently, the good folks over at LifeHacker fielded a poll entitled “Email Etiquette Pages Explain So You Don’t Have To” – offering individuals to vote on which ‘tell a friend they’re spammin’ya crazy‘ service they use:

    • Thanks. No – for opting out of all types of unwanted email;
    • BCC Please – for requesting the sender doesn’t expose your email address to a large list;
    • Sentenc.es – for explaining your email brevity; and
    • Waiting-For.com – to let your recipient know you’re waiting to hear back from them.

    Had said survey not been closed, I might have possibly recommended some other pages that also go into detail over what’s proper and what’s not in terms of one’s SMTP activities, including:

    use this service the next time you get hit with Christian spamNote that I said “I might have possibly recommended some other pages” … this is because old ‘never met a Software as a Service he didn’t like’ author has found via the folks at AppScout a nice, free little online service offered by the generous and thoughtful folks at StopForwarding.Us.

    What this neat little online tool does is simply send an anonymous email to the church spammer of your choice that sheds the light truth on said sinner’s incorrect use of the forward feature on their email program. Here’s a sample I sent myself:

    Hi Dean is testing this service,

    One of your friends has sent you this message from StopForwarding.Us, a website that allows individuals to anonymously email their friends and politely ask that they stop the habit of sending forwarded emails or FWDs.

    Please do not forward chain letters, urban myths presented as truth, potentially offensive jokes, videos or photos without being asked or first receiving permission. If you find something that is funny and it is clean and you genuinely think the recipient will enjoy it then foward it to that person only (not in an email blast to all your friends and family) and include a personal note about why you enjoyed it and why you think they will too. Avoid sending forwards to friends or relatives that you’ve grown distant with. It can be frustrating for the recpient when the only correspondance you have with someone is via impersonal, unwanted email.

    For more tips on email etiquette, visit StopForwarding.Us/etiq.html

    Thank you,
    A Friend (via stopforwarding.us)

    And if that doesn’t work – send’m here to this post for a dose of tough love.

    Now pardon me while I get some wiki work over at blogJordan.com.

  • ip2Country.pl – A fast little script to bulk id IPs by country

    ip2Country.pl - a fast little PERL script to bulk identify IPs by countryYes, I know, all cool programmers use Python these days – but to this old-school programmer, PERL is to my antiquated PC what GWBasic was to first computer at work back in 1983. That is a nice little tool to get things done, like identify a list of IP addresses by country.

    Here’s the situation, I’ve been getting a lot of incoming spambots attempting to create accounts and post comments both here on HYCW and a few other sites I help manage. The Akismet spam filtering service catches all of it – but there’s still at times a huge draw on bandwidth, CPU and other resources when these bots hit.

    So from time to time, I harvest the IP addresses from the thwarted ne’er-do-well’s failed attempts via my user registration table and/or Apache logs and then add them to the firewalls, .htaccess file and/or application IP ban lists of these various sites – except for those IPs incoming from countries where both the languages and laws give me the ability to email the abuse administrator.

    Moreover, by excluding IPs from countries like the US, Canada, etc … from my ‘hit list,’ I don’t accidentally banish entire ISPs such as RoadRunner, ComCast or AOL when one of their user’s machines goes z0mbie goes due to some malware.

    So the trick is then to take all the IPs from all the computers with which I’m associated, and drive the list through a simple application that will generate a list of IPs to ban – while excluding IPs whom I can (and do) contact via email at a later time.

    Which is what inspired me to write ip2Country.pl – a fast little PERL script to bulk identify IPs by countries who don’t have IP abuse administrators who care, and generate a bash script to insert the entries into my apf firewall deny_hosts.rules file:

    #!/usr/bin/perl
    #
    # by Dean Peters
    # http://healyourchurchwebsite.com/
    #
    use IP::Country::Fast;
    use Geography::Countries;
    my $reg = IP::Country::Fast->new();
    
    print "#/bin/sh\n";
    print "# -- append firewall --\n";
    while() {
            chomp;
            my $ip = $_;
            my $ip_cntry_abr = $reg->inet_atocc($ip);
            my $ip_cntry_nam = country $ip_cntry_abr;
            next if ($ip_cntry_abr =~ m/US|CA|GB|AU|NZ/i);
            print "/etc/apf/apf -d $ip {mad spammer from $ip_cntry_nam}\n";
    }
    print "# -- restart firewall --\n";
    print "/etc/apf/apf -r\n";
    
    __DATA__
    121.1.29.246
    121.15.200.148
    193.238.213.70
    196.20.7.74
    210.22.83.146
    217.30.244.226
    222.124.200.212
    

    Oh sure, I could be real fancy and write a version that takes command line arguments for individual IP addresses and/or a file of IP addresses … but the point here was to demonstrate how a crufty old tool like PERL can help bulk identify IPs by countries so you can too add them to your firewalls, .htaccess file and/or application IP ban list.

    That said, if you’ve got a Python or even PHP version of the same, leave a comment and share the goods.

    Or you can just preemptively use the online services of Block a Country and be done with it.