CVE-2022-35153 (published 2022-08-18T05:15Z)

FusionPBX 5.0.1 was discovered to contain a command injection vulnerability via /fax/fax_send.php.

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-116
cwe_name: Improper Encoding or Escaping of Output
description: The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved.
extended_description: 
            Improper encoding or escaping can allow attackers to change the commands that are sent to another component, inserting malicious commands instead.
            Most products follow a certain protocol that uses structured messages for communication between components, such as queries or commands. These structured messages can contain raw data interspersed with metadata or control information. For example, "GET /index.html HTTP/1.1" is a structured message containing a command ("GET") with a single argument ("/index.html") and metadata about which protocol version is being used ("HTTP/1.1").
            If an application uses attacker-supplied inputs to construct a structured message without properly encoding or escaping, then the attacker could insert special characters that will cause the data to be interpreted as control information or metadata. Consequently, the component that receives the output will perform the wrong operations, or otherwise interpret the data incorrectly.
         
         

Fix information:
repo_url: https://github.com/fusionpbx/fusionpbx
commit_details: repo_url: https://github.com/fusionpbx/fusionpbx
author: FusionPBX
author_date: 2022-06-29 10:24:05-06:00
msg: Security use escapeshellarg
repository: repo_url: https://github.com/fusionpbx/fusionpbx
repo_name: fusionpbx/fusionpbx
description: Official FusionPBX - A full-featured domain based multi-tenant PBX and voice switch for FreeSwitch.
repo_language: PHP
owner: fusionpbx
file_changes: filename: fax_send.php
change_type: ModificationType.MODIFY
diff: @@ -312,7 +312,7 @@ if (!function_exists('fax_split_dtmf')) {
 				if ($fax_file_extension != "pdf" && $fax_file_extension != "tif") {
 					chdir($dir_fax_temp);
 					$command = $IS_WINDOWS ? '' : 'export HOME=/tmp && ';
-					$command .= 'libreoffice --headless --convert-to pdf --outdir '.$dir_fax_temp.' '.$dir_fax_temp.'/'.$fax_name.'.'.$fax_file_extension;
+					$command .= 'libreoffice --headless --convert-to pdf --outdir '.$dir_fax_temp.' '.$dir_fax_temp.'/'.escapeshellarg($fax_name).'.'.escapeshellarg($fax_file_extension);
 					exec($command);
 					@unlink($dir_fax_temp.'/'.$fax_name.'.'.$fax_file_extension);
 				}
@@ -322,7 +322,7 @@ if (!function_exists('fax_split_dtmf')) {
 					chdir($dir_fax_temp);
 
 					//convert pdf to tif
-					$cmd = exec('which gs')." -q -r".$gs_r." -g".$gs_g." -dBATCH -dPDFFitPage -dNOSAFER -dNOPAUSE -dBATCH -sOutputFile=".correct_path($fax_name).".tif -sDEVICE=tiffg4 -Ilib stocht.ps -c \"{ .75 gt { 1 } { 0 } ifelse} settransfer\" -- ".correct_path($fax_name).".pdf -c quit";
+					$cmd = exec('which gs')." -q -r".$gs_r." -g".$gs_g." -dBATCH -dPDFFitPage -dNOSAFER -dNOPAUSE -dBATCH -sOutputFile=".escapeshellarg($fax_name).".tif -sDEVICE=tiffg4 -Ilib stocht.ps -c \"{ .75 gt { 1 } { 0 } ifelse} settransfer\" -- ".escapeshellarg($fax_name).".pdf -c quit";
 					// echo($cmd . "<br/>\n");
 					exec($cmd);
 					@unlink($dir_fax_temp.'/'.$fax_name.'.pdf');
@@ -672,17 +672,17 @@ if (!function_exists('fax_split_dtmf')) {
 
 		//send the fax
 		$fax_file = $dir_fax_sent."/".$fax_instance_uuid.".tif";
-		$common_variables .= "fax_queue_uuid='"               . $fax_queue_uuid          . "',";
+		$common_variables .= "fax_queue_uuid='"               . escapeshellarg($fax_queue_uuid)          . "',";
 		$common_variables  = "for_fax=1,";
-		$common_variables .= "accountcode='"                  . $fax_accountcode         . "',";
-		$common_variables .= "sip_h_X-accountcode='"          . $fax_accountcode         . "',";
-		$common_variables .= "domain_uuid="                   . $_SESSION["domain_uuid"] . ",";
-		$common_variables .= "domain_name="                   . $_SESSION["domain_name"] . ",";
-		$common_variables .= "origination_caller_id_name='"   . $fax_caller_id_name      . "',";
-		$common_variables .= "origination_caller_id_number='" . $fax_caller_id_number    . "',";
-		$common_variables .= "fax_ident='"                    . $fax_caller_id_number    . "',";
-		$common_variables .= "fax_header='"                   . $fax_caller_id_name      . "',";
-		$common_variables .= "fax_file='"                     . $fax_file                . "',";
+		$common_variables .= "accountcode='"                  . escapeshellarg($fax_accountcode)         . "',";
+		$common_variables .= "sip_h_X-accountcode='"          . escapeshellarg($fax_accountcode)         . "',";
+		$common_variables .= "domain_uuid="                   . escapeshellarg($_SESSION["domain_uuid"]) . ",";
+		$common_variables .= "domain_name="                   . escapeshellarg($_SESSION["domain_name"]) . ",";
+		$common_variables .= "origination_caller_id_name='"   . escapeshellarg($fax_caller_id_name)      . "',";
+		$common_variables .= "origination_caller_id_number='" . escapeshellarg($fax_caller_id_number)    . "',";
+		$common_variables .= "fax_ident='"                    . escapeshellarg($fax_caller_id_number)    . "',";
+		$common_variables .= "fax_header='"                   . escapeshellarg($fax_caller_id_name)      . "',";
+		$common_variables .= "fax_file='"                     . escapeshellarg($fax_file)               . "',";
 
 		foreach ($fax_numbers as $fax_number) {
 
@@ -704,16 +704,16 @@ if (!function_exists('fax_split_dtmf')) {
 				$fax_uri = $route_array[0];
 				$fax_variables = "";
 				foreach($_SESSION['fax']['variable'] as $variable) {
-					$fax_variables .= $variable.",";
+					$fax_variables .= escapeshellarg($variable).",";
 				}
 			}
 
 			//build the fax dial string
 			$dial_string = $common_variables;
 			$dial_string .= $fax_variables;
-			$dial_string .= "mailto_address='"     . $mail_to_address   . "',";
-			$dial_string .= "mailfrom_address='"   . $mail_from_address . "',";
-			$dial_string .= "fax_uri=" . $fax_uri  . ",";
+			$dial_string .= "mailto_address='"     . escapeshellarg($mail_to_address)   . "',";
+			$dial_string .= "mailfrom_address='"   . escapeshellarg($mail_from_address) . "',";
+			$dial_string .= "fax_uri="             . escapeshellarg($fax_uri)           . ",";
 			$dial_string .= "fax_retry_attempts=1" . ",";
 			$dial_string .= "fax_retry_limit=20"   . ",";
 			$dial_string .= "fax_retry_sleep=180"  . ",";

programming_language: PHP
repo_url: https://github.com/fusionpbx/fusionpbx
commit_details: repo_url: https://github.com/fusionpbx/fusionpbx
author: FusionPBX
author_date: 2022-06-29 10:38:36-06:00
msg: Add escapeshellarg to the variables used in the command line.
repository: repo_url: https://github.com/fusionpbx/fusionpbx
repo_name: fusionpbx/fusionpbx
description: Official FusionPBX - A full-featured domain based multi-tenant PBX and voice switch for FreeSwitch.
repo_language: PHP
owner: fusionpbx
file_changes: filename: fax_to_email.php
change_type: ModificationType.MODIFY
diff: @@ -273,7 +273,7 @@ if (!function_exists('fax_split_dtmf')) {
 		$tmp_array = explode("=", $_SERVER["argv"][9]);
 		$fax_prefix = $tmp_array[1];
 		unset($tmp_array);
-	
+
 		$tmp_array = explode("=", $_SERVER["argv"][10]);
 		$mail_from_address = $tmp_array[1];
 		unset($tmp_array);
@@ -381,7 +381,7 @@ if (!function_exists('fax_split_dtmf')) {
 		if (isset($fax_forward_number) && strlen($fax_forward_number) > 0) {
 			//show info
 				echo "fax_forward_number: $fax_forward_number\n";
-		
+
 			//add fax to the fax queue or send it directly
 			if ($_SESSION['fax_queue']['enabled']['boolean'] == 'true') {
 				//build an array to add the fax to the queue
@@ -427,7 +427,7 @@ if (!function_exists('fax_split_dtmf')) {
 				$route_array = outbound_route_to_bridge($domain_uuid, $fax_forward_number);
 				if (count($route_array) == 0) {
 					//send the internal call to the registered extension
-						$fax_uri = "user/".$fax_forward_number."@".$domain_name;
+						$fax_uri = "user/".escapeshellarg($fax_forward_number)."@".escapeshellarg($domain_name);
 						$fax_variables = "";
 				}
 				else {
@@ -435,35 +435,35 @@ if (!function_exists('fax_split_dtmf')) {
 						$fax_uri = $route_array[0];
 						$fax_variables = "";
 						foreach($_SESSION['fax']['variable'] as $variable) {
-							$fax_variables .= $variable.",";
+							$fax_variables .= escapeshellarg($variable).",";
 						}
 				}
 
 				//build the dial string
 				$dial_string = "absolute_codec_string='PCMU,PCMA',";
-				$dial_string .= "accountcode='"                  . $fax_accountcode         . "',";
-				$dial_string .= "sip_h_X-accountcode='"          . $fax_accountcode         . "',";
-				$dial_string .= "domain_uuid="                   . $domain_uuid . ",";
-				$dial_string .= "domain_name="                   . $domain_name . ",";
-				$dial_string .= "origination_caller_id_name='"   . $fax_caller_id_name      . "',";
-				$dial_string .= "origination_caller_id_number='" . $fax_caller_id_number    . "',";
-				$dial_string .= "fax_ident='"                    . $fax_caller_id_number    . "',";
-				$dial_string .= "fax_header='"                   . $fax_caller_id_name      . "',";
-				$dial_string .= "fax_file='"                     . $fax_file                . "',";
+				$dial_string .= "accountcode='"                  . escapeshellarg($fax_accountcode)         . "',";
+				$dial_string .= "sip_h_X-accountcode='"          . escapeshellarg($fax_accountcode)         . "',";
+				$dial_string .= "domain_uuid="                   . escapeshellarg($domain_uuid)             . ",";
+				$dial_string .= "domain_name="                   . escapeshellarg($domain_name)             . ",";
+				$dial_string .= "origination_caller_id_name='"   . escapeshellarg($fax_caller_id_name)      . "',";
+				$dial_string .= "origination_caller_id_number='" . escapeshellarg($fax_caller_id_number)    . "',";
+				$dial_string .= "fax_ident='"                    . escapeshellarg($fax_caller_id_number)    . "',";
+				$dial_string .= "fax_header='"                   . escapeshellarg($fax_caller_id_name)      . "',";
+				$dial_string .= "fax_file='"                     . escapeshellarg($fax_file)                . "',";
 
 				if ($fax_send_mode != 'queue') {
 					//add more ot the dial string
 						$dial_string .= $fax_variables;
-						$dial_string .= "mailto_address='"     . $mail_to_address   . "',";
-						$dial_string .= "mailfrom_address='"   . $mail_from_address . "',";
-						$dial_string .= "fax_uri=" . $fax_uri  . ",";
+						$dial_string .= "mailto_address='"     . escapeshellarg($mail_to_address)   . "',";
+						$dial_string .= "mailfrom_address='"   . escapeshellarg($mail_from_address) . "',";
+						$dial_string .= "fax_uri="             . escapeshellarg($fax_uri)  . ",";
 						$dial_string .= "fax_retry_attempts=1" . ",";
 						$dial_string .= "fax_retry_limit=20"   . ",";
 						$dial_string .= "fax_retry_sleep=180"  . ",";
 						$dial_string .= "fax_verbose=true"     . ",";
 						$dial_string .= "fax_use_ecm=off"      . ",";
 						$dial_string .= "api_hangup_hook='lua fax_retry.lua'";
-						$dial_string = "{" . $dial_string . "}" . $fax_uri." &txfax('".$fax_file."')";
+						$dial_string = "{" . $dial_string . "}" . escapeshellarg($fax_uri)." &txfax('".escapeshellarg($fax_file)."')";
 
 					//get the event socket information
 						$sql = "select * from v_settings ";
@@ -629,23 +629,6 @@ if (!function_exists('fax_split_dtmf')) {
 					fwrite($fp, $fax_file_name." received on ".$fax_extension." emailed to ".$fax_email." ".$fax_messages."\n");
 					fclose($fp);
 			}
-			else {
-				//create an instruction log to email messages once the connection to the mail server has been restored
-					$fp = fopen($fax_to_email_queue_dir."/failed_fax_emails.log", "a");
-					fwrite($fp, PHP_BINDIR."/php ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/secure/fax_to_email.php email='".$fax_email."' extension=".$fax_extension." name='".$fax_file."' messages='".$fax_messages."' domain=".$domain_name." caller_id_name='".$caller_id_name."' caller_id_number=".$caller_id_number." retry=true\n");
-					fclose($fp);
-				//create a script to do the delayed mailing
-					$fp = fopen($_SESSION['server']['temp']['dir']."/failed_fax_emails.sh", "w");
-					fwrite($fp, "rm ".$_SESSION['server']['temp']['dir']."/fax_email_retry.sh\n");
-					fwrite($fp, "mv ".$fax_to_email_queue_dir."/failed_fax_emails.log ".$_SESSION['server']['temp']['dir']."/fax_email_retry.sh\n");
-					fwrite($fp, "chmod 777 ".$_SESSION['server']['temp']['dir']."/fax_email_retry.sh\n");
-					fwrite($fp, $_SESSION['server']['temp']['dir']."/fax_email_retry.sh\n");
-					fclose($fp);
-					$tmp_response = exec("chmod 777 ".$_SESSION['server']['temp']['dir']."/failed_fax_emails.sh");
-				//note we use batch in order to execute when system load is low.  Alternatively this could be replaced with AT.
-					$tmp_response = exec("at -f ".$_SESSION['server']['temp']['dir']."/failed_fax_emails.sh now + 3 minutes");
-				
-			}
 		}
 	}
 

programming_language: PHP