Can a website detect when you are using selenium with chromedriver?

后端 未结 19 2663
情歌与酒
情歌与酒 2020-11-21 05:41

I\'ve been testing out Selenium with Chromedriver and I noticed that some pages can detect that you\'re using Selenium even though there\'s no automation at all. Even when I

相关标签:
19条回答
  • 2020-11-21 06:05

    Some sites are detecting this:

    function d() {
    try {
        if (window.document.$cdc_asdjflasutopfhvcZLmcfl_.cache_)
            return !0
    } catch (e) {}
    
    try {
        //if (window.document.documentElement.getAttribute(decodeURIComponent("%77%65%62%64%72%69%76%65%72")))
        if (window.document.documentElement.getAttribute("webdriver"))
            return !0
    } catch (e) {}
    
    try {
        //if (decodeURIComponent("%5F%53%65%6C%65%6E%69%75%6D%5F%49%44%45%5F%52%65%63%6F%72%64%65%72") in window)
        if ("_Selenium_IDE_Recorder" in window)
            return !0
    } catch (e) {}
    
    try {
        //if (decodeURIComponent("%5F%5F%77%65%62%64%72%69%76%65%72%5F%73%63%72%69%70%74%5F%66%6E") in document)
        if ("__webdriver_script_fn" in document)
            return !0
    } catch (e) {}
    
    0 讨论(0)
  • 2020-11-21 06:06

    For Mac Users

    Replacing cdc_ variable using Vim or Perl

    You can use vim, or as @Vic Seedoubleyew has pointed out in the answer by @Erti-Chris Eelmaa, perl, to replace the cdc_ variable in chromedriver(See post by @Erti-Chris Eelmaa to learn more about that variable). Using vim or perl prevents you from having to recompile source code or use a hex-editor. Make sure to make a copy of the original chromedriver before attempting to edit it. Also, the methods below were tested on chromedriver version 2.41.578706.


    Using Vim

    vim /path/to/chromedriver
    

    After running the line above, you'll probably see a bunch of gibberish. Do the following:

    1. Search for cdc_ by typing /cdc_ and pressing return.
    2. Enable editing by pressing a.
    3. Delete any amount of $cdc_lasutopfhvcZLmcfl and replace what was deleted with an equal amount characters. If you don't, chromedriver will fail.
    4. After you're done editing, press esc.
    5. To save the changes and quit, type :wq! and press return.
    6. If you don't want to save the changes, but you want to quit, type :q! and press return.
    7. You're done.

    Go to the altered chromedriver and double click on it. A terminal window should open up. If you don't see killed in the output, you successfully altered the driver.


    Using Perl

    The line below replaces cdc_ with dog_:

    perl -pi -e 's/cdc_/dog_/g' /path/to/chromedriver
    

    Make sure that the replacement string has the same number of characters as the search string, otherwise the chromedriver will fail.

    Perl Explanation

    s///g denotes that you want to search for a string and replace it globally with another string (replaces all occurrences).

    e.g., s/string/replacment/g

    So,

    s/// denotes searching for and replacing a string.

    cdc_ is the search string.

    dog_ is the replacement string.

    g is the global key, which replaces every occurrence of the string.

    How to check if the Perl replacement worked

    The following line will print every occurrence of the search string cdc_:

    perl -ne 'while(/cdc_/g){print "$&\n";}' /path/to/chromedriver

    If this returns nothing, then cdc_ has been replaced.

    Conversely, you can use the this:

    perl -ne 'while(/dog_/g){print "$&\n";}' /path/to/chromedriver

    to see if your replacement string, dog_, is now in the chromedriver binary. If it is, the replacement string will be printed to the console.

    Go to the altered chromedriver and double click on it. A terminal window should open up. If you don't see killed in the output, you successfully altered the driver.


    Wrapping Up

    After altering the chromedriver binary, make sure that the name of the altered chromedriver binary is chromedriver, and that the original binary is either moved from its original location or renamed.


    My Experience With This Method

    I was previously being detected on a website while trying to log in, but after replacing cdc_ with an equal sized string, I was able to log in. Like others have said though, if you've already been detected, you might get blocked for a plethora of other reasons even after using this method. So you may have to try accessing the site that was detecting you using a VPN, different network, or what have you.

    0 讨论(0)
  • 2020-11-21 06:06

    You can try to use the parameter "enable-automation"

    var options = new ChromeOptions();
    
    // hide selenium
    options.AddExcludedArguments(new List<string>() { "enable-automation" });
    
    var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), options);
    

    But, I want to warn that this ability was fixed in ChromeDriver 79.0.3945.16. So probably you should use older versions of chrome.

    Also, as another option, you can try using InternetExplorerDriver instead of Chrome. As for me, IE does not block at all without any hacks.

    And for more info try to take a look here:

    Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection

    Unable to hide "Chrome is being controlled by automated software" infobar within Chrome v76

    0 讨论(0)
  • 2020-11-21 06:07

    Try to use selenium with a specific user profile of chrome, That way you can use it as specific user and define any thing you want, When doing so it will run as a 'real' user, look at chrome process with some process explorer and you'll see the difference with the tags.

    For example:

    username = os.getenv("USERNAME")
    userProfile = "C:\\Users\\" + username + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default"
    options = webdriver.ChromeOptions()
    options.add_argument("user-data-dir={}".format(userProfile))
    # add here any tag you want.
    options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors", "safebrowsing-disable-download-protection", "safebrowsing-disable-auto-update", "disable-client-side-phishing-detection"])
    chromedriver = "C:\Python27\chromedriver\chromedriver.exe"
    os.environ["webdriver.chrome.driver"] = chromedriver
    browser = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)
    

    chrome tag list here

    0 讨论(0)
  • 2020-11-21 06:09

    Write an html page with the following code. You will see that in the DOM selenium applies a webdriver attribute in the outerHTML

    <html>
    <head>
      <script type="text/javascript">
      <!--
        function showWindow(){
          javascript:(alert(document.documentElement.outerHTML));
        }
      //-->
      </script>
    </head>
    <body>
      <form>
        <input type="button" value="Show outerHTML" onclick="showWindow()">
      </form>
    </body>
    </html>

    0 讨论(0)
  • 2020-11-21 06:10

    Obfuscating JavaScripts result

    I have checked the chromedriver source code. That injects some javascript files to the browser.
    Every javascript file on this link is injected to the web pages: https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/js/

    So I used reverse engineering and obfuscated the js files by Hex editing. Now i was sure that no more javascript variable, function names and fixed strings were used to uncover selenium activity. But still some sites and reCaptcha detect selenium!
    Maybe they check the modifications that are caused by chromedriver js execution :)


    Edit 1:

    Chrome 'navigator' parameters modification

    I discovered there are some parameters in 'navigator' that briefly uncover using of chromedriver. These are the parameters:

    • "navigator.webdriver" On non-automated mode it is 'undefined'. On automated mode it's 'true'.
    • "navigator.plugins" On headless chrome has 0 length. So I added some fake elements to fool the plugin length checking process.
    • "navigator.languages" was set to default chrome value '["en-US", "en", "es"]' .

    So what i needed was a chrome extension to run javascript on the web pages. I made an extension with the js code provided in the article and used another article to add the zipped extension to my project. I have successfully changed the values; But still nothing changed!

    I didn't find other variables like these but it doesn't mean that they don't exist. Still reCaptcha detects chromedriver, So there should be more variables to change. The next step should be reverse engineering of the detector services that i don't want to do.

    Now I'm not sure does it worth to spend more time on this automation process or search for alternative methods!

    0 讨论(0)
提交回复
热议问题