在 docker 环境中通过 OWASP zap 扫描 Rest API

Scanning Rest API's through OWASP zap inside a docker environment

我设置了一个 Azure devops CI/CD 构建,它将启动一个虚拟机,其中 Owasp Zap 运行ning 作为代理,Owasp zap Azure devops 任务将 运行 在目标 url 并将我的报告复制到 Azure 存储中。

关注了这个人的漂亮教程:https://kasunkodagoda.com/2017/09/03/introducing-owasp-zed-attack-proxy-task-for-visual-studio-team-services/ (也是创建 Azure devops 任务的人)

一切都很好,但最近我想使用 REST Api 作为目标 url。 azure devops 中的 Owasp zap 任务没有这个能力。甚至询问了创建者 (https://github.com/kasunkv/owasp-zap-vsts-task/issues/30#issuecomment-452258621),他也不认为这可以通过 Azure devops 任务获得,只能通过 docker.

在我的下一个任务中,我现在正在尝试将其 运行 放入 docker 图像中。 (首先在 Azure devops 中,但并不顺利 https://github.com/zaproxy/zaproxy/issues/5176 ) 终于开始学习本教程了 (https://zaproxy.blogspot.com/2017/06/scanning-apis-with-zap.html)

我尝试通过以下步骤运行 docker 图像:

--- docker pull owasp/zap2docker-weekly

--运行安装容器

--------命令:docker run -v ${pwd}:/zap/wrk/:rw -t owasp/zap2docker-weekly zap-api-scan.py -t https://apiurl/api.json -f openapi -z "-configfile /zap/wrk/options.prop"

------- options.prop file
  -config replacer.full_list\(0\).description=auth1 \
  -config replacer.full_list\(0\).enabled=true \
  -config replacer.full_list\(0\).matchtype=REQ_HEADER \
  -config replacer.full_list\(0\).matchstr=Authorization \
  -config replacer.full_list\(0\).regex=false \
  -config replacer.full_list\(0\).replacement=Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

但是这只扫描根 url 而不是每个 URL。当我输入这个问题时,我尝试从根目录下载 json 文件并 运行ning docker 运行 命令并通过 json 文件传递-t 我得到了导入的 url 的数量:似乎是一切。但这似乎在 powershell 中冻结了。

我错过了哪一步才能在休息时进行完整的递归扫描api? 任何人有一些想法或一些帮助吗?

首先,您的属性文件格式有误。如果直接在命令行上设置选项,则只需要“-config”和“\”。在 属性 文件中你应该有:

replacer.full_list(0).description=auth1
replacer.full_list(0).enabled=true
replacer.full_list(0).matchtype=REQ_HEADER
replacer.full_list(0).matchstr=Authorization
replacer.full_list(0).regex=false
replacer.full_list(0).replacement=Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

其次,https://apiurl/api.json return 是什么,您是否检查过可以从 docker 容器中访问它? 尝试 运行

curl https://apiurl/api.json

看看你得到了什么。