kaliiiiiiiiii / Selenium-Profiles

undetected Selenium using chromedriver and emulation / device profiles
Other
255 stars 29 forks source link

`seleniumwire_options` don't work with `profile["options"]["auth_proxy"]` #48

Closed tnt2k closed 1 year ago

tnt2k commented 1 year ago

version == selenium-profiles 2.2.6 from pypi.org

The seleniumwire_options methods do not work when adding a proxy with authorization. In this case, the code does not end with any error, maybe I'm doing something wrong? If you comment out the profile["options"]["auth_proxy"] = auth_proxy line in the code below, everything works as expected.

from selenium_profiles import webdriver
from selenium_profiles.profiles import profiles
from selenium_profiles.scripts.driver_utils import TouchActionChain
from data.get_cdp import get_random_android_cdp
import random

profile = profiles.Android()
print(profile)
profile = profiles.Android()
host = "127.0.0.1"  # IP
port = random.randint(1000, 1024)
user = "user"
password = "pass"
scheme = "http"
auth_proxy = {"host": host, "port": port, "username": user, "password": password, "scheme": scheme,
              "temp_dir": "/test_Selenium_Profiles/proxy_extension",
              }
profile["options"]["auth_proxy"] = auth_proxy

cdp_p = get_random_android_cdp()
mydriver = webdriver.Chrome(profile, uc_driver=True, seleniumwire_options=True) # or pass seleniumwire-options
driver = mydriver.start()
chain = TouchActionChain(driver)

def interceptor(request):
    request.headers['New-Header'] = 'Some Value'
driver.request_interceptor = interceptor

driver.get("https://httpbin.org/headers")

input("Press ENTER to quit..")
driver.quit()
exit()
tnt2k commented 1 year ago

One gets the impression that the wire itself uses the idea of proxying for the implementation of mitm.

kaliiiiiiiiii commented 1 year ago

One gets the impression that the wire itself uses the idea of proxying for the implementation of mitm.

Exactly, and Chrome doesn't allow proxychains (proxy-over-proxy)

For now, the workaround is to pass the proxies with the seleniumwire_options as following:

wire_options = {
    'proxy': {
        'http': 'http://username:password@host:port', 
        'https': 'https://username:password@host:port',
        'no_proxy': 'localhost,127.0.0.1' # excludes
    }
}

mydriver = webdriver.Chrome(profile, uc_driver=True, seleniumwire_options=wire_options)
driver = mydriver.start()

See documentation

I plan to automatically pass proxies from profile["options"]["auth_proxy"] if seleniumwire is enabled. ==> TODO

Note here, that seleniumwire might get detected because of the different SSL-fingerprint. If you still need to intercept requests, maybe have a look at selenium-interceptor

tnt2k commented 1 year ago

Note here, that seleniumwire might get detected because of the different SSL-fingerprint. If you still need to intercept requests, maybe have a look at selenium-interceptor Exactly! I did not begin to describe the problem of pure wire, advanced proxy option in the wire we have a problem with the certificate. The wire was interested only in the possibility of modifying the response body.

One gets the impression that the wire itself uses the idea of proxying for the implementation of mitm.

Exactly, and Chrome doesn't allow proxychains (proxy-over-proxy)

For now, the workaround is to pass the proxies with the seleniumwire_options as following:

wire_options = {
    'proxy': {
        'http': 'http://username:password@host:port', 
        'https': 'https://username:password@host:port',
        'no_proxy': 'localhost,127.0.0.1' # excludes
    }
}

mydriver = webdriver.Chrome(profile, uc_driver=True, seleniumwire_options=wire_options)
driver = mydriver.start()

See documentation

I plan to automatically pass proxies from profile["options"]["auth_proxy"] if seleniumwire is enabled. ==> TODO

Note here, that seleniumwire might get detected because of the different SSL-fingerprint. If you still need to intercept requests, maybe have a look at selenium-interceptor

Exactly! I did not begin to describe the problem of pure wire, advanced proxy option in the wire we have a problem with the certificate. The wire was interested only in the possibility of modifying the response body.

kaliiiiiiiiii commented 1 year ago

Actually, let's reopen, just to not forget it:)

kaliiiiiiiiii commented 1 year ago

now fixed with https://github.com/kaliiiiiiiiii/Selenium-Profiles/commit/9e3e4340b012168fc7507c0d6c59f96c9ed5814a