# CVE-2022-29245: Weak private key generation in SSH.NET

> Weak random number generation in SSH.NET allows attackers to decrypt SSH communications by brute-forcing private key seeds.

- **Severity:** Medium 6.5 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:N/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 31 May 2022
- **Updated:** 22 Apr 2025
- **Also known as:** GHSA-72p8-v4hg-v45p

## What is CVE-2022-29245?

CVE-2022-29245 is a medium-severity vulnerability in sshnet SSH.NET, published on 31 May 2022. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

SSH.NET is a Secure Shell (SSH) library for .NET. In versions 2020.0.0 and 2020.0.1, during an `X25519` key exchange, the client’s private key is generated with `System.Random`. `System.Random` is not a cryptographically secure random number generator, it must therefore not be used for cryptographic purposes. When establishing an SSH connection to a remote host, during the X25519 key exchange, the private key is generated with a weak random number generator whose seed can be brute forced. This allows an attacker who is able to eavesdrop on the communications to decrypt them. Version 2020.0.2 contains a patch for this issue. As a workaround, one may disable support for `curve25519-sha256` and `curve25519-sha256@libssh.org` key exchange algorithms.

Weakness: CWE-338 (Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG))

## Which versions are affected by CVE-2022-29245?

2 open source packages ship an affected version, including SSH.NET. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `SSH.NET` | NuGet | All versions | 2020.0.2 |
| `SSH.NET` | NuGet | All versions | 2020.0.2 |

Products: Ssh.net Project Ssh.net.

## How do I fix CVE-2022-29245?

Upgrade SSH.NET to 2020.0.2 or later.

## Is CVE-2022-29245 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2022-29245 exists.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2022-29245 and fix it if it is affected.

What it is: CVE-2022-29245 is a medium-severity vulnerability in sshnet SSH.NET, published on 31 May 2022. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2022-29245 exists.

Affected packages and fixed versions:
- SSH.NET (NuGet): affected all versions; fixed in 2020.0.2
- SSH.NET (NuGet): affected all versions; fixed in 2020.0.2

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2022-29245/ (Markdown: https://insights.sbomify.com/CVE-2022-29245/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2022-29245
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2022-29245
- OSV: https://osv.dev/vulnerability/CVE-2022-29245

---
From sbomify Insights: https://insights.sbomify.com/CVE-2022-29245/
Summaries are generated and may contain mistakes; the official description above is the record.
