CVE-2016-5100 (published 2017-02-13T18:59Z)

Froxlor before 0.9.35 uses the PHP rand function for random number generation, which makes it easier for remote attackers to guess the password reset token by predicting a value.

Severity: MEDIUM
CVSS v2 base score: 5.0 (AV:N/AC:L/Au:N/C:P/I:N/A:N)
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-330
cwe_name: Use of Insufficiently Random Values
description: The product uses insufficiently random numbers or values in a security context that depends on unpredictable numbers.
extended_description: When product generates predictable values in a context requiring unpredictability, it may be possible for an attacker to guess the next value that will be generated, and use this guess to impersonate another user or access sensitive information.
         

Fix information:
repo_url: https://github.com/Froxlor/Froxlor
commit_details: repo_url: https://github.com/Froxlor/Froxlor
author: Michael Kaufmann (d00p)
author_date: 2016-01-28 08:27:15+01:00
msg: avoid rand() if possible as it is not generating cryptographically secure values, thx to Hanno for putting some effort into this

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
repository: repo_url: https://github.com/Froxlor/Froxlor
repo_name: froxlor/Froxlor
description: The server administration software for your needs - The official Froxlor development Git repository
repo_language: PHP
owner: Froxlor
file_changes: filename: index.php
change_type: ModificationType.MODIFY
diff: @@ -345,8 +345,8 @@ if ($action == 'forgotpwd') {
 				if ($user !== false) {
 					// build a activation code
 					$timestamp = time();
-					$first = substr(md5($user['loginname'] . $timestamp . rand(0, $timestamp)), 0, 15);
-					$third = substr(md5($user['email'] . $timestamp . rand(0, $timestamp)), -15);
+					$first = substr(md5($user['loginname'] . $timestamp . randomStr(16)), 0, 15);
+					$third = substr(md5($user['email'] . $timestamp . randomStr(16)), -15);
 					$activationcode = $first . $timestamp . $third . substr(md5($third . $timestamp), 0, 10);
 
 					// Drop all existing activation codes for this user

programming_language: PHP
filename: function.randomStr.php
change_type: ModificationType.ADD
diff: @@ -0,0 +1,44 @@
+<?php
+
+/**
+ * This file is part of the Froxlor project.
+ * Copyright (c) 2010 the Froxlor Team (see authors).
+ *
+ * For the full copyright and license information, please view the COPYING
+ * file that was distributed with this source code. You can also view the
+ * COPYING file online at http://files.froxlor.org/misc/COPYING.txt
+ *
+ * @copyright  (c) the authors
+ * @author     Froxlor team <team@froxlor.org> (2016-)
+ * @license    GPLv2 http://files.froxlor.org/misc/COPYING.txt
+ * @package    Functions
+ *
+ */
+
+/**
+ * Function randomStr
+ *
+ * generate a pseudo-random string of bytes
+ *
+ * @param int $length            
+ *
+ * @return string
+ */
+function randomStr($length)
+{
+    if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
+        return random_bytes($length);
+    } elseif (function_exists('openssl_random_pseudo_bytes')) {
+        return openssl_random_pseudo_bytes($length);
+    } else {
+        $pr_bits = '';
+        $fp = @fopen('/dev/urandom', 'rb');
+        if ($fp !== false) {
+            $pr_bits .= @fread($fp, $length);
+            @fclose($fp);
+        } else {
+            $pr_bits = substr(rand(time()).rand(time()), 0, $length);
+        }
+        return $pr_bits;
+    }
+}

programming_language: PHP