用于从命令行执行目标测试的zap cli工具。
zapcli的Python项目详细描述
安装
要安装pypi的最新版本,可以运行以下命令:
pip install --upgrade zapcli
要安装最新开发版本的zap cli,可以运行 以下内容:
pip install --upgrade git+https://github.com/Grunny/zap-cli.git
安装zap cli进行开发,包括所需的依赖项 为了运行单元测试,克隆此存储库并使用 pip install -e .[dev]。
用法
要使用zap cli,需要设置zap运行在的端口(默认为8090)和 安装zap的文件夹的路径。这些可以设置为 命令行参数或使用环境变量ZAP_PORT和 ZAP_PATH。如果为zap设置了api密钥,也可以设置 作为命令行参数或使用ZAP_API_KEY环境 变量。
然后,zap cli可以与以下命令一起使用:
Usage: zap-cli [OPTIONS] COMMAND [ARGS]... ZAP CLI - A simple commandline tool for OWASP ZAP. Options: --boring Remove color from console output. -v, --verbose Add more verbose debugging output. --zap-path TEXT Path to the ZAP daemon. Defaults to /zap or the value of the environment variable ZAP_PATH. -p, --port INTEGER Port of the ZAP proxy. Defaults to 8090 or the value of the environment variable ZAP_PORT. --zap-url TEXT The URL of the ZAP proxy. Defaults to http://127.0.0.1 or the value of the environment variable ZAP_URL. --api-key TEXT The API key for using the ZAP API if required. Defaults to the value of the environment variable ZAP_API_KEY. --log-path TEXT Path to the directory in which to save the ZAP output log file. Defaults to the value of the environment variable ZAP_LOG_PATH and uses the value of --zap-path if it is not set. --help Show this message and exit. Commands: active-scan Run an Active Scan. ajax-spider Run the AJAX Spider against a URL. alerts Show alerts at the given alert level. context Manage contexts for the current session. exclude Exclude a pattern from all scanners. open-url Open a URL using the ZAP proxy. policies Enable or list a set of policies. quick-scan Run a quick scan. report Generate XML, MD or HTML report. scanners Enable, disable, or list a set of scanners. scripts Manage scripts. session Manage sessions. shutdown Shutdown the ZAP daemon. spider Run the spider against a URL. start Start the ZAP daemon. status Check if ZAP is running.
可以将--help与任何子命令一起使用,以获取有关如何使用 他们。
开始运行扫描
为了运行扫描,可以使用active-scan或quick-scan 命令。active-scan只对已经存在的url运行活动扫描 在zap的站点树中(即已经使用open-url命令打开,或者 通过运行spider找到。quick-scan命令的目的是 使用单个命令中包含的大多数选项对站点运行快速扫描 (包括能够在前后启动和关闭zap),所以您可以 一气呵成。没有传递给命令的任何其他选项,quick-scan 将打开URL以确保它在站点树中,运行活动扫描,并将 输出任何找到的警报。
作为一个例子,要运行一个url的快速扫描,该扫描将打开url并将其蜘蛛化,请扫描 递归地排除与给定regex匹配的url,并且只使用xss和sqli扫描仪, 您可以运行:
$ zap-cli quick-scan -s xss,sqli --spider -r -e "some_regex_pattern" http://127.0.0.1/ [INFO] Running a quick scan for http://127.0.0.1/ [INFO] Issues found: 1 +----------------------------------+--------+----------+---------------------------------------------------------------------------------+ | Alert | Risk | CWE ID | URL | +==================================+========+==========+=================================================================================+ | Cross Site Scripting (Reflected) | High | 79 | http://127.0.0.1/index.php?foo=%22%3E%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E | +----------------------------------+--------+----------+---------------------------------------------------------------------------------+
以上示例相当于按顺序运行以下命令:
$ zap-cli open-url http://127.0.0.1/ [INFO] Accessing URL http://127.0.0.1/ $ zap-cli exclude "some_regex_pattern" $ zap-cli spider http://127.0.0.1/ [INFO] Running spider... $ zap-cli active-scan --scanners xss,sqli --recursive http://127.0.0.1/ [INFO] Running an active scan... $ zap-cli alerts [INFO] Issues found: 1 +----------------------------------+--------+----------+---------------------------------------------------------------------------------+ | Alert | Risk | CWE ID | URL | +==================================+========+==========+=================================================================================+ | Cross Site Scripting (Reflected) | High | 79 | http://127.0.0.1/index.php?foo=%22%3E%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E | +----------------------------------+--------+----------+---------------------------------------------------------------------------------+
quick-scan命令还有一个--self-contained选项(或者简称为-sc) 如果zap还没有运行,它将首先尝试启动zap,并在 扫描完成。例如:
$ zap-cli quick-scan --self-contained --spider -r -s xss http://127.0.0.1/ [INFO] Starting ZAP daemon [INFO] Running a quick scan for http://127.0.0.1/ [INFO] Issues found: 1 +----------------------------------+--------+----------+---------------------------------------------------------------------------------+ | Alert | Risk | CWE ID | URL | +==================================+========+==========+=================================================================================+ | Cross Site Scripting (Reflected) | High | 79 | http://127.0.0.1/index.php?foo=%22%3E%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E | +----------------------------------+--------+----------+---------------------------------------------------------------------------------+ [INFO] Shutting down ZAP daemon
额外启动选项
您还可以使用--start-options或^{tt17}向zap的start命令传递额外的选项。$ 使用允许它的命令。例如,要使用自定义api密钥启动zap,可以使用:
$ zap-cli start --start-options '-config api.key=12345'
或者运行一个独立的快速扫描(扫描后将启动zap并关闭它 已完成)使用自定义API密钥,您可以使用:
$ zap-cli --api-key 12345 quick-scan --self-contained -o '-config api.key=12345' -s xss http://127.0.0.1/
或者在禁用API密钥的情况下运行相同的扫描:
$ zap-cli quick-scan -sc -o '-config api.disablekey=true' -s xss http://127.0.0.1/
以认证用户身份运行扫描
为了以经过身份验证的用户身份运行扫描,首先配置身份验证方法和用户 使用zap ui的上下文(请参见ZAP help page 更多信息)。一旦身份验证方法和用户准备好,就可以导出上下文 使用配置的身份验证方法,以便可以导入它并使用zap cli运行经过身份验证的扫描。
您可以通过zap ui或使用 context exportzap cli命令。例如,要将名为devtest的上下文导出到文件,可以运行:
$ zap-cli context export --name DevTest --file-path /home/user/DevTest.context
要导入保存的上下文以便稍后与zap cli一起使用,可以运行:
$ zap-cli context import /home/user/DevTest.context
使用配置的身份验证方法和用户导入上下文后,可以提供上下文名称 以及spider、active-scan和quick-scan命令的用户名,以在身份验证为 给定的用户。例如:
$ zap-cli context import /home/user/DevTest.context $ zap-cli open-url "http://localhost/" $ zap-cli spider --context-name DevTest --user-name SomeUser "http://localhost" $ zap-cli active-scan --recursive -c DevTest -u SomeUser "http://localhost" $ zap-cli quick-scan --recursive --spider -c DevTest -u SomeUser "http://localhost"