1

I'm trying to do automated tests on a localhost site using the following settings:

Python 3.8.10
selenium 3.141.0
Firefox 90.0
Burp Suite Community Edition v2021.6.2

I'm using Burp proxy with the address 127.0.0.1:8080.

I tested several examples available here. The below code is the one that has worked best so far.

from selenium import webdriver

firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True

PROXY = "127.0.0.1:8080"

firefox_capabilities['proxy'] = {
    "proxyType": "MANUAL",
    "httpProxy": PROXY,
    "sslProxy": PROXY
}

driver = webdriver.Firefox(capabilities=firefox_capabilities)
driver.get("http://127.0.0.1")

This code works fine when the url in driver.get("URL here") is not localhost. When I enter the url http://127.0.0.1, the access made by selenium does not appear in Burp Suite's HTTP history. Instead of the accessed url, "http://detectportal.firefox.com" appears.

Is this a problem in the code or some configuration that I need to do?

Burp HTTP History

Rob
  • 14,746
  • 28
  • 47
  • 65

2 Answers2

1

Look into the Firefox proxy settings, there you can find a statement that localhost connections are never directed to a proxy.

But this can be changed by opening about:config and set the option network.proxy.allow_hijacking_localhost to true.

Robert
  • 39,162
  • 17
  • 99
  • 152
  • Thanks for the answer, Robert. I had already done this configuration in the browser. But I noticed that when I run selenium, firefox is opened with this option disabled. Do you know how to pass this setting to selenium webdriver? I wish I didn't have to manually modify this every time I run the code. – Danilo Escudero Jul 23 '21 at 15:07
  • @DaniloEscudero You should be able to specify the used Firefox profile in Selenium: https://stackoverflow.com/a/14458405/150978 – Robert Jul 23 '21 at 15:15
  • Thanks, it worked. The solution was much simpler, I'll post it here. Note: I don't want to load my entire browser profile, I just want to set the option network.proxy.allow_hijacking_localhost to True. – Danilo Escudero Jul 23 '21 at 19:14
1

For Burp to track links on localhost just add ("network.proxy.allow_hijacking_localhost", True) to FirefoxProfile().

from selenium import webdriver

fp = webdriver.FirefoxProfile()
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http", "127.0.0.1")
fp.set_preference("network.proxy.http_port", 8080)
fp.set_preference("network.proxy.allow_hijacking_localhost", True)
fp.update_preferences()

driver = webdriver.Firefox(firefox_profile=fp)
driver.get('http://127.0.0.1')