目录
  • 关于pip-audit
  • 功能介绍
  • 工具安装
    • 第三方包
  • 工具使用
    • 退出代码
      • 工具使用样例
        • 许可证协议

          关于pip-audit

          pip-audit是一款功能强大的安全漏洞扫描工具,该工具主要针对python环境,可以帮助广大研究人员扫描和测试python包中的已知安全漏洞。pip-audit使用了pythonpackagingadvisory数据库pypijsonapi作为漏洞报告源。

          功能介绍

          • 1、支持对本地环境和依赖组件(requirements风格文件)进行安全审计;
          • 2、支持多种漏洞服务(pypi、osv);
          • 3、支持以cyclonedx xml或json格式发送sbom;
          • 4、提供人类和机器均可读的输出格式(columnar、json);
          • 5、无缝接入 / 重用本地pip缓存;

          工具安装

          pip-audit基于python开发,且要求本地环境为python 3.7或更新版本。安装并配置好python环境之后,就可以使用下列命令并通过pip来安装pip-audit了:

          python -m pip install pip-audit
          

          第三方包

          pip-audit的正常运行需要使用到多个第三方包,具体组件包名称和版本如下图所示:

          除此之外,我们还可以通过conda来安装pip-audit:

          conda install -c conda-forge pip-audit

           

          工具使用

          我们可以直接将pip-audit以独立程序运行,或通过“python -m”运行:

          pip-audit --help
          
          python -m pip_audit --help
          
          usage: pip-audit [-h] [-v] [-l] [-r requirements] [-f format] [-s service]
                           [-d] [-s] [--desc [{on,off,auto}]] [--cache-dir cache_dir]
                           [--progress-spinner {on,off}] [--timeout timeout]
                           [--path paths] [-v] [--fix] [--require-hashes]
          audit the python environment for dependencies with known vulnerabilities
          
          optional arguments:
            -h, --help            show this help message and exit
            -v, --version         show program's version number and exit
            -l, --local           show only results for dependencies in the local
                                  environment (default: false)
            -r requirements, --requirement requirements
                                  audit the given requirements file; this option can be
                                  used multiple times (default: none)
            -f format, --format format
                                  the format to emit audit results in (choices: columns,
                                  json, cyclonedx-json, cyclonedx-xml) (default:
                                  columns)
            -s service, --vulnerability-service service
                                  the vulnerability service to audit dependencies
                                  against (choices: osv, pypi) (default: pypi)
            -d, --dry-run         without `--fix`: collect all dependencies but do not
                                  perform the auditing step; with `--fix`: perform the
                                  auditing step but do not perform any fixes (default:
                                  false)
            -s, --strict          fail the entire audit if dependency collection fails
                                  on any dependency (default: false)
            --desc [{on,off,auto}]
                                  include a description for each vulnerability; `auto`
                                  defaults to `on` for the `json` format. this flag has
                                  no effect on the `cyclonedx-json` or `cyclonedx-xml`
                                  formats. (default: auto)
            --cache-dir cache_dir
                                  the directory to use as an http cache for pypi; uses
                                  the `pip` http cache by default (default: none)
            --progress-spinner {on,off}
                                  display a progress spinner (default: on)
            --timeout timeout     set the socket timeout (default: 15)
            --path paths          restrict to the specified installation path for
                                  auditing packages; this option can be used multiple
                                  times (default: [])
            -v, --verbose         give more output; this setting overrides the
                                  `pip_audit_loglevel` variable and is equivalent to
                                  setting it to `debug` (default: false)
            --fix                 automatically upgrade dependencies with known
                                  vulnerabilities (default: false)
            --require-hashes      require a hash to check each requirement against, for
                                  repeatable audits; this option is implied when any
                                  package in a requirements file has a `--hash` option.
                                  (default: false)
          

          退出代码

          任务完成后, pip-audit将会退出运行,并返回一个代码以显示其状态,其中:

          0:未检测到已知漏洞;

          1:检测到了一个或多个已知漏洞;

          工具使用样例

          审计当前python环境中的依赖:

          $ pip-audit
          no known vulnerabilities found
          

          审计给定requirements文件的依赖:

          $ pip-audit -r ./requirements.txt
          no known vulnerabilities found
          

          审计一个requirements文件,并排除系统包:

          $ pip-audit -r ./requirements.txt -l
          no known vulnerabilities found
          

          审计依赖中发现的安全漏洞:

          $ pip-audit
          found 2 known vulnerabilities in 1 package
          name  version id             fix versions
          ----  ------- -------------- ------------
          flask 0.5     pysec-2019-179 1.0
          flask 0.5     pysec-2018-66  0.12.3
          

          审计依赖(包含描述):

          $ pip-audit --desc
          
          found 2 known vulnerabilities in 1 package
          
          name  version id             fix versions description
          
          ----  ------- -------------- ------------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
          
          flask 0.5     pysec-2019-179 1.0          the pallets project flask before 1.0 is affected by: unexpected memory usage. the impact is: denial of service. the attack vector is: crafted encoded json data. the fixed version is: 1\. note: this may overlap cve-2018-1000656.
          
          flask 0.5     pysec-2018-66  0.12.3       the pallets project flask version before 0.12.3 contains a cwe-20: improper input validation vulnerability in flask that can result in large amount of memory usage possibly leading to denial of service. this attack appear to be exploitable via attacker provides json data in incorrect encoding. this vulnerability appears to have been fixed in 0.12.3\. note: this may overlap cve-2019-1010083.
          

          审计json格式依赖:

          $ pip-audit -f json | jq
          found 2 known vulnerabilities in 1 package
          [
          {
          "name": "flask",
          "version": "0.5",
          "vulns": [
          {
          "id": "pysec-2019-179",
          "fix_versions": [
          "1.0"
          ],
          "description": "the pallets project flask before 1.0 is affected by: unexpected memory usage. the impact is: denial of service. the attack vector is: crafted encoded json data. the fixed version is: 1\. note: this may overlap cve-2018-1000656."
          },
          {
          "id": "pysec-2018-66",
          "fix_versions": [
          "0.12.3"
          ],
          "description": "the pallets project flask version before 0.12.3 contains a cwe-20: improper input validation vulnerability in flask that can result in large amount of memory usage possibly leading to denial of service. this attack appear to be exploitable via attacker provides json data in incorrect encoding. this vulnerability appears to have been fixed in 0.12.3\. note: this may overlap cve-2019-1010083."
          }
          ]
          },
          {
          "name": "jinja2",
          "version": "3.0.2",
          "vulns": []
          },
          {
          "name": "pip",
          "version": "21.3.1",
          "vulns": []
          },
          {
          "name": "setuptools",
          "version": "57.4.0",
          "vulns": []
          },
          {
          "name": "werkzeug",
          "version": "2.0.2",
          "vulns": []
          },
          {
          "name": "markupsafe",
          "version": "2.0.1",
          "vulns": []
          }
          ]

          审计并尝试自动审计存在漏洞的依赖:

          $ pip-audit --fix
          
          found 2 known vulnerabilities in 1 package and fixed 2 vulnerabilities in 1 package
          
          name  version id             fix versions applied fix
          
          ----- ------- -------------- ------------ ----------------------------------------
          
          flask 0.5     pysec-2019-179 1.0          successfully upgraded flask (0.5 => 1.0)
          
          flask 0.5     pysec-2018-66  0.12.3       successfully upgraded flask (0.5 => 1.0)
          

          许可证协议

          本项目的开发与发布遵循 apache 2.0开源许可证协议。

          以上就是python环境功能强大的pip-audit安全漏洞扫描工具的详细内容,更多关于pip-audit安全漏洞扫描工具的资料请关注www.887551.com其它相关文章!