Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:32554
HistoryOct 12, 2015 - 12:00 a.m.

CVE-2015-7392 Heap overflow in Freeswitch json parser < 1.6.2 & < 1.4.23

2015-10-1200:00:00
vulners.com
15
  1. Advisory Information

Title: Heap overflow in freeswitch json parser < 1.6.2 & < 1.4.23
Submitter: Marcello Duarte ([email protected])
Product: freeswitch
Product URL: http://freeswitch.org
Affected Versions: freeswitch < 1.6.2 & < 1.4.23
Fixed Versions: 1.6.2 , 1.4.23
Link to source code diff:
https://freeswitch.org/stash/projects/FS/repos/freeswitch/commits/cf892528a1a107ed6eb67fb98ed22533e27778fd
CVE Status: CVE-2015-7392

  1. Vulnerability Information

Impact: Code execution
Remotely Exploitable: Yes
Locally Exploitable: No

  1. Vulnerability Description

Product Information: FreeSWITCH is a scalable open source
cross-platform telephony platform designed to route and interconnect
popular communication protocols using audio, video, text or any other
form of media. It was created in 2006 to fill the void left by
proprietary commercial solutions. FreeSWITCH also provides a stable
telephony platform on which many applications can be developed using a
wide range of free tools.

Vulnerability:

A carefully crafted json string supplied to cJSON_Parse will trigger a
heap overflow with user controlled data.

The underlying vulnerability occurs in the parse_string function.

By passing a json string with \u at the end of the string will cause
the parser to increment past the null at the end of string.

This confuses the code responsible for copying the string. Since it
doesn't detect the NULL in this situation, it will keep copying until
it hits a null in memory. This leads to a heap overflow with user
controlled data.

Any modules or core code which allows user supplied json to enter the
json parser will be vulnerable.

Vulnerable Source Code:

static const char *parse_string(cJSON *item, const char *str) {

/* HACKLOG The length of string is determined here, it will stop
counting when it hits a null */

while (*ptr != '\"' && *ptr && ++len)
if (ptr++ == '\\')
ptr++; /
Skip escaped quotes. */

/* HACKLOG The buffer is alloced with the length obtained from the
previous section */

out = (char )cJSON_malloc(
len + 1); /
This is how long we need for the string, roughly. */
if (!out)
return 0;

/* HACKLOG the following code will copy the string into the alloced
buffer taking into account utf16 to utf8 conversion */

ptr = str + 1;
ptr2 = out;
/* 1 */
while (*ptr != '\"' && *ptr) {
if (*ptr != '\\')
*ptr2++ = *ptr++;
else {
ptr++;
switch (*ptr) {
case 'b':
*ptr2++ = '\b';
break;
case 'f':
*ptr2++ = '\f';
break;
case 'n':
*ptr2++ = '\n';
break;
case 'r':
*ptr2++ = '\r';
break;
case 't':
ptr2++ = '\t';
break;
case 'u': /
transcode utf16 to utf8. */
if (sscanf(ptr + 1, "%4x", &uc) < 1)
break;

ptr += 4; /* get the unicode char. */

    if &#40;&#40;uc &gt;= 0xDC00 &amp;&amp; uc &lt;= 0xDFFF&#41; || uc == 0&#41;
      break; // check for invalid.

    if &#40;uc &gt;= 0xD800 &amp;&amp; uc &lt;= 0xDBFF&#41; // UTF16 surrogate pairs.
    {
      if &#40;ptr[1] != &#39;&#92;&#92;&#39; || ptr[2] != &#39;u&#39;&#41;
        break; // missing second-half of surrogate.
      if &#40;sscanf&#40;ptr + 3, &quot;&#37;4x&quot;, &amp;uc2&#41; &lt; 1&#41;
        break;
      ptr += 6;
      if &#40;uc2 &lt; 0xDC00 || uc2 &gt; 0xDFFF&#41;
        break; // invalid second-half of surrogate.
      uc = 0x10000 | &#40;&#40;uc &amp; 0x3FF&#41; &lt;&lt; 10&#41; | &#40;uc2 &amp; 0x3FF&#41;;
    }

    len = 4;
    if &#40;uc &lt; 0x80&#41;
      len = 1;
    else if &#40;uc &lt; 0x800&#41;
      len = 2;
    else if &#40;uc &lt; 0x10000&#41;
      len = 3;
    ptr2 += len;

    switch &#40;len&#41; {
    case 4:
      *--ptr2 = &#40;&#40;uc | 0x80&#41; &amp; 0xBF&#41;;
      uc &gt;&gt;= 6;
    case 3:
      *--ptr2 = &#40;&#40;uc | 0x80&#41; &amp; 0xBF&#41;;
      uc &gt;&gt;= 6;
    case 2:
      *--ptr2 = &#40;&#40;uc | 0x80&#41; &amp; 0xBF&#41;;
      uc &gt;&gt;= 6;
    case 1:
      *--ptr2 = &#40;char&#41;&#40;uc | firstByteMark[len]&#41;;
    }
    ptr2 += len;
    break;
  default:
    *ptr2++ = *ptr;
    break;
  }

  /* HACKLOG INCREMENTS past null here, causing the while loop to

not detect the end of the buffer so it keeps copying past the end of
the alloced buffer */
ptr++;
}

  1. Vendor Information, Solutions

Freeswitch has released versions 1.6.2 , 1.4.23 which fix the issue.

  1. Credits

This vulnerability was discovered and researched by Marcello Duarte (
[email protected] ) from CYBERSIGHT GROUP Vulnerability
Research Labs.

  1. Report Timeline
    2015-09-02 - Vulnerability found
    2015-09-13 - Freeswitch developers contacted
    2015-09-14 - Freeswitch developers verified bug and patched in master
    2015-09-25 - Freeswitch releases fixed packages.
    2015-09-20 - CVE requested
    2015-09-29 - CVE issued, Advisory released

  2. About CYBERSIGHT GROUP

CYBERSIGHT GROUP is an organization of security professionals
specializing in several areas of offensive computer security research.
We specialize in vulnerability research, exploit development, reverse
engineering and cyber attack planning. http://cybersightgroup.com ,
[email protected]

  1. Disclaimer

The information provided in the advisory is provided as is without any
warranty. CYBERSIGHT GROUP and it's members are not liable in any case
of damage, direct or indirect. Permission to redistribute the
advisory in it's unmodified form is granted.


Marcello Duarte
Chief Research Officer
CYBERSIGHT GROUP

Related for SECURITYVULNS:DOC:32554