CVE-2016-15031: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: A vulnerability was found in PHP-Login 1.0. It has been declared as critical. This vulnerability affects the function checkLogin of the file login/scripts/class.loginscript.php of the component POST Parameter Handler. The manipulation of the argument myusername leads to sql injection. The attack can be initiated remotely. Upgrading to version 2.0 is able to address this issue. The patch is identified as 0083ec652786ddbb81335ea20da590df40035679. It is recommended to upgrade the affected component. VDB-228022 is the identifier 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-05-06T01:15Z
Repository: https://github.com/ipoelnet/php-login
Language: PHP
Files changed: login/scripts/class.loginscript.php
Commit date: 2016-01-10 02:14:32 +0100
Commit message: Added sqlInjection prevention.
The login form parameter username was vulnerable.
SQLMap output:
---------------------
POST parameter 'myusername' is vulnerable.
sqlmap identified the following injection point(s) with a total of 910 HTTP(s) requests:
---
Parameter: myusername (POST)
Type: boolean-based blind
Title: MySQL RLIKE boolean-based blind - WHERE, HAVING, ORDER BY or GROUP BY clause
Payload: myusername=uoev' RLIKE (SELECT (CASE WHEN (6566=6566) THEN 0x756f6576 ELSE 0x28 END)) AND 'cyMw'='cyMw&mypassword=&Submit=TzWk
---------------------

added prepared statement to prevent sql injection

Diff: diff --git a/login/scripts/class.loginscript.php b/login/scripts/class.loginscript.php
index 7062f3f..1311d53 100644
--- a/login/scripts/class.loginscript.php
+++ b/login/scripts/class.loginscript.php
@@ -26,10 +26,12 @@ class selectEmail extends dbConn {
 			$eerr = "Error: " . $e->getMessage();
 		}
 
 		//Queries database
 		$estmt = $edb->conn->query("SELECT email, username FROM $tbl_name WHERE id = '$id'");
+            //http://www.w3schools.com/php/php_mysql_prepared_statements.asp
+        
 
 		$eresult = $estmt->fetch(PDO::FETCH_ASSOC);
 
 		return $eresult;
 
@@ -50,11 +52,15 @@ class loginForm extends dbConn {
 
 		catch (PDOException $e) {
 			$err = "Error: " . $e->getMessage();
 		}
 
-		$stmt = $stmt = $db->conn->query("SELECT * FROM $tbl_name WHERE username='$myusername'");
+		$stmt = $stmt = $db->conn->prepare("SELECT * FROM $tbl_name WHERE username= :myusername");
+        $stmt->bindParm(':myusername', $myusrname);
+        $myusrname = $myusername;
+        stmt->execute();
+        
 
 		// Gets query result
 		$result = $stmt->fetch(PDO::FETCH_ASSOC);
 
 	// Checks password entered against db password hash

Vulnerable code: 		$stmt = $stmt = $db->conn->query("SELECT * FROM $tbl_name WHERE username='$myusername'");
Fixed code:             //http://www.w3schools.com/php/php_mysql_prepared_statements.asp
        
		$stmt = $stmt = $db->conn->prepare("SELECT * FROM $tbl_name WHERE username= :myusername");
        $stmt->bindParm(':myusername', $myusrname);
        $myusrname = $myusername;
        stmt->execute();