[英]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.