[英]How to start OWASP ZAP proxy with Chrome webdriver and java?
我今天(13-05-2020)下載了一個新的 OWASP ZAP。 我重新生成根 CA 證書。 我將本地代理配置為 localhost:8092
運行一個簡單的 java 代碼后:
public static void main(String[] args) throws InterruptedException {
Proxy proxy = new Proxy();
proxy.setAutodetect(false);
proxy.setHttpProxy("localhost:8092");
proxy.setSslProxy("localhost:8092");
final OperatingSystem currentOperatingSystem = OperatingSystem.getCurrentOperatingSystem();
String pathWebdriver = String.format("src/test/resources/drivers/%s/googlechrome/%s/chromedriver%s", currentOperatingSystem.getOperatingSystemDir(),
SystemArchitecture.getCurrentSystemArchitecture().getSystemArchitectureName(), currentOperatingSystem.getSuffixBinary());
if (!new File(pathWebdriver).setExecutable(true)) {
logger.error("ERROR when change setExecutable on " + pathWebdriver);
}
System.setProperty("webdriver.chrome.driver", pathWebdriver);
final ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--ignore-certificate-errors");
chromeOptions.setCapability(CapabilityType.PROXY, proxy);
chromeOptions.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
chromeOptions.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
WebDriver driver = new ChromeDriver(chromeOptions);
for (int i = 0; i < 6; i++) {
//driver.get("http://www.google.com/ncr");
// www.google.com work (OWASP ZAP list all requests) but not localhost
driver.get("http://localhost:8080/ui");
}
driver.quit();
}
Selenium 腳本運行正常,但 OWASP ZAP 不攔截任何請求。
您需要確保包含 SSL 代理詳細信息(以及 HttpProxy 詳細信息),例如: proxy.setSslProxy("<proxy-host>:<proxy-port>");
,或者更具體地說是proxy.setSslProxy("localhost:8092");
為您的代碼
為了能夠在現代版本的 Chrome 中代理 localhost,您需要從代理繞過列表中刪除環回,如下所示: --proxy-bypass-list=<-loopback>
,或者在您的代碼中具體: chromeOptions.addArguments("--proxy-bypass-list=<-loopback>");
您可能還需要考慮添加: chromeOptions.addArguments("--ignore-certificate-errors");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.