关于pip-auditpip-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 --helppython -m pip_audit --helpusage: 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 vulnerabilitiesoptional arguments:-h, --helpshow this help message and exit-V, --versionshow program's version number and exit-l, --localshow only results for dependencies in the localenvironment (default: False)-r REQUIREMENTS, --requirement REQUIREMENTSaudit the given requirements file; this option can beused multiple times (default: None)-f FORMAT, --format FORMATthe format to emit audit results in (choices: columns,json, cyclonedx-json, cyclonedx-xml) (default:columns)-s SERVICE, --vulnerability-service SERVICEthe vulnerability service to audit dependenciesagainst (choices: osv, pypi) (default: pypi)-d, --dry-runwithout `--fix`: collect all dependencies but do notperform the auditing step; with `--fix`: perform theauditing step but do not perform any fixes (default:False)-S, --strictfail the entire audit if dependency collection failson any dependency (default: False)--desc [{on,off,auto}]include a description for each vulnerability; `auto`defaults to `on` for the `json` format. This flag hasno effect on the `cyclonedx-json` or `cyclonedx-xml`formats. (default: auto)--cache-dir CACHE_DIRthe directory to use as an HTTP cache for PyPI; usesthe `pip` HTTP cache by default (default: None)--progress-spinner {on,off}display a progress spinner (default: on)--timeout TIMEOUTset the socket timeout (default: 15)--path PATHSrestrict to the specified installation path forauditing packages; this option can be used multipletimes (default: [])-v, --verbosegive more output; this setting overrides the`PIP_AUDIT_LOGLEVEL` variable and is equivalent tosetting it to `debug` (default: False)--fixautomatically upgrade dependencies with knownvulnerabilities (default: False)--require-hashesrequire a hash to check each requirement against, forrepeatable audits; this option is implied when anypackage in a requirements file has a `--hash` option.(default: False)退出代码任务完成后, pip-audit将会退出运行,并返回一个代码以显示其状态,其中:
0:未检测到已知漏洞;
1:检测到了一个或多个已知漏洞;
工具使用样例审计当前Python环境中的依赖:
标签:漏洞,扫描,工具