Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
CVE-2022-0778 — Proof-of-concept exploit for CVE-2022-0778, a denial-of-service vulnerability in OpenSSL's BN_mod_sqrt() function, with Docker-based lab environment for testing and analysis. | Kitploit
Tools/GitHubGitHub/jeongjunsoo/cve-2022-0778
Vulnerability AnalysisExploitationCryptographyLearning & EducationLabs & Practice
GitHubjeongjunsoo/cve-2022-0778

CVE-2022-0778

Proof-of-concept exploit for CVE-2022-0778, a denial-of-service vulnerability in OpenSSL's BN_mod_sqrt() function, with Docker-based lab environment for testing and analysis.

View Repository
12 years agoNot yet reviewed

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share

CVE-2022-0778

Contributors

  • Jeong Junsoo (@jeongjunsoo)

Summary

  • The CVE-2022-0778 vulnerability affects the BN_mod_sqrt() function in OpenSSL that computes the modular square root of a prime number.

  • When this function processes a maliciously crafted certificate that is not based on a prime number, an unpatched server can be exposed to a DoS attack.


Target

  • OpenSSL 1.0.2
  • OpenSSL 1.1.1
  • OpenSSL 3.0

Before Patch

root@kitploit:~
i = 1;
if (!BN_mod_sqr(t, b, p, ctx))
    goto end;
while (!BN_is_one(t)) {
    i++;
    if (i == e) {
        ERR_raise(ERR_LIB_BN, BN_R_NOT_A_SQUARE);
        goto end;
    }
    if (!BN_mod_mul(t, t, t, p, ctx))
        goto end;
}

  • According to this algorithm, the loop should terminate when the value of i reaches e.
  • However, if a specific input causes both i and e to have a value of 1, the loop does not terminate and an infinite loop occurs.
  • This results in a denial of service.

  • After Patch

    root@kitploit:~
    for (i = 1; i < e; i++) {
        if (i == 1) {
            if (!BN_mod_sqr(t, b, p, ctx))
                goto end;
        } else {
            if (!BN_mod_mul(t, t, t, p, ctx))
                goto end;
        }
        if (BN_is_one(t))
            break;
    }
    /* If not found, a is not a square or p is not prime. */
    if (i >= e) {
        ERR_raise(ERR_LIB_BN, BN_R_NOT_A_SQUARE);
        goto end;
    }
    
    
    • The existing while loop was changed to a for loop.
    • Accordingly, the loop is automatically terminated when the value of i reaches e.
    • The patch eliminates the risk of an infinite loop.

    Environment Setup and Execution

    • Ubuntu environment setup

    • docker compose up -d Run test environment

    • docker run -it --rm -p 12345:12345 yywing/cve-2022-0778 --addr 0.0.0.0:12345

    • docker compose exec curl top Check process status

    • docker compose exec curl bash Run bash

    • curl -k https://172.17.0.1:12345 Send HTTPS request to port 12345


    Execution

    • Prepare three terminal windows (A, B, C) for the lab.

    • Run the command docker run -it --rm -p 12345:12345 yywing/cve-2022-0778 --addr 0.0.0.0:12345 in terminal A to start the Docker image.

    • Next, run the command docker compose exec curl top in terminal B to check the status of currently running processes.

    • Finally, in terminal C, enter docker compose exec curl bash, then send an HTTPS request to port 12345 with curl -k https://172.17.0.1:12345.

    Result

    • From the result of the top command executed in terminal B, we can see that the curl process is using nearly 100% of CPU resources. This is caused by an infinite loop.

    Summary

    • This vulnerability is caused by the lack of verification of whether the number is prime.
    • To prevent the infinite loop issue, the while statement was changed to a for statement as a patch.

    References

    • https://github.com/drago-96/CVE-2022-0778

    • https://hackyboiz.github.io/2022/03/19/syru/cve-2022-0778/

    • https://github.com/yywing/cve-2022-0778/

    Download Tool