org.zaproxy.clientapi.core.ClientApiException: java.net.ConnectException: 拒绝连接:使用Java API连接到ZAP时出现连接错误。

问题描述 投票:0回答:1

我正在尝试将硒与ZAP整合。

为了达到这个目的,我使用了下面的代码来在使用硒启动浏览器之前自动打开ZAP工具。

我面临的问题是,ZAP工具不能正常打开,它卡在了中间。

下面的代码是我用来打开ZAP工具的。

代码:ZAP工具

public void triggerZAP() throws IOException, InterruptedException, ClientApiException
{       
    String[] command = { "CMD", "/C",zapLocation + "ZAP.exe" };
    ProcessBuilder build = new ProcessBuilder(command);
    build.directory(new File(zapLocation));
    Process p = build.start();
    p.waitFor();
    Thread.sleep(5000);
    ClientApi api = new ClientApi(zapAddress, zapPort);
    currentURL = controls.getCurrentUrl();
    System.out.println("Spider : " + currentURL);
    ApiResponse resp = api.spider.scan(currentURL, null, null, null, null);
    scanId = ((ApiResponseElement) resp).getValue();
    while (true)
    {
        Thread.sleep(1000);
        progress = Integer.parseInt(((ApiResponseElement) api.spider.status(scanId)).getValue());
        System.out.println("Spider progress : " + progress + "%");
        if (progress >= 100)
        {
            break;
        }
    }
    System.out.println("Spider complete");
    System.out.println(new String(api.core.xmlreport()));

}

错误:

org.zaproxy.clientapi.core.ClientApiException: java.net.ConnectException: Connection refused: connect
at org.zaproxy.clientapi.core.ClientApi.callApiDom(ClientApi.java:329)
at org.zaproxy.clientapi.core.ClientApi.callApi(ClientApi.java:311)
at org.zaproxy.clientapi.gen.Spider.scan(Spider.java:220)
at com.exterro.fusion.selenium.controls.ZAPConfigurations.triggerZAP(ZAPConfigurations.java:61)
at com.exterro.fusion.selenium.core.FusionSignin.config(FusionSignin.java:54)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient$1.run(Unknown Source)
at sun.net.www.http.HttpClient$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.http.HttpClient.privilegedOpenServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at org.zaproxy.clientapi.core.ClientApi.getConnectionInputStream(ClientApi.java:338)
at org.zaproxy.clientapi.core.ClientApi.callApiDom(ClientApi.java:327)
... 31 more
... Removed 27 stack frames
security selenium-webdriver penetration-testing zap zapproxy
1个回答
1
投票

看起来你在启动ZAP时没有指定API密钥。如果是这样的话,ZAP将为你创建一个,但你不知道它是什么,所以无法使用它,ZAP将忽略你的API调用。

要通过命令行设置一个API密钥,可以使用一个类似的选项。-config api.key=change-me-9203935709

你也可以在安全的环境下禁用API密钥--更多细节请看这里。https:/github.comzaproxyzaproxywikiFAQapikey。


0
投票

这个错误信息...

org.zaproxy.clientapi.core.ClientApiException: java.net.ConnectException: Connection refused: connect
at org.zaproxy.clientapi.core.ClientApi.callApiDom(ClientApi.java:329)

...意味着 Java客户端 无法启动新的连接。 代理人.


这个错误可能会因多种原因而出现。解决此错误的几个检查点如下。

ZAP_API_enable

你可以在 无法使用zap-java-api进行zap蜘蛛扫描。

  • 当你启动 Java客户端 连接,你需要提到 API密钥 强制性的,因为ZAP在默认情况下需要API密钥才能调用对ZAP进行修改的API操作。因此,为了调用任何API操作,默认情况下都需要API密钥。这是一个安全功能,以防止恶意网站调用ZAP API。API安全选项,包括API密钥,可以在 API选项屏幕.

    • 代码块。

      private static final int ZAP_PORT = 8080;
      private static final String ZAP_API_KEY = "abcdefghijklmnop123456789";
      private static final String ZAP_ADDRESS = "localhost";
      private static final String TARGET = "https://public-firing-range.appspot.com";
      

你可以在 使用OWASP Zap Api进行扫描。

© www.soinside.com 2019 - 2024. All rights reserved.