CVE-2022-21716: Twisted Twisted SSH Client And Server Vulnerability

HIGH
Advisory Identifier: GHSA-rv6r-3f5q-9rgx
CVSS 7.5
CWE-120 CWE-770
Published
Advisory Summary

CVE-2022-21716 is a HIGH (CVSS 7.5) twisted ssh client and server vulnerability (CWE-120: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')) affecting Twisted libraries in the PyPI ecosystem. The issue involves twisted ssh client and server deny of service during ssh handshake.. Remediation is available by upgrading affected packages to version 22.2.0.

CVE-2022-21716 at a Glance

CVE Identifier CVE-2022-21716
GHSA Identifier GHSA-rv6r-3f5q-9rgx
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-120: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
Affected Product Twisted
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity None (I:N)
Availability High (A:H)

How to Fix CVE-2022-21716

To remediate this vulnerability, upgrade all affected Twisted dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

twisted fixed: 22.2.0
pip install twisted>=22.2.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show twisted

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2022-21716, inspect your installed packages using pip:

pip show twisted

Analyze the terminal output to locate any version of Twisted in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 22.2.0), your application is affected.

Note: The pip show twisted command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-120: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow'), where the product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer. In Twisted, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact The Twisted SSH client and server implementation naively accepted an infinite amount of data for the peer's SSH version identifier. A malicious peer can trivially craft a request that uses all available memory and crash the server, resulting in denial of service. The attack is as simple as `nc -rv localhost 22 < /dev/zero`. ### Patches The issue was fix in GitHub commit https://github.com/twisted/twisted/commit/98387b39e9f0b21462f6abc7a1325dc370fcdeb1 A fix is available in Twisted 22.2.0. ### Workarounds * Limit access to the SSH server only to trusted source IP addresses. * Connect over SSH only to trusted destination IP addresses. ### References Reported at https://twistedmatrix.com/trac/ticket/10284 Discussions at https://github.com/twisted/twisted/security/advisories/GHSA-rv6r-3f5q-9rgx ### For more information Found by vin01

CVE-2022-21716 Affected Twisted Versions

1 component(s)
Fixed Versions:
22.2.0
Product / Package Ecosystem Affected Versions Fixed Version
twisted
PyPI
≥ 21.7.0
< 22.2.0
22.2.0

References

GitHub Advisory / Wiki ADVISORY
https://github.com/twisted/twisted/security/advisories/GHSA-rv6r-3f5q-9rgx
NVD — CVE-2022-21716 NVD
https://nvd.nist.gov/vuln/detail/CVE-2022-21716
Security Fix Commit FIX COMMIT
https://github.com/twisted/twisted/commit/89c395ee794e85a9657b112c4351417850330ef9
Security Fix Commit FIX COMMIT
https://github.com/twisted/twisted/commit/98387b39e9f0b21462f6abc7a1325dc370fcdeb1
Twisted Source Repository REPOSITORY
https://github.com/pypa/advisory-database/tree/main/vulns/twisted/PYSEC-2022-160.yaml
Twisted Source Repository REPOSITORY
https://github.com/twisted/twisted
Twisted Release RELEASE
https://github.com/twisted/twisted/releases/tag/twisted-22.2.0
lists.debian.org/debian-lts-announce... WEB
https://lists.debian.org/debian-lts-announce/2022/03/msg00009.html
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/7U6KYDTOLPICAVSR34G2WRYLFBD2YW5K
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/GLKHA6WREIVAMBQD7KKWYHPHGGNKMAG6
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/7U6KYDTOLPICAVSR34G2WRYLFBD2YW5K
lists.fedoraproject.org/archives/list/packa... WEB
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/GLKHA6WREIVAMBQD7KKWYHPHGGNKMAG6
Twisted Security Information SECURITY
https://security.gentoo.org/glsa/202301-02
Twisted Security Information SECURITY
https://twistedmatrix.com/trac/ticket/10284
Twisted Security Information SECURITY
https://www.oracle.com/security-alerts/cpuapr2022.html

Frequently Asked Questions

What is CVE-2022-21716?
CVE-2022-21716 is a security vulnerability in Twisted involving Twisted SSH client and server deny of service during SSH handshake. under CWE-120: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow').
Which Twisted versions are affected?
Affected versions include releases prior to 22.2.0 across affected packages: twisted.
What version fixes CVE-2022-21716?
Upgrading to 22.2.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is twisted affected?
Yes, twisted is affected in releases prior to 22.2.0. Upgrade your dependency to 22.2.0 or later.
What is the CVSS score of CVE-2022-21716?
CVE-2022-21716 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2022-21716?
CVE-2022-21716 is classified under CWE-120: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') (The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer.).
How can I check PyPI dependencies for CVE-2022-21716?
Run the dependency tree command: 'pip show twisted'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-rv6r-3f5q-9rgx",
  "modified" : "2024-11-25T18:33:22Z",
  "published" : "2022-03-03T19:02:08Z",
  "aliases" : [ "CVE-2022-21716" ],
  "summary" : "Twisted SSH client and server deny of service during SSH handshake.",
  "details" : "### Impact\n\nThe Twisted SSH client and server implementation naively accepted an infinite amount of data for the  peer's SSH version identifier.\n\nA malicious peer can trivially craft a request that uses all available memory and crash the server, resulting in denial of service. The attack is as simple as `nc -rv localhost 22 < /dev/zero`.\n\n### Patches\n\nThe issue was fix in GitHub commit https://github.com/twisted/twisted/commit/98387b39e9f0b21462f6abc7a1325dc370fcdeb1\n\nA fix is available in Twisted 22.2.0.\n\n### Workarounds\n\n* Limit access to the SSH server only to trusted source IP addresses.\n* Connect over SSH only to trusted destination IP addresses.\n\n### References\n\nReported at https://twistedmatrix.com/trac/ticket/10284\nDiscussions at https://github.com/twisted/twisted/security/advisories/GHSA-rv6r-3f5q-9rgx\n\n### For more information\n\nFound by vin01",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "twisted"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "21.7.0"
      }, {
        "fixed" : "22.2.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/twisted/twisted/security/advisories/GHSA-rv6r-3f5q-9rgx"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-21716"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twisted/twisted/commit/89c395ee794e85a9657b112c4351417850330ef9"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twisted/twisted/commit/98387b39e9f0b21462f6abc7a1325dc370fcdeb1"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/twisted/PYSEC-2022-160.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/twisted/twisted"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twisted/twisted/releases/tag/twisted-22.2.0"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2022/03/msg00009.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/7U6KYDTOLPICAVSR34G2WRYLFBD2YW5K"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/GLKHA6WREIVAMBQD7KKWYHPHGGNKMAG6"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/7U6KYDTOLPICAVSR34G2WRYLFBD2YW5K"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/GLKHA6WREIVAMBQD7KKWYHPHGGNKMAG6"
  }, {
    "type" : "WEB",
    "url" : "https://security.gentoo.org/glsa/202301-02"
  }, {
    "type" : "WEB",
    "url" : "https://twistedmatrix.com/trac/ticket/10284"
  }, {
    "type" : "WEB",
    "url" : "https://www.oracle.com/security-alerts/cpuapr2022.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-120", "CWE-770" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-03-03T19:02:08Z",
    "nvd_published_at" : "2022-03-03T21:15:00Z"
  }
}