CVE-2015-10122: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: A vulnerability was found in wp-donate Plugin up to 1.4 on WordPress. It has been classified as critical. This affects an unknown part of the file includes/donate-display.php. The manipulation leads to sql injection. It is possible to initiate the attack remotely. Upgrading to version 1.5 is able to address this issue. The identifier of the patch is 019114cb788d954c5d1b36d6c62418619e93a757. It is recommended to upgrade the affected component. The identifier VDB-234249 was assigned to this vulnerability.
CWE 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.
CVSS v3 base score: 9.8
Published: 2023-07-18T05:15Z
Repository: https://github.com/wp-plugins/wp-donate
Language: PHP
Files changed: includes/donate-display.php
Commit date: 2015-03-23 09:39:42 +0000
Commit message: made changes in sql query to fix sql injection vulnerabilities by using proper WP query

git-svn-id: https://plugins.svn.wordpress.org/wp-donate/trunk@1118609 b8457f37-d9ea-0310-8a92-e5e31aec5664

Diff: diff --git a/includes/donate-display.php b/includes/donate-display.php
index 7dd6fb4..418fdf0 100644
--- a/includes/donate-display.php
+++ b/includes/donate-display.php
@@ -10,30 +10,30 @@
 	global $wpdb;
     if(isset($_REQUEST['action']))
     {
     if($_REQUEST['action']=='submitdonate')
     {		
-		$first_name = $_REQUEST['first_name'];
-		$last_name = $_REQUEST['last_name'];
-		$organization = $_REQUEST['organization'];
-		$address = $_REQUEST['address'];
-		$city = $_REQUEST['city'];
-		$country = $_REQUEST['country'];
-		$state = $_REQUEST['state'];
-		$zip = $_REQUEST['zip'];
-		$phone = $_REQUEST['phone'];
-		$email = $_REQUEST['email'];		
-		$donation_type = $_REQUEST['donation_type'];
-		$r_frequency = $_REQUEST['r_frequency'];
-		$r_times = $_REQUEST['r_times'];
-		$amount = $_REQUEST['amount'];
-		$card_type = $_REQUEST['card_type'];
-		$x_card_num = $_REQUEST['x_card_num'];
-		$exp_month = $_REQUEST['exp_month'];
-		$exp_year = $_REQUEST['exp_year'];
-		$x_card_code = $_REQUEST['x_card_code'];
-		$comment = $_REQUEST['comment'];
+		$first_name = mysql_real_escape_string($_REQUEST['first_name']);
+		$last_name = mysql_real_escape_string($_REQUEST['last_name']);
+		$organization = mysql_real_escape_string($_REQUEST['organization']);
+		$address = mysql_real_escape_string($_REQUEST['address']);
+		$city = mysql_real_escape_string($_REQUEST['city']);
+		$country = mysql_real_escape_string($_REQUEST['country']);
+		$state = mysql_real_escape_string($_REQUEST['state']);
+		$zip = mysql_real_escape_string($_REQUEST['zip']);
+		$phone = mysql_real_escape_string($_REQUEST['phone']);
+		$email = mysql_real_escape_string($_REQUEST['email']);		
+		$donation_type = mysql_real_escape_string($_REQUEST['donation_type']);
+		$r_frequency = mysql_real_escape_string($_REQUEST['r_frequency']);
+		$r_times = mysql_real_escape_string($_REQUEST['r_times']);
+		$amount = mysql_real_escape_string($_REQUEST['amount']);
+		$card_type = mysql_real_escape_string($_REQUEST['card_type']);
+		$x_card_num = mysql_real_escape_string($_REQUEST['x_card_num']);
+		$exp_month = mysql_real_escape_string($_REQUEST['exp_month']);
+		$exp_year = mysql_real_escape_string($_REQUEST['exp_year']);
+		$x_card_code = mysql_real_escape_string($_REQUEST['x_card_code']);
+		$comment = mysql_real_escape_string($_REQUEST['comment']);
 		$payment_method = $_REQUEST['payment_method'];
 		
 		// Adjust this to point to the Authorize.Net PHP SDK
 		include dirname(__FILE__) .'/../anet_php_sdk/AuthorizeNet.php';
 
@@ -54,13 +54,36 @@
 		define("AUTHORIZENET_MD5_SETTING","");                // Add your MD5 Setting.
 
 		$REQUEST = $_REQUEST;
 		if($paypalp = authorizepayment($METHOD_TO_USE,$REQUEST,$address1,$city,$state,$country,$zipcode,$emailaddress,$plan))
 		{
-			$sql = "INSERT INTO `".$wpdb->prefix."donate` (`first_name`, `last_name`, `organization`, `address`, `city`, `country`, `state`, `zip`, `phone`, `email`, `donation_type`, `amount`, `comment`, `status`,`date`) 
-			VALUES ('".$first_name."', '".$last_name."','".$organization."','".$address."','".$city."','".$country."','".$state."','".$zip."','".$phone."','".$email."','".$donation_type."','".$amount."','".$comment."', '1',now());";
-			$wpdb->query($sql);
+			
+                        
+				$q_status = "1";
+				$wpdb->query(
+						$wpdb->prepare("
+							INSERT INTO `".$wpdb->prefix."donate`
+							(`first_name`, `last_name`, `organization`, `address`, `city`, `country`, `state`, `zip`, `phone`, `email`, `donation_type`, `amount`, `comment`, `status`,`date`) 
+							VALUES ( %s, %s, %s, %s,%s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s  )
+						", 
+						$first_name, 
+						$last_name, 
+						$organization,
+						$address,
+						$city,
+						$country,
+						$state,
+						$zip,
+						$phone,
+						$email,
+						$donation_type,
+						$amount,
+						$comment,
+						$q_status,
+						date('Y-m-d H:i:s')
+					)
+				);
 			
 			$post = get_post($post->ID);
 			$slug = $post->post_name;
 			
 			header("Location:".site_url().$_SERVER['REQUEST_URI']);

Vulnerable code: 		$first_name = $_REQUEST['first_name'];
		$last_name = $_REQUEST['last_name'];
		$organization = $_REQUEST['organization'];
		$address = $_REQUEST['address'];
		$city = $_REQUEST['city'];
		$country = $_REQUEST['country'];
		$state = $_REQUEST['state'];
		$zip = $_REQUEST['zip'];
		$phone = $_REQUEST['phone'];
		$email = $_REQUEST['email'];		
		$donation_type = $_REQUEST['donation_type'];
		$r_frequency = $_REQUEST['r_frequency'];
		$r_times = $_REQUEST['r_times'];
		$amount = $_REQUEST['amount'];
		$card_type = $_REQUEST['card_type'];
		$x_card_num = $_REQUEST['x_card_num'];
		$exp_month = $_REQUEST['exp_month'];
		$exp_year = $_REQUEST['exp_year'];
		$x_card_code = $_REQUEST['x_card_code'];
		$comment = $_REQUEST['comment'];
			$sql = "INSERT INTO `".$wpdb->prefix."donate` (`first_name`, `last_name`, `organization`, `address`, `city`, `country`, `state`, `zip`, `phone`, `email`, `donation_type`, `amount`, `comment`, `status`,`date`) 
			VALUES ('".$first_name."', '".$last_name."','".$organization."','".$address."','".$city."','".$country."','".$state."','".$zip."','".$phone."','".$email."','".$donation_type."','".$amount."','".$comment."', '1',now());";
			$wpdb->query($sql);
Fixed code: 		$first_name = mysql_real_escape_string($_REQUEST['first_name']);
		$last_name = mysql_real_escape_string($_REQUEST['last_name']);
		$organization = mysql_real_escape_string($_REQUEST['organization']);
		$address = mysql_real_escape_string($_REQUEST['address']);
		$city = mysql_real_escape_string($_REQUEST['city']);
		$country = mysql_real_escape_string($_REQUEST['country']);
		$state = mysql_real_escape_string($_REQUEST['state']);
		$zip = mysql_real_escape_string($_REQUEST['zip']);
		$phone = mysql_real_escape_string($_REQUEST['phone']);
		$email = mysql_real_escape_string($_REQUEST['email']);		
		$donation_type = mysql_real_escape_string($_REQUEST['donation_type']);
		$r_frequency = mysql_real_escape_string($_REQUEST['r_frequency']);
		$r_times = mysql_real_escape_string($_REQUEST['r_times']);
		$amount = mysql_real_escape_string($_REQUEST['amount']);
		$card_type = mysql_real_escape_string($_REQUEST['card_type']);
		$x_card_num = mysql_real_escape_string($_REQUEST['x_card_num']);
		$exp_month = mysql_real_escape_string($_REQUEST['exp_month']);
		$exp_year = mysql_real_escape_string($_REQUEST['exp_year']);
		$x_card_code = mysql_real_escape_string($_REQUEST['x_card_code']);
		$comment = mysql_real_escape_string($_REQUEST['comment']);
			
                        
				$q_status = "1";
				$wpdb->query(
						$wpdb->prepare("
							INSERT INTO `".$wpdb->prefix."donate`
							(`first_name`, `last_name`, `organization`, `address`, `city`, `country`, `state`, `zip`, `phone`, `email`, `donation_type`, `amount`, `comment`, `status`,`date`) 
							VALUES ( %s, %s, %s, %s,%s, %s, %s, %s,%s, %s, %s, %s, %s,%s,%s  )
						", 
						$first_name, 
						$last_name, 
						$organization,
						$address,
						$city,
						$country,
						$state,
						$zip,
						$phone,
						$email,
						$donation_type,
						$amount,
						$comment,
						$q_status,
						date('Y-m-d H:i:s')
					)
				);