CVE-2015-10031 (published 2023-01-08T17:15Z)

A vulnerability classified as critical was found in purpleparrots 491-Project. This vulnerability affects unknown code of the file update.php of the component Highscore Handler. The manipulation leads to sql injection. The name of the patch is a812a5e4cf72f2a635a716086fe1ee2b8fa0b1ab. It is recommended to apply a patch to fix this issue. The identifier of this vulnerability is VDB-217648.

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/purpleparrots/491-Project
commit_details: repo_url: https://github.com/purpleparrots/491-Project
author: purpleparrots
author_date: 2015-03-10 22:41:40-07:00
msg: fixed update.php to prevent sql injections because people are douchebags
repository: repo_url: https://github.com/purpleparrots/491-Project
repo_name: purpleparrots/491-Project
repo_language: JavaScript
owner: purpleparrots
file_changes: filename: update.php
change_type: ModificationType.MODIFY
diff: @@ -1,28 +1,33 @@
 <?php
-	$name = $_GET["name"];
-	$score = $_GET["score"];
 	
-	$username = "alpertmd";
-	$password = "yofer`";
-	$hostname = "repos.insttech.washington.edu";
+	if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){
+		$username = "alpertmd";
+		$password = "yofer`";
+		$hostname = "repos.insttech.washington.edu";
 
-	$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
-
-	$selected = mysql_select_db("alpertmd", $dbhandle) or die("Could not select high score db");
+		$dbhandle = mysqli_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
 	
-	$result = mysql_query("SELECT MAX(idHighscores) FROM Highscores");
-	$id = mysql_result($result, 0) + 1;
+		$selected = mysqli_select_db($dbhandle,$username) or die("Could not select high score db");
 	
-	$query = "INSERT INTO Highscores VALUES ($id, '$name', $score)";
-	$result = mysql_query($query);
-		
-	$query = "SELECT idHighscores FROM Highscores WHERE score = (SELECT Min(score) FROM Highscores)";
-	$result = mysql_query($query);
-	$minID = mysql_result($result, 0);
+		$result = mysqli_query($dbhandle, "SELECT MAX(idHighscores) FROM Highscores");
+	
+		$id = mysqli_fetch_row($result)[0] + 1;
+		$name = $_POST["name"];
+		$score = $_POST["score"];
 
+		$query =  mysqli_prepare($dbhandle, "INSERT INTO Highscores Values (?, ?, ?)");
+	
+		mysqli_stmt_bind_param($query, 'isi', $id, $name, $score);
+		mysqli_stmt_execute($query);
+		mysqli_stmt_close($query);
+		
+		$query = "SELECT idHighscores FROM Highscores WHERE score = (SELECT Min(score) FROM Highscores)";
+		$result = mysqli_query($dbhandle, $query);
+		$minID = mysqli_fetch_row($result)[0];
 
-	$query = "DELETE FROM Highscores WHERE idHighscores = $minID";
-	$result = mysql_query($query);
+		$query = "DELETE FROM Highscores WHERE idHighscores = $minID";
+		$result = mysqli_query($dbhandle, $query);
 	
-	mysql_close($dbhandle);
+		mysqli_close($dbhandle);
+	}
 ?>
\ No newline at end of file

programming_language: PHP