Skip to main content

用于从命令行进行目标测试的 ZAP CLI 工具。

项目描述

快速命令行

https://travis-ci.org/Grunny/zap-cli.svg?branch=master

一个命令行工具,它封装了 OWASP ZAP API,用于控制 ZAP 并执行快速、有针对性的攻击。

安装

要从 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_PORTZAP_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-scanquick-scan 命令。主动扫描只对已经在 ZAP 站点树中的 URL 运行主动扫描(即已经使用open-url命令打开或通过运行蜘蛛找到)。快速扫描命令旨在成为一种对站点进行快速扫描的方法,其中大多数选项包含在单个命令中(包括能够在之前和之后启动和关闭 ZAP),因此您可以一次完成所有操作。如果没有传递给命令的任何其他选项,快速扫描 将打开 URL 以确保它在站点树中,运行主动扫描,并输出任何找到的警报。

例如,要对将打开并抓取 URL、递归扫描、排除与给定正则表达式匹配的 URL 并仅使用 XSS 和 SQLi 扫描器的 URL 进行快速扫描,您可以运行:

$ 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。例如:

$ 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-o将额外的选项传递给 ZAP 的启动命令,并使用 允许它的命令。例如,要使用自定义 API 密钥启动 ZAP,您可以使用:

$ zap-cli start --start-options '-config api.key=12345'

或者使用自定义 API 密钥运行独立的快速扫描(将启动 ZAP 并在扫描完成后将其关闭),您可以使用:

$ 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 帮助页面 )。准备好身份验证方法和用户后,您可以使用配置的身份验证方法导出上下文,以便将其导入并用于使用 ZAP CLI 运行经过身份验证的扫描。

您可以使用通过 ZAP UI 或使用 context export ZAP CLI 命令配置的身份验证方法和用户导出上下文。例如,要将名为 DevTest 的上下文导出到文件,您可以运行:

$ zap-cli context export --name DevTest --file-path /home/user/DevTest.context

要导入保存的上下文以供稍后与 ZAP CLI 一起使用,您可以运行:

$ zap-cli context import /home/user/DevTest.context

使用配置的身份验证方法和用户导入上下文后,您可以将上下文名称和用户名提供给spideractive-scanquick-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 快速扫描 --recursive --spider -c DevTest -u SomeUser "http://localhost"

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

zapcli-0.10.0.tar.gz (15.6 kB 查看哈希)

已上传 source