randomize cdc_string and silicenced output

changed the warning log messsage to level INFO for @Avnxs
randomize cdc string   @czoins
This commit is contained in:
Leon 2020-12-19 15:49:34 +01:00 committed by GitHub
parent 78c59cc710
commit 6708019040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -22,6 +22,8 @@ import os
import re import re
import sys import sys
import zipfile import zipfile
import string
import random
from distutils.version import LooseVersion from distutils.version import LooseVersion
from urllib.request import urlopen, urlretrieve from urllib.request import urlopen, urlretrieve
@ -160,7 +162,7 @@ class ChromeDriverManager(object):
selenium.webdriver.Chrome = Chrome selenium.webdriver.Chrome = Chrome
selenium.webdriver.ChromeOptions = ChromeOptions selenium.webdriver.ChromeOptions = ChromeOptions
logger.warning("Selenium patched. Safe to import Chrome / ChromeOptions") logger.info("Selenium patched. Safe to import Chrome / ChromeOptions")
self_.__class__.selenium_patched = True self_.__class__.selenium_patched = True
def install(self, patch_selenium=True): def install(self, patch_selenium=True):
@ -219,6 +221,14 @@ class ChromeDriverManager(object):
os.chmod(self._exe_name, 0o755) os.chmod(self._exe_name, 0o755)
return self._exe_name return self._exe_name
@staticmethod
def random_cdc():
cdc = random.choices(string.ascii_lowercase, k=26)
cdc[-6: -4] = map(str.upper, cdc[-6: -4])
cdc[2] = cdc[0]
cdc[3] = '_'
return ''.join(cdc).encode()
def patch_binary(self): def patch_binary(self):
""" """
Patches the ChromeDriver binary Patches the ChromeDriver binary
@ -226,11 +236,12 @@ class ChromeDriverManager(object):
:return: False on failure, binary name on success :return: False on failure, binary name on success
""" """
linect = 0 linect = 0
replacement = self.random_cdc()
with io.open(self.executable_path, "r+b") as fh: with io.open(self.executable_path, "r+b") as fh:
for line in iter(lambda: fh.readline(), b""): for line in iter(lambda: fh.readline(), b""):
if b"cdc_" in line: if b"cdc_" in line:
fh.seek(-len(line), 1) fh.seek(-len(line), 1)
newline = re.sub(b"cdc_.{22}", b"xxz_undetectedchromeDRiver", line) newline = re.sub(b"cdc_.{22}", replacement, line)
fh.write(newline) fh.write(newline)
linect += 1 linect += 1
return linect return linect