CVE-2014-125062: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: A vulnerability classified as critical was found in ananich bitstorm. Affected by this vulnerability is an unknown functionality of the file announce.php. The manipulation of the argument event leads to sql injection. The identifier of the patch is ea8da92f94cdb78ee7831e1f7af6258473ab396a. It is recommended to apply a patch to fix this issue. The identifier VDB-217621 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-01-07T17:15Z
Repository: https://github.com/ananich/bitstorm
Language: PHP
Files changed: announce.php
Commit date: 2014-12-15 01:32:16 +0300
Commit message: FIX: SQL Injection
Diff: diff --git a/announce.php b/announce.php
index 20b1dc0..1a598cc 100644
--- a/announce.php
+++ b/announce.php
@@ -106,16 +106,16 @@ if (!isset($_GET['left'])) {
 }
 
 $state = 'state';
 $attempt = 'attempt';
 if (isset($_GET['event'])){
-	$state = "'" . $_GET['event'] . "'";
+	$state = "'" . mysql_real_escape_string($_GET['event']) . "'";
 	$attempt = 'LAST_INSERT_ID(peer_torrent.id)';
 }
 
-mysql_query('INSERT INTO peer_torrent (peer_id, torrent_id, uploaded, downloaded, `left`, state, attempt, `last_updated`) '
-	. 'SELECT ' . $pk_peer . ', `torrent`.`id`, ' . intval($_GET['uploaded']) . ', ' . intval($_GET['downloaded']) . ', ' . intval($_GET['left']) . ', ' . $state .  ', ' . 0 . ', UTC_TIMESTAMP() '
+mysql_query('INSERT INTO peer_torrent (peer_id, torrent_id, uploaded, downloaded, `left`, attempt, `last_updated`) '
+	. 'SELECT ' . $pk_peer . ', `torrent`.`id`, ' . intval($_GET['uploaded']) . ', ' . intval($_GET['downloaded']) . ', ' . intval($_GET['left']) . ', ' . 0 . ', UTC_TIMESTAMP() '
 	. 'FROM `torrent` '
 	. "WHERE `torrent`.`hash` = '" . mysql_real_escape_string(bin2hex($_GET['info_hash'])) . "' "
 	. 'ON DUPLICATE KEY UPDATE `uploaded` = VALUES(`uploaded`), `downloaded` = VALUES(`downloaded`), `left` = VALUES(`left`), ' 
 	. 'state=' . $state . ', attempt=' . $attempt . ', ' 
 	. 'last_updated = VALUES(`last_updated`), ')

Vulnerable code: 	$state = "'" . $_GET['event'] . "'";
mysql_query('INSERT INTO peer_torrent (peer_id, torrent_id, uploaded, downloaded, `left`, state, attempt, `last_updated`) '
	. 'SELECT ' . $pk_peer . ', `torrent`.`id`, ' . intval($_GET['uploaded']) . ', ' . intval($_GET['downloaded']) . ', ' . intval($_GET['left']) . ', ' . $state .  ', ' . 0 . ', UTC_TIMESTAMP() '
Fixed code: 	$state = "'" . mysql_real_escape_string($_GET['event']) . "'";
mysql_query('INSERT INTO peer_torrent (peer_id, torrent_id, uploaded, downloaded, `left`, attempt, `last_updated`) '
	. 'SELECT ' . $pk_peer . ', `torrent`.`id`, ' . intval($_GET['uploaded']) . ', ' . intval($_GET['downloaded']) . ', ' . intval($_GET['left']) . ', ' . 0 . ', UTC_TIMESTAMP() '