使用 ZAP Docker 映像扫描 API - 使用正则表达式替换

问题描述

我正在尝试使用此处描述的 API 扫描器 Docker 映像:https://www.zaproxy.org/blog/2017-06-19-scanning-apis-with-zap/ 并且我想使用正则表达式进行一些请求替换。我正在使用命令:

docker run -v $(pwd):/zap/wrk/:rw --network=host -t owasp/zap2docker-weekly zap-api-scan.py --hook=/zap/wrk/authentication-hooks.py -t docs/openapi.yaml -f openapi  -w output/oppenapi.md -z "-configfile /zap/wrk/zapproxy.prop" -d

使用“zapproxy.prop”:

replacer.full_list(0).description=customerId
replacer.full_list(0).enabled=true
replacer.full_list(0).matchtype=REQ_HEADER_STR
replacer.full_list(0).matchstr=/api/customers/\d+
replacer.full_list(0).regex=true
replacer.full_list(0).replacement=/api/customers/1

并且替换对我想修改的 URL 不起作用:GET /api/customers/10。通过 GUI 使用的相同规则工作正常。

我也试过:

replacer.full_list(0).description=customerId
replacer.full_list(0).enabled=true
replacer.full_list(0).matchtype=REQ_HEADER_STR
replacer.full_list(0).matchstr=/api/customers/10
replacer.full_list(0).regex=false
replacer.full_list(0).replacement=/api/customers/1

它也能正常工作。

Simon Bennetts 建议检查 GUI 如何保存这些设置:https://www.zaproxy.org/faq/how-do-you-find-out-what-key-to-use-to-set-a-config-value-on-the-command-line/。正如你所看到的 - 在 mastchstr 中没有任何逃避。

enter image description here

我需要做些什么才能正确传递这个正则表达式吗?

解决方法

问题是转义:

replacer.full_list(0).description=clientId
replacer.full_list(0).enabled=true
replacer.full_list(0).matchtype=REQ_HEADER_STR
replacer.full_list(0).matchstr=/api/customers/\\d+
replacer.full_list(0).regex=true
replacer.full_list(0).replacement=/api/customers/2