lightswitch05/php-version-audit

一个方便的工具,可以轻松检查指定版本的PHP与定期更新的CVE漏洞列表、新版本和停用日期的对应关系

1.20240922.1 2024-09-22 13:25 UTC

This package is auto-updated.

Last update: 2024-09-22 13:26:36 UTC


README

PHP Version Audit Logo

Github Stars GitHub Workflow Status Packagist Version Docker Pulls license last commit commit activity

PHP版本审计是一个方便的工具,可以轻松检查给定版本的PHP与定期更新的CVE漏洞列表、新版本和停用日期的对应关系。

PHP版本审计不是:漏洞检测/缓解、特定供应商版本跟踪、替代保持对PHP发布和安全漏洞的了解。

功能

  • 列出PHP特定版本的已知CVE
  • 检查PHP的运行时版本或提供的版本
  • 显示PHP特定版本的停用日期
  • 显示PHP特定版本的新版本,具有可配置的特定性(最新/次要/补丁)
    • 补丁:7.3.0 -> 7.3.33
    • 次要:7.3.0 -> 7.4.27
    • 最新:7.3.0 -> 8.1.1
  • 规则每天自动更新两次。信息直接来源于php.net - 你将无需等待像我这样的人合并拉取请求才能获取最新的补丁信息。
  • 多个接口:CLI(通过PHP Composer)、Docker、直接代码导入
  • 易于脚本化,可用于CI/CD工作流程。所有Docker/CLI输出都是JSON格式,可以与您喜欢的工具一起使用,例如jq
  • 可配置的退出条件。使用CLI标志如--fail-security设置一个失败退出代码,如果给定的PHP版本有已知的CVE或不再接收安全更新。
  • 无依赖项

示例

docker run --rm -t lightswitch05/php-version-audit:latest --version=8.0.12
{
    "auditVersion": "8.0.12",
    "hasVulnerabilities": true,
    "hasSecuritySupport": true,
    "hasActiveSupport": true,
    "isLatestPatchVersion": false,
    "isLatestMinorVersion": false,
    "isLatestVersion": false,
    "latestPatchVersion": "8.0.14",
    "latestMinorVersion": "8.1.1",
    "latestVersion": "8.1.1",
    "activeSupportEndDate": "2022-11-26T00:00:00+0000",
    "securitySupportEndDate": "2023-11-26T00:00:00+0000",
    "rulesLastUpdatedDate": "2022-01-18T02:13:52+0000",
    "vulnerabilities": {
        "CVE-2021-21707": {
            "id": "CVE-2021-21707",
            "baseScore": 5.3,
            "publishedDate": "2021-11-29T07:15:00+0000",
            "lastModifiedDate": "2022-01-04T16:12:00+0000",
            "description": "In PHP versions 7.3.x below 7.3.33, 7.4.x below 7.4.26 and 8.0.x below 8.0.13, certain XML parsing functions, like simplexml_load_file(), URL-decode the filename passed to them. If that filename contains URL-encoded NUL character, this may cause the function to interpret this as the end of the filename, thus interpreting the filename differently from what the user intended, which may lead it to reading a different file than intended."
        }
    }
}

用法

Docker

使用Docker是使用PHP版本审计的首选和最简单的方式。

使用Docker检查特定的PHP版本

docker run --rm -t lightswitch05/php-version-audit:latest --version=8.1.1

使用Docker检查主机的PHP版本

docker run --rm -t lightswitch05/php-version-audit:latest --version=$(php -r 'echo phpversion();')

在HTTPS代理后面运行(用于受限网络)。需要一个包含您的信任证书的目录的卷挂载(具有.crt扩展名) - 更多信息请参阅update-ca-certificates

docker run --rm -t -e https_proxy='https://your.proxy.server:port/' --volume /full/path/to/trusted/certs/directory:/usr/local/share/ca-certificates lightswitch05/php-version-audit:latest --version=8.1.1

命令行界面

不使用Docker?没问题。这需要多几步,但直接运行同样简单。

通过composer安装包

composer require lightswitch05/php-version-audit:~1.0

执行PHP脚本,检查PHP的运行时版本

./vendor/bin/php-version-audit

如果发现任何CVE,则产生一个退出代码

./vendor/bin/php-version-audit --fail-security

直接调用

想与PHP版本审计集成?当然可以。请注意,这是一个非常早期的版本。我没有任何计划进行重大更改,但如果需要实现新功能,我也不会承诺保持接口不变。Docker/CLI是比直接调用更受欢迎的方法。

$phpVersionAudit = new lightswitch05\PhpVersionAudit\Application(phpversion(), false);
$phpVersionAudit->hasVulnerabilities(); #=> true
$phpVersionAudit->getLatestPatchVersion(); #=> '8.1.1'

JSON规则

驱动PHP版本审计所使用的数据会定期自动更新,并托管在GitHub页面上。这是PHP版本审计的核心内容,您可以直接使用它在其他工具中。如果您选择这样做,请尊重项目许可证,并给出适当的归属通知。此外,我要求任何实现都应读取lastUpdatedDate,如果它已过时(2周以上)则失败。由于它是自动更新的,所以这种情况不应该发生……但我们都知道软件是多么脆弱。

使用curljq从规则中直接获取最新的PHP 8.1发布版本。

curl -s https://www.github.developerdan.com/php-version-audit/rules-v1.json | jq '.latestVersions["8.1"]'

选项

usage: php-version-audit        [--help] [--version=PHP_VERSION]
                                [--fail-security] [--fail-support]
                                [--fail-patch] [--fail-latest]
                                [--no-update] [--silent]
                                [--v]

optional arguments:
--help                          show this help message and exit.
--version                       set the PHP Version to run against. Defaults to the runtime version. This is required when running with docker.
--fail-security                 generate a 10 exit code if any CVEs are found, or security support has ended.
--fail-support                  generate a 20 exit code if the version of PHP no longer gets active (bug) support.
--fail-patch                    generate a 30 exit code if there is a newer patch-level release.
--fail-latest                   generate a 40 exit code if there is a newer release.
--no-update                     do not download the latest rules. NOT RECOMMENDED!
--silent                        do not write any error messages to STDERR.
--v                             Set verbosity. v=warnings, vv=info, vvv=debug. Default is error. All logging writes to STDERR.

输出

  • auditVersion: string - 正在审计的PHP版本。
  • hasVulnerabilities: bool - auditVersion是否有已知的CVE。
  • hasSecuritySupport: bool - auditVersion是否仍在接收安全更新。
  • hasActiveSupport: bool - auditVersion是否仍在接收活跃支持(错误更新)。
  • isLatestPatchVersion: bool - auditVersion是否是最新补丁级别发布(8.0.x)。
  • isLatestMinorVersion: bool - auditVersion是否是最新次要级别发布(8.x.x)。
  • isLatestVersion: bool - auditVersion是否是最新发布(x.x.x)。
  • latestPatchVersion: string - auditVersion的最新补丁级别版本。
  • latestMinorVersion: string - auditVersion的最新次要级别版本。
  • latestVersion: string - 最新PHP版本。
  • activeSupportEndDate: string|null - auditVersion活跃支持结束的ISO8601格式日期(错误修复)。
  • securitySupportEndDate: string - auditVersion安全支持结束的ISO8601格式日期。
  • rulesLastUpdatedDate: string - 规则上次自动更新的ISO8601格式日期(每天两次)。
  • vulnerabilities: object - 影响auditVersion的CVE及其详细信息。对于最近发现的CVE,CVE详细信息可能为null。

项目目标

  • 始终使用最新信息,如果信息过于陈旧则失败。由于此工具旨在帮助用户保持了解,因此如果工具过时,它必须相应地失败。
  • 如果请求的信息不可用则失败。例如,获取PHP版本6.0或5.7.0的支持结束日期。同样,由于此工具旨在帮助用户保持了解,如果请求的信息不可用,则必须相应地失败。
  • 在公开和封闭网络中工作(只要工具是最新的)。
  • 最小化足迹和依赖。
  • 支持最老的PHP支持版本。如果您使用此工具与不受支持的PHP版本,那么您已经有了此工具可以提供的所有答案:是的,您有漏洞,并且已经过时。当然,这只是为了运行时,此项目的目标仍然是提供有关任何合理版本PHP的信息。

致谢 & 许可

  • 本项目采用Apache License 2.0发布。
  • 本项目提供信息的准确性无法验证或保证。所有功能仅提供方便,不应用于可靠性、准确性或准时性。
  • 该标志是基于Colin Viebrock的PHP Logo创建的,作为基本图像,并采用Creative Commons Attribution-Share Alike 4.0 International发布。标志已被修改,以包括叠加图形。
  • Colin Viebrock不认可本项目和修改后的PHP标志的使用。
  • The PHP Group不认可本项目和PHP名称的使用。
  • CVE详细信息及描述是从国家标准化技术研究院的国家漏洞数据库下载的。本项目及CVE信息的用途未获得NIST或NVD的支持。CVE详细信息仅提供方便。信息准确性无法验证。
  • PHP发布详情和支持日期是从变更日志(4578)以及支持版本EOL日期中解析出来的。信息准确性无法验证。