CVE-2016-6175 (published 2017-02-07T15:59Z)

Eval injection vulnerability in php-gettext 1.0.12 and earlier allows remote attackers to execute arbitrary PHP code via a crafted plural forms header.

Severity: HIGH
CVSS v2 base score: 7.5 (AV:N/AC:L/Au:N/C:P/I:P/A:P)
CVSS v3 base score: 9.8, CRITICAL (CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-94
cwe_name: Improper Control of Generation of Code ('Code Injection')
description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
extended_description: 
            When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. Such an alteration could lead to arbitrary code execution.
            Injection problems encompass a wide variety of issues -- all mitigated in very different ways. For this reason, the most effective way to discuss these weaknesses is to note the distinct features which classify them as injection weaknesses. The most important issue to note is that all injection problems share one thing in common -- i.e., they allow for the injection of control plane data into the user-controlled data plane. This means that the execution of the process may be altered by sending code in through legitimate data channels, using no other mechanism. While buffer overflows, and many other flaws, involve the use of some further issue to gain execution, injection problems need only for the data to be parsed. The most classic instantiations of this category of weakness are SQL injection and format string vulnerabilities.
         
         

Fix information:
repo_url: https://github.com/NagVis/nagvis
commit_details: repo_url: https://github.com/NagVis/nagvis
author: Lars Michelsen
author_date: 2016-06-25 13:21:48+02:00
msg: Clarified change log on php-gettext 1.0.12 update
repository: repo_url: https://github.com/NagVis/nagvis
repo_name: NagVis/nagvis
description: Visualization addon for your open source monitoring core
repo_language: PHP
owner: NagVis
file_changes: filename: ChangeLog
change_type: ModificationType.MODIFY
diff: @@ -3,22 +3,9 @@ Core:
   * MK BI backend: Now prints an error message when trying to use it with
     objects that are not aggregations.
   * NDO MySQL backend: Filtering out legacy objects from DB (setting is_active filter)
-  * FIX: A local exploitable security issue has been discovered in the php-gettext
-    library which is used to make NagVis localizable on platforms which has no gettext
-    support built into PHP.
-
-    A local user with privileges to create/modify the .mo files used by NagVis
-    could modify a file in a way that it executes custom code with the privileges of
-    the web server which is executing the NagVis code.
-
-    To more than 99% of NagVis installations (installed with the install.sh
-    installer or OMD) this is no special threat because a user which is able to .mo
-    files is able to modify the .php program files of NagVis. An attacker
-    would rather modify the .php files directly instead of injecting it's code through
-    the .mo files.
-
-    However, to fix this for most installations minor issue, we included php-gettext
-    in version 1.0.12 with this release which fixes the issue.
+  * FIX: Updated php-gettext to 1.0.12 and commented out unused code because it contains
+    some exploitable PHP code which could be used to inject code using modified .mo files.
+    However, NagVis has never used these functions, so was never affected by this issue.
 
 Frontend:
   * FIX: Fixed error in ad-hoc automaps (Network Topology in Check_MK) during state updates

programming_language: Markdown
filename: gettext.php
change_type: ModificationType.MODIFY
diff: @@ -275,34 +275,34 @@ class gettext_reader {
    * @access private
    * @return string sanitized plural form expression
    */
-  function sanitize_plural_expression($expr) {
-    // Get rid of disallowed characters.
-    $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
-
-    // Add parenthesis for tertiary '?' operator.
-    $expr .= ';';
-    $res = '';
-    $p = 0;
-    for ($i = 0; $i < strlen($expr); $i++) {
-      $ch = $expr[$i];
-      switch ($ch) {
-      case '?':
-        $res .= ' ? (';
-        $p++;
-        break;
-      case ':':
-        $res .= ') : (';
-        break;
-      case ';':
-        $res .= str_repeat( ')', $p) . ';';
-        $p = 0;
-        break;
-      default:
-        $res .= $ch;
-      }
-    }
-    return $res;
-  }
+  //function sanitize_plural_expression($expr) {
+  //  // Get rid of disallowed characters.
+  //  $expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
+
+  //  // Add parenthesis for tertiary '?' operator.
+  //  $expr .= ';';
+  //  $res = '';
+  //  $p = 0;
+  //  for ($i = 0; $i < strlen($expr); $i++) {
+  //    $ch = $expr[$i];
+  //    switch ($ch) {
+  //    case '?':
+  //      $res .= ' ? (';
+  //      $p++;
+  //      break;
+  //    case ':':
+  //      $res .= ') : (';
+  //      break;
+  //    case ';':
+  //      $res .= str_repeat( ')', $p) . ';';
+  //      $p = 0;
+  //      break;
+  //    default:
+  //      $res .= $ch;
+  //    }
+  //  }
+  //  return $res;
+  //}
 
   /**
    * Parse full PO header and extract only plural forms line.
@@ -310,13 +310,13 @@ class gettext_reader {
    * @access private
    * @return string verbatim plural form header field
    */
-  function extract_plural_forms_header_from_po_header($header) {
-    if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs))
-      $expr = $regs[2];
-    else
-      $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
-    return $expr;
-  }
+  //function extract_plural_forms_header_from_po_header($header) {
+  //  if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs))
+  //    $expr = $regs[2];
+  //  else
+  //    $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
+  //  return $expr;
+  //}
 
   /**
    * Get possible plural forms from MO header
@@ -324,23 +324,24 @@ class gettext_reader {
    * @access private
    * @return string plural form header
    */
-  function get_plural_forms() {
-    // lets assume message number 0 is header
-    // this is true, right?
-    $this->load_tables();
-
-    // cache header field for plural forms
-    if (! is_string($this->pluralheader)) {
-      if ($this->enable_cache) {
-        $header = $this->cache_translations[""];
-      } else {
-        $header = $this->get_translation_string(0);
-      }
-      $expr = $this->extract_plural_forms_header_from_po_header($header);
-      $this->pluralheader = $this->sanitize_plural_expression($expr);
-    }
-    return $this->pluralheader;
-  }
+  //function get_plural_forms() {
+  //  // lets assume message number 0 is header
+  //  // this is true, right?
+  //  $this->load_tables();
+
+  //  // cache header field for plural forms
+  //  if (! is_string($this->pluralheader)) {
+  //    if ($this->enable_cache) {
+  //      $header = $this->cache_translations[""];
+  //    } else {
+  //      $header = $this->get_translation_string(0);
+  //    }
+  //    print($header);
+  //    $expr = $this->extract_plural_forms_header_from_po_header($header);
+  //    $this->pluralheader = $this->sanitize_plural_expression($expr);
+  //  }
+  //  return $this->pluralheader;
+  //}
 
   /**
    * Detects which plural form to take
@@ -349,23 +350,23 @@ class gettext_reader {
    * @param n count
    * @return int array index of the right plural form
    */
-  function select_string($n) {
-    if (!is_int($n)) {
-      throw new InvalidArgumentException(
-        "Select_string only accepts integers: " . $n);
-    }
-    $string = $this->get_plural_forms();
-    $string = str_replace('nplurals',"\$total",$string);
-    $string = str_replace("n",$n,$string);
-    $string = str_replace('plural',"\$plural",$string);
-
-    $total = 0;
-    $plural = 0;
-
-    eval("$string");
-    if ($plural >= $total) $plural = $total - 1;
-    return $plural;
-  }
+  //function select_string($n) {
+  //  if (!is_int($n)) {
+  //    throw new InvalidArgumentException(
+  //      "Select_string only accepts integers: " . $n);
+  //  }
+  //  $string = $this->get_plural_forms();
+  //  $string = str_replace('nplurals',"\$total",$string);
+  //  $string = str_replace("n",$n,$string);
+  //  $string = str_replace('plural',"\$plural",$string);
+
+  //  $total = 0;
+  //  $plural = 0;
+
+  //  eval("$string");
+  //  if ($plural >= $total) $plural = $total - 1;
+  //  return $plural;
+  //}
 
   /**
    * Plural version of gettext
@@ -376,40 +377,40 @@ class gettext_reader {
    * @param string number
    * @return translated plural form
    */
-  function ngettext($single, $plural, $number) {
-    if ($this->short_circuit) {
-      if ($number != 1)
-        return $plural;
-      else
-        return $single;
-    }
-
-    // find out the appropriate form
-    $select = $this->select_string($number);
-
-    // this should contains all strings separated by NULLs
-    $key = $single . chr(0) . $plural;
-
-
-    if ($this->enable_cache) {
-      if (! array_key_exists($key, $this->cache_translations)) {
-        return ($number != 1) ? $plural : $single;
-      } else {
-        $result = $this->cache_translations[$key];
-        $list = explode(chr(0), $result);
-        return $list[$select];
-      }
-    } else {
-      $num = $this->find_string($key);
-      if ($num == -1) {
-        return ($number != 1) ? $plural : $single;
-      } else {
-        $result = $this->get_translation_string($num);
-        $list = explode(chr(0), $result);
-        return $list[$select];
-      }
-    }
-  }
+  //function ngettext($single, $plural, $number) {
+  //  if ($this->short_circuit) {
+  //    if ($number != 1)
+  //      return $plural;
+  //    else
+  //      return $single;
+  //  }
+
+  //  // find out the appropriate form
+  //  $select = $this->select_string($number);
+
+  //  // this should contains all strings separated by NULLs
+  //  $key = $single . chr(0) . $plural;
+
+
+  //  if ($this->enable_cache) {
+  //    if (! array_key_exists($key, $this->cache_translations)) {
+  //      return ($number != 1) ? $plural : $single;
+  //    } else {
+  //      $result = $this->cache_translations[$key];
+  //      $list = explode(chr(0), $result);
+  //      return $list[$select];
+  //    }
+  //  } else {
+  //    $num = $this->find_string($key);
+  //    if ($num == -1) {
+  //      return ($number != 1) ? $plural : $single;
+  //    } else {
+  //      $result = $this->get_translation_string($num);
+  //      $list = explode(chr(0), $result);
+  //      return $list[$select];
+  //    }
+  //  }
+  //}
 
   function pgettext($context, $msgid) {
     $key = $context . chr(4) . $msgid;
@@ -421,16 +422,16 @@ class gettext_reader {
     }
   }
 
-  function npgettext($context, $singular, $plural, $number) {
-    $key = $context . chr(4) . $singular;
-    $ret = $this->ngettext($key, $plural, $number);
-    if (strpos($ret, "\004") !== FALSE) {
-      return $singular;
-    } else {
-      return $ret;
-    }
+  //function npgettext($context, $singular, $plural, $number) {
+  //  $key = $context . chr(4) . $singular;
+  //  $ret = $this->ngettext($key, $plural, $number);
+  //  if (strpos($ret, "\004") !== FALSE) {
+  //    return $singular;
+  //  } else {
+  //    return $ret;
+  //  }
 
-  }
+  //}
 }
 
 ?>

programming_language: PHP