Fix for new Cloudflare detection. Thanks @cedric-bour for #845

This commit is contained in:
ngosang 2023-08-02 19:29:44 +02:00
parent 5ba9ef03f3
commit 22ed3d324b
2 changed files with 13 additions and 14 deletions

View File

@ -251,7 +251,7 @@ def _resolve_challenge(req: V1RequestBase, method: str) -> ChallengeResolutionT:
def click_verify(driver: WebDriver): def click_verify(driver: WebDriver):
try: try:
logging.debug("Try to find the Cloudflare verify checkbox") logging.debug("Try to find the Cloudflare verify checkbox...")
iframe = driver.find_element(By.XPATH, "//iframe[@title='Widget containing a Cloudflare security challenge']") iframe = driver.find_element(By.XPATH, "//iframe[@title='Widget containing a Cloudflare security challenge']")
driver.switch_to.frame(iframe) driver.switch_to.frame(iframe)
checkbox = driver.find_element( checkbox = driver.find_element(
@ -263,14 +263,14 @@ def click_verify(driver: WebDriver):
actions.move_to_element_with_offset(checkbox, 5, 7) actions.move_to_element_with_offset(checkbox, 5, 7)
actions.click(checkbox) actions.click(checkbox)
actions.perform() actions.perform()
logging.debug("Cloudflare verify checkbox found and clicked") logging.debug("Cloudflare verify checkbox found and clicked!")
except Exception: except Exception as e:
logging.debug("Cloudflare verify checkbox not found on the page") logging.debug("Cloudflare verify checkbox not found on the page. Error: " + str(e))
finally: finally:
driver.switch_to.default_content() driver.switch_to.default_content()
try: try:
logging.debug("Try to find the Cloudflare 'Verify you are human' button") logging.debug("Try to find the Cloudflare 'Verify you are human' button...")
button = driver.find_element( button = driver.find_element(
by=By.XPATH, by=By.XPATH,
value="//input[@type='button' and @value='Verify you are human']", value="//input[@type='button' and @value='Verify you are human']",
@ -280,10 +280,9 @@ def click_verify(driver: WebDriver):
actions.move_to_element_with_offset(button, 5, 7) actions.move_to_element_with_offset(button, 5, 7)
actions.click(button) actions.click(button)
actions.perform() actions.perform()
logging.debug("The Cloudflare 'Verify you are human' button found and clicked") logging.debug("The Cloudflare 'Verify you are human' button found and clicked!")
except Exception as e: except Exception as e:
logging.debug("The Cloudflare 'Verify you are human' button not found on the page") logging.debug("The Cloudflare 'Verify you are human' button not found on the page. Error: " + str(e))
# print(e)
time.sleep(2) time.sleep(2)
@ -298,6 +297,7 @@ def _evil_logic(req: V1RequestBase, driver: WebDriver, method: str) -> Challenge
if method == 'POST': if method == 'POST':
_post_request(req, driver) _post_request(req, driver)
else: else:
with driver:
driver.get(req.url) driver.get(req.url)
# set cookies if required # set cookies if required
@ -310,6 +310,7 @@ def _evil_logic(req: V1RequestBase, driver: WebDriver, method: str) -> Challenge
if method == 'POST': if method == 'POST':
_post_request(req, driver) _post_request(req, driver)
else: else:
with driver:
driver.get(req.url) driver.get(req.url)
# wait for the page # wait for the page
@ -429,4 +430,5 @@ def _post_request(req: V1RequestBase, driver: WebDriver):
<script>document.getElementById('hackForm').submit();</script> <script>document.getElementById('hackForm').submit();</script>
</body> </body>
</html>""" </html>"""
with driver:
driver.get("data:text/html;charset=utf-8," + html_content) driver.get("data:text/html;charset=utf-8," + html_content)

View File

@ -135,9 +135,6 @@ def get_webdriver(proxy: dict = None) -> WebDriver:
# https://github.com/microsoft/vscode/issues/127800#issuecomment-873342069 # https://github.com/microsoft/vscode/issues/127800#issuecomment-873342069
# https://peter.sh/experiments/chromium-command-line-switches/#use-gl # https://peter.sh/experiments/chromium-command-line-switches/#use-gl
options.add_argument('--use-gl=swiftshader') options.add_argument('--use-gl=swiftshader')
# workaround for updated 'verify you are human' check
# https://github.com/FlareSolverr/FlareSolverr/issues/811
options.add_argument('--auto-open-devtools-for-tabs')
proxy_extension_dir = None proxy_extension_dir = None
if proxy and all(key in proxy for key in ['url', 'username', 'password']): if proxy and all(key in proxy for key in ['url', 'username', 'password']):