CVE-2021-4336 (published 2023-05-28T22:15Z)

A vulnerability was found in ITRS Group monitor-ninja up to 2021.11.1. It has been rated as critical. Affected by this issue is some unknown functionality of the file modules/reports/models/scheduled_reports.php. The manipulation leads to sql injection. Upgrading to version 2021.11.30 is able to address this issue. The name of the patch is 6da9080faec9bca1ca5342386c0421dca0a6c0cc. It is recommended to upgrade the affected component. The identifier of this vulnerability is VDB-230084.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-89
cwe_name: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
extended_description: 
            
            
         
         

Fix information:
repo_url: https://github.com/ITRS-Group/monitor-ninja
commit_details: repo_url: https://github.com/ITRS-Group/monitor-ninja
author: Petter Nyström
author_date: 2021-09-17 16:04:17+02:00
msg: Prevent SQL injections

This escapes a bunch of variables used in SQL statements, which could
otherwise be used to perform SQL injection attacks.

This is part of MON-12841.

Signed-off-by: Petter Nyström <pnystrom@itrsgroup.com>
repository: repo_url: https://github.com/ITRS-Group/monitor-ninja
repo_name: ITRS-Group/monitor-ninja
description: Ninja is Now Just Awesome - a modern web GUI for Naemon
repo_language: PHP
owner: ITRS-Group
file_changes: filename: scheduled_reports.php
change_type: ModificationType.MODIFY
diff: @@ -37,7 +37,7 @@ class Scheduled_reports_Model extends Model
 
 		$row = $res->current();
 		$report_type_id = $row->id;
-		$sql = "DELETE FROM scheduled_reports WHERE report_type_id=".$report_type_id." AND report_id=".$id;
+		$sql = "DELETE FROM scheduled_reports WHERE report_type_id=".$db->escape($report_type_id)." AND report_id=".$db->escape($id);
 		try {
 			$db->query($sql);
 		} catch (Kohana_Database_Exception $e) {
@@ -74,7 +74,7 @@ class Scheduled_reports_Model extends Model
 				scheduled_report_periods rp,
 				saved_reports r
 			WHERE
-				rt.identifier='".$type."' AND
+				rt.identifier=".$db->escape($type)." AND
 				sr.report_type_id=rt.id AND
 				rp.id=sr.period_id AND
 				sr.report_id=r.id".$sql_xtra."
@@ -205,9 +205,9 @@ class Scheduled_reports_Model extends Model
 
 		if ($id) {
 			// UPDATE
-			$sql = "UPDATE scheduled_reports SET ".self::USERFIELD."=".$db->escape($user).", report_type_id=".$rep_type.", report_id=".$saved_report_id.", recipients=".$db->escape($recipients).", period_id=".$period.", filename=".$db->escape($filename).", description=".$db->escape($description).", local_persistent_filepath = ".$db->escape($local_persistent_filepath).", attach_description = ".$db->escape($attach_description)." WHERE id=".$id;
+			$sql = "UPDATE scheduled_reports SET ".self::USERFIELD."=".$db->escape($user).", report_type_id=".$db->escape($rep_type).", report_id=".$db->escape($saved_report_id).", recipients=".$db->escape($recipients).", period_id=".$db->escape($period).", filename=".$db->escape($filename).", description=".$db->escape($description).", local_persistent_filepath = ".$db->escape($local_persistent_filepath).", attach_description = ".$db->escape($attach_description)." WHERE id=".$db->escape($id);
 		} else {
-			$sql = "INSERT INTO scheduled_reports (".self::USERFIELD.", report_type_id, report_id, recipients, period_id, filename, description, local_persistent_filepath, attach_description, report_time, report_on, report_period)VALUES(".$db->escape($user).", ".$rep_type.", ".$saved_report_id.", ".$db->escape($recipients).", ".$period.", ".$db->escape($filename).", ".$db->escape($description).", ".$db->escape($local_persistent_filepath).", ".$db->escape($attach_description).", '".$report_time."', '".$report_on."', '".$report_period."' )";
+			$sql = "INSERT INTO scheduled_reports (".self::USERFIELD.", report_type_id, report_id, recipients, period_id, filename, description, local_persistent_filepath, attach_description, report_time, report_on, report_period)VALUES(".$db->escape($user).", ".$db->escape($rep_type).", ".$db->escape($saved_report_id).", ".$db->escape($recipients).", ".$db->escape($period).", ".$db->escape($filename).", ".$db->escape($description).", ".$db->escape($local_persistent_filepath).", ".$db->escape($attach_description).", ".$db->escape($report_time).", ".$db->escape($report_on).", ".$db->escape($report_period).")";
 
 		}
 
@@ -234,11 +234,11 @@ class Scheduled_reports_Model extends Model
 	 */
 	static function update_report_field($id=false, $field=false, $value=false)
 	{
-		$id = (int)$id;
-		$field = trim($field);
-		$value = trim($value);
 		$db = Database::instance();
-		$sql = "UPDATE scheduled_reports SET ".$field."= ".$db->escape($value)." WHERE id=".$id;
+		$id = (int)$id;
+		$field = $db->escape_column(trim($field));
+		$value = $db->escape(trim($value));
+		$sql = "UPDATE scheduled_reports SET {$field}={$value} WHERE id={$id}";
 		try {
 			$res = $db->query($sql);
 		} catch (Kohana_Database_Exception $e) {

programming_language: PHP