As recently noted over at my favorite website lifehacker.com…Google has recently added a nice feature to GMAIL that allows you to see your account activity.
If you scroll to the bottom of you Inbox, you will see something that looks like this.
This really got me thinking. This is a great feature, however its lacking in a few areas.
1) I’d like to know when suspicious activity is occuring. Although the likelyhood is low (that someone is trying to hack in…at least I think), I’d still like to have alerts that tell me there is an issue.
2) I’d also like tracking details in case there is an issue, I can try to figure out who it is,and where they are coming from. Actually, when I first looked at this, I noticed someone or somethign was hitting me from 67.228.182.163. Using my technical efficentcies…I was able to track it back to Xoopit. Another service I found over at lifehacker.com.
The process was basically taking the IP in the activity window and doing a whois lookup. The problem is that the whois, generally returns the ISP. However, luckily there was an RWHOIS available. That pointed me to Xoopit!
Well, from here I decided to write a script that will run every 30 mins, Alert me if something looks suspicious.
It does the following.
1) Logs into Gmail.
2) Pulls up Account Activity Page
3) Parses Page.
4) If IP is not in the whitelist…
a. does a Whois Loopup on the IP
b. generates
5) If the count of suspicious IP’s is > 0. Sends and email using Gmail as SMTP server to whomever cares to know.
HERE IS THE CODE: Use it as you wish. If you have issues or like it, please leave comments.
#!c:\\perl\\bin
#use strict;
use WWW::Mechanize;
use HTTP::Cookies;
use HTML::TableExtract;
use Net::Whois::IP qw(whoisip_query);
use chilkat;
our $count = 0;
my %Whitelist =
(
‘67.228.182.163′ => ‘Xoopit’,
‘ip.ip.ip.ip’ => ‘Work’
);
my $capture = GetGoogleActivity();
my $HTML = ParseActivity($capture);
print "Count = $count\n";
if ($count > 0) {
DoEmail("GMAIL: Possible Suspicious Activity", $HTML);
}
sub GetGoogleActivity {
###go to login page and login.
my $url = "https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=1k96igf4806cy<mpl=default<mplcache=2&hl=en";
my $username = "someone@gmail.com";
my $password = "password";
my $mech = […]