1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cloaking script against Googlebot with RDNS [PHP]

Discussion in 'Cloaking and Content Generators' started by bestscoop, Jan 15, 2017.

  1. bestscoop

    bestscoop Newbie

    Joined:
    Dec 29, 2016
    Messages:
    43
    Likes Received:
    26
    Gender:
    Male
    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.
     
    • Thanks Thanks x 6
    Last edited: Jan 15, 2017
  2. Sunny A. Pt.

    Sunny A. Pt. BANNED BANNED

    Joined:
    Oct 8, 2016
    Messages:
    219
    Likes Received:
    18
    Gender:
    Male
    But every time the Bots IP changes

    And

    How this can be useful ?


    I'm new
    I don't have that much knowledge
     
  3. bestscoop

    bestscoop Newbie

    Joined:
    Dec 29, 2016
    Messages:
    43
    Likes Received:
    26
    Gender:
    Male
    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
     
  4. 86league

    86league Newbie

    Joined:
    Jan 12, 2014
    Messages:
    14
    Likes Received:
    0
    Gender:
    Male
    Location:
    Mn
    Thanks for the script.
     
  5. mrtruehybrid

    mrtruehybrid Regular Member

    Joined:
    Aug 4, 2013
    Messages:
    263
    Likes Received:
    65
    Nice one man :)
     
  6. m1D_n1GhT

    m1D_n1GhT Newbie

    Joined:
    Nov 13, 2012
    Messages:
    7
    Likes Received:
    0
    where to include this script bro :)
    I'm New
     
  7. bestscoop

    bestscoop Newbie

    Joined:
    Dec 29, 2016
    Messages:
    43
    Likes Received:
    26
    Gender:
    Male
    I m Sorry, I have made a mistake

    This line will trigger an error, just leave it
    Code:
    return $user;
    
     
  8. bestscoop

    bestscoop Newbie

    Joined:
    Dec 29, 2016
    Messages:
    43
    Likes Received:
    26
    Gender:
    Male
    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.
     
  9. qcp860

    qcp860 Jr. VIP Jr. VIP

    Joined:
    Dec 16, 2008
    Messages:
    256
    Likes Received:
    82
    Gender:
    Male
    Occupation:
    marketing
    Location:
    PA
    Home Page:
    • 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
     
    • Thanks Thanks x 1
  10. thedorf

    thedorf Supreme Member

    Joined:
    Oct 1, 2008
    Messages:
    1,223
    Likes Received:
    721
    Occupation:
    what? I gotta have a job?
    Location:
    BHW - Where else?
    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.
     
  11. qcp860

    qcp860 Jr. VIP Jr. VIP

    Joined:
    Dec 16, 2008
    Messages:
    256
    Likes Received:
    82
    Gender:
    Male
    Occupation:
    marketing
    Location:
    PA
    Home Page:
    @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.
     
    • Thanks Thanks x 1
  12. judaculla

    judaculla Jr. VIP Jr. VIP

    Joined:
    Oct 11, 2014
    Messages:
    324
    Likes Received:
    118
    Location:
    USA
    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.
     
    • Thanks Thanks x 3
  13. bestscoop

    bestscoop Newbie

    Joined:
    Dec 29, 2016
    Messages:
    43
    Likes Received:
    26
    Gender:
    Male
    Have you ever tried doing a Reverse DNS Before claiming it takes multiple seconds? An RDNS is typically 200 ms

    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.
     
  14. bestscoop

    bestscoop Newbie

    Joined:
    Dec 29, 2016
    Messages:
    43
    Likes Received:
    26
    Gender:
    Male
    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
     
  15. bestscoop

    bestscoop Newbie

    Joined:
    Dec 29, 2016
    Messages:
    43
    Likes Received:
    26
    Gender:
    Male
    If it's unofficial (so Googlebot hides himself) how could you understand that is Googlebot? :D
     
  16. bartosimpsonio

    bartosimpsonio Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 21, 2013
    Messages:
    12,026
    Likes Received:
    10,816
    Occupation:
    WHEREZ MA
    Location:
    BITCOINS AT?
    Home Page:
    Thanks for sharing OP.

    Cloaking for serious campaigns is really hard. But the script shared here shows the correct overall idea.
     
  17. judaculla

    judaculla Jr. VIP Jr. VIP

    Joined:
    Oct 11, 2014
    Messages:
    324
    Likes Received:
    118
    Location:
    USA
    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?
     
    • Thanks Thanks x 1
  18. tb303

    tb303 Power Member

    Joined:
    Dec 18, 2011
    Messages:
    733
    Likes Received:
    388
    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.
     
  19. bestscoop

    bestscoop Newbie

    Joined:
    Dec 29, 2016
    Messages:
    43
    Likes Received:
    26
    Gender:
    Male
    $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.
     
  20. bestscoop

    bestscoop Newbie

    Joined:
    Dec 29, 2016
    Messages:
    43
    Likes Received:
    26
    Gender:
    Male
    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 :)