Owasp Zap 测试休息 api

Owasp Zap Testing rest api

是否可以通过 OWASP ZAP 测试 rest-api? Url 攻击仅对 GET 请求有效。

例如,我的 api 控制器仅使用令牌。我有 TokenController,此控制器需要通过 JSON 数据获取 POST 数据,包括密码和登录名。我可以通过 OWASP 测试这个控制器吗?

简短的回答是肯定的。长答案 - 这很复杂 :)

测试 REST API 比测试 Web API 更难一些 - 您必须向 Zap 提供有关 API 的信息 - 它有哪些端点、参数等。你能分享更多关于你 API 的信息吗?它有 OpenAPI/Swagger 文档吗?你有现成的测试吗?您可以使用其中之一来完成此任务。

我讲了如何实现这一点 - 你可以找到录音 here

可以使用 OWASP ZAP 自动执行 API testint,但要执行测试,我看到两个选项: 提供一些使用模式,例如 OpenAPI for ZAP 考虑提取信息。第二种选择是 运行 自动测试以捕获 ZAP 作为被动扫描信息,然后您可以测试会话信息。

我们建议使用 OpenAPI 文档。 黄瓜测试看起来像这样:

Feature: Security
  This feature is to test pokemon service security

  Scenario: Validate passive and active scan
    Given I import context from open API specification "/v2/api-docs"
    And I remove alerts
      | url                    |
      | http://.*/v2/api-docs* |
    And I import scan policy "javaclean" from file "javaclean.policy"
    When I run active scan
    And I generate security test HTML report with name "java-clean-security-report"
    Then the number of risks per category should not be greater than
      | low | medium | high | informational |
      | 0   | 0      | 0    | 0             |

我正在为 ZAP 开发步骤,在 GitHub 中查看:https://github.com/osvaldjr/easy-cucumber/wiki/Security-steps

导入打开的示例步骤API 文档:

@Given("^I import context from open API specification \"([^\"]*)\"$")
  public void iImportContextFromOpenAPISpecification(String path)
      throws ClientApiException, InterruptedException {
    String url = getTargetUrl() + path;
    log.info("Import Open API from url: " + url);
    zapProxyApi.openapi.importUrl(url, null);

    waitPassiveScanRunning();
    verifyThatTheProxyHasCapturedHostInformation();
  }

查看其他步骤:https://github.com/osvaldjr/easy-cucumber/blob/master/src/main/java/io/github/osvaldjr/stepdefinitions/steps/SecuritySteps.java