Cloaking script against Googlebot with RDNS [PHP]

bestscoop

Newbie
Joined
Dec 29, 2016
Messages
43
Reaction score
26
Hi !

Here is a cloaking script with reverse dns. Is just triggering Googlebot nothing else. Hope it's helpful

Code:
<?php

       $ua = $_SERVER['HTTP_USER_AGENT'];
       $ip = $_SERVER['REMOTE_ADDR'];

       if(preg_match('#googlebot#i',$ua)){
          
           $dns = gethostbyaddr($ip);
           if (preg_match('#\.googlebot\.com$#i',$dns)) {
               $host = gethostbyname($dns);
               if ($host == $ip){
                  
                   // This helps understand if googlebot here is googlebot for mobile, in some case you need to do other stuff
                   if(preg_match('#AppleWebKit#i',$ua)) {
                       include ('googlemobilebot.php');
                       exit;
                   }
                   else {
                       include ('googlebot.php');
                       return $user;
                   }
               }
               else {

                   // someone is trying to make you think is Googlebot
                   include ('fakegooglebot.php');
                   exit;
               }
           }
           else {
               // someone is trying to make you think is Googlebot
               include ('fakegooglebot.php');
               exit;
           }
       }
      
       else {
           // other users
           include ('unknownuser.php');
           exit;
       }
?>

You don't necessary need to use the included PHP files, you can just code the actions you want the server performs for each case.

Bear in mind that this script can be optimized. When you catch Googlebot the best thing is to save the IP in a text file for example, in that way the next time it comes with the same IP, you don't need to make a new RDNS.
 
Last edited:
But every time the Bots IP changes

And

How this can be useful ?


I'm new
I don't have that much knowledge
 
I'm new
I don't have that much knowledge

Don't worry for that, we're all here to learn something and help each other (when we can)

Yes, the IP change but this script works for every IP, it's not a cloaking based on user agent or ip, it's based on reverse dns
 
I m Sorry, I have made a mistake

This line will trigger an error, just leave it
Code:
return $user;
 
where to include this script bro :)
I'm New

It depends on your use case and on your cms bro. Are you using wp? Tell me an example of use case that interest you. maybe I can help.
 
  • reverse DNS using PHP is typically very very slow (multiple seconds)
  • Google doesn't just use bots from their own IP ranges - this renders reverse DNS less effective
 
Hi !

include ('googlemobilebot.php');
...
include ('googlebot.php');
...
include ('fakegooglebot.php');
...
include ('unknownuser.php');

You've only given us half the code. It is appreciated but the additional files would make your thread much more helpful - just saying. Still, thanks given.
 
@thedorf he did give all the code. Those other files are the landing pages to show various bots/users. You would make these yourself based on your campaign needs.

Again, be careful using this because reverse DNS is not reliable in general and slow enough to cause issues.

Oh, and if you look at the mobile code you'll see only a check for iOS, you'd have to extend the code to detect Android for Android-specific offers or use something like mobiledetect for a more generic solution.
 
Googlebot is notorious for using non-googlebot user-agents, unofficially of course.

Anyone using this should be aware of the very real chance that a long term penalty would get placed on your site.
 
  • reverse DNS using PHP is typically very very slow (multiple seconds)
Have you ever tried doing a Reverse DNS Before claiming it takes multiple seconds? An RDNS is typically 200 ms

  • Google doesn't just use bots from their own IP ranges - this renders reverse DNS less effective

Source please. This is a myth I think. I m not talking about the other google spiders as fetcher or ads-bot or whatever. Googlebot is is always coming from googlebot.com.
 
Oh, and if you look at the mobile code you'll see only a check for iOS, you'd have to extend the code to detect Android for Android-specific offers or use something like mobiledetect for a more generic solution.

I've done many tests with Googlebot for mobile it uses always ApplelWebKit in the user agent string. If you see something different from your logs files please provide the correct strings, this could be helpful to everyone
 
Googlebot is notorious for using non-googlebot user-agents, unofficially of course.

If it's unofficial (so Googlebot hides himself) how could you understand that is Googlebot? :D
 
Thanks for sharing OP.

Cloaking for serious campaigns is really hard. But the script shared here shows the correct overall idea.
 
If it's unofficial (so Googlebot hides himself) how could you understand that is Googlebot? :D

By inference only.

Imagine the following:

You have a website, that serves content based on the user agent parameter in the request headers. You have been serving different content to google bot than you have been serving to your audience. This is a common practice among BHW, or at least used to before it became shorter-lived. Don't get me wrong, it'd still work—just not for too long.

So Imagine you're doing this without any other shady link-building practices that could get your site penalized, and then all the sudden your site penalized. Now imagine 100s of BHW webmasters experience the same thing over the years, and talk about it on forums, and all eventually agree that it's likely Google has an 'unofficial' practice of cataloging sites that serve different content based on user agent.

That's basically how you could 'understand' that it's Googlebot. You don't know for sure, but it's by far the most likely scenario. I mean, what would you do if you were Google?
 
Surely all this code does is check if the user agent contains googlebot?

When would this code ever run?
Code:
// someone is trying to make you think is Googlebot
               include ('fakegooglebot.php');
               exit;

I dont see the point of the reverse dns part.
$host == $ip will always be true.
 
Surely all this code does is check if the user agent contains Googlebot?

When would this code ever run?
Code:
// someone is trying to make you think is Googlebot
               include ('fakegooglebot.php');
               exit;

I dont see the point of the reverse dns part.
$host == $ip will always be true.

$host == $ip it's not always true, it's false if someone is spoofing the DNS. Don't ask me how DNS spoofing works I don't know but it's well known that reverse DNS is the most secure way to know for sure who is spidering your web pages.

That said, I believe that DNS spoofing is something really rare and that in 99% of cases $ip == $host. So I don't think it's crazy if you make only a DNS lookup without the reverse.
 
Surely all this code does is check if the user agent contains googlebot?

That's crazy. I just wanted to share a stuff that could help and this is what I get. Are you sure you looked at the code dude?

It s not a clocking on user agent, the user agent check is to make the clock faster without serving a reverse DNS to all of your human traffic :)
 
Back
Top