Skip to content

Instantly share code, notes, and snippets.

@sujit
Last active April 28, 2024 13:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sujit/578d577c3f5a74a9f183c92a2c18c5b5 to your computer and use it in GitHub Desktop.
Save sujit/578d577c3f5a74a9f183c92a2c18c5b5 to your computer and use it in GitHub Desktop.
Selenium Bypass SSL Bad/Revoked Certificates
import sys
from time import sleep
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import WebDriverException
from eliot import start_action, to_file, log_call
# from selenium.webdriver.common.keys import Keys
# from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support import expected_conditions as EC
# from selenium.webdriver.support.ui import WebDriverWait
to_file(open("debug.log", "w")) # Eliot logs
options = webdriver.ChromeOptions()
# options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--mute-audio')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.add_argument('--disable-infobars')
options.add_argument('--ignore-certificate-errors-spki-list')
options.add_argument('--no-sandbox')
options.add_argument('--no-zygote')
options.add_argument('--log-level=3')
options.add_argument('--allow-running-insecure-content')
options.add_argument('--disable-web-security')
options.add_argument('--disable-features=VizDisplayCompositor')
options.add_argument('--disable-breakpad')
# Set desired capabilities to ignore SSL stuffs
desired_capabilities = options.to_capabilities()
desired_capabilities['acceptInsecureCerts'] = True
# desired_capabilities['acceptSslCerts'] = True
driver = webdriver.Chrome(
options=options,
service_args=["--verbose", "--log-path=chromerun.log"],
desired_capabilities=desired_capabilities)
driver.implicitly_wait(10)
driver.set_page_load_timeout(5)
@log_call
def ignore_insecure_certs():
ips = ['http://10.255.255.1', 'http://wikisecure.net/',
'https://self-signed.badssl.com/', 'https://revoked.badssl.com/']
for eachHost in ips:
try:
with start_action(action_type="urlOpen",
domain=eachHost,
drv_desired_caps=driver.desired_capabilities):
try:
print('\nURL:\t{}'.format(eachHost))
driver.get(eachHost)
sleep(3)
if driver.title:
print("Title:\t{}".format(driver.title))
except TimeoutException as pyexp:
print(pyexp)
pass
except WebDriverException as webdrvexcp:
print(webdrvexcp)
pass
except Exception as excp:
print(excp)
pass
ignore_insecure_certs()
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment