使用 ZAP Docker 图片扫描 API - 用正则表达式替换

Scanning APIs with ZAP Docker image - replacer with regex

我正在尝试使用 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 中没有任何转义符。

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

转义是问题所在:

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