CVE-2015-10106: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: ** UNSUPPORTED WHEN ASSIGNED ** A vulnerability classified as critical was found in mback2k mh_httpbl Extension up to 1.1.7 on TYPO3. This vulnerability affects the function moduleContent of the file mod1/index.php. The manipulation leads to sql injection. The attack can be initiated remotely. Upgrading to version 1.1.8 is able to address this issue. The patch is identified as 429f50f4e4795b20dae06735b41fb94f010722bf. It is recommended to upgrade the affected component. VDB-230086 is the identifier assigned to this vulnerability. NOTE: This vulnerability only affects products that are no longer supported by the maintainer.
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: 8.8
Published: 2023-05-28T13:15Z
Repository: https://github.com/mback2k/mh_httpbl
Language: PHP
Files changed: mod1/index.php
Commit date: 2015-12-15 16:12:50 +0100
Commit message: Fix TYPO3-EXT-SA-2015-021: SQL Injection

Handle all user-input which is passed as WHERE or ORDER statement to
exec_SELECTquery using fullQuoteStr or explicit value checks.
Diff: diff --git a/mod1/index.php b/mod1/index.php
index cde4997..a35dad0 100644
--- a/mod1/index.php
+++ b/mod1/index.php
@@ -202,16 +202,18 @@ class tx_mhhttpbl_module1 extends t3lib_SCbase {
 							<td valign="top" align="right" class="c-headLineTable"><b>'.$LANG->getLL('move_whitelist').' &amp; '.$LANG->getLL('delete').'</b></td>
 						</tr>
 				';
 
 				if (t3lib_div::_GP('block_ip')) {
-					$where = "block_ip = '". t3lib_div::_GP('block_ip') ."'";
+					$where = 'block_ip = '. $GLOBALS['TYPO3_DB']->fullQuoteStr(t3lib_div::_GP('block_ip'), 'tx_mhhttpbl_blocklog');
 				} else {
 					$where = '';
 				}
 				if (t3lib_div::_GP('sort') && t3lib_div::_GP('order')) {
-					$order = t3lib_div::_GP('sort').' '.strtoupper(t3lib_div::_GP('order'));
+					$sort_param = in_array(t3lib_div::_GP('sort'), array('tstamp', 'block_ip', 'block_type', 'block_score')) ? t3lib_div::_GP('sort') : 'tstamp';
+					$order_param = strtoupper(t3lib_div::_GP('order')) == 'ASC' ? 'ASC' : 'DESC';
+					$order = $sort_param.' '.$order_param;
 				} else {
 					$order = 'tstamp DESC';
 				}
 				$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_mhhttpbl_blocklog', $where, '', $order);
 				if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
@@ -238,11 +240,12 @@ class tx_mhhttpbl_module1 extends t3lib_SCbase {
 
 				$this->content.=$this->doc->section($LANG->getLL('function1'),$content,0,1);
 			break;
 			case 2:
 				if (t3lib_div::_GP('whitelist_add')) {
-					$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_mhhttpbl_whitelist', array('cruser_id'=>$BE_USER->user['uid'], 'crdate'=>time(), 'tstamp'=>time(), 'whitelist_ip'=>implode('.', t3lib_div::_GP('whitelist_ip'))));
+					$whitelist_ip = implode('.', array_map('intval', t3lib_div::_GP('whitelist_ip')));
+					$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_mhhttpbl_whitelist', array('cruser_id'=>$BE_USER->user['uid'], 'crdate'=>time(), 'tstamp'=>time(), 'whitelist_ip'=>$whitelist_ip));
 				} else if (t3lib_div::_GP('delete')) {
 					$GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_mhhttpbl_whitelist', 'uid = '.intval(t3lib_div::_GP('delete')));
 				}
 
 				$content = '
@@ -273,11 +276,13 @@ class tx_mhhttpbl_module1 extends t3lib_SCbase {
 							<td valign="top" align="right" class="c-headLineTable"><b>'.$LANG->getLL('delete').'</b></td>
 						</tr>
 				';
 
 				if (t3lib_div::_GP('sort') && t3lib_div::_GP('order')) {
-					$order = t3lib_div::_GP('sort').' '.strtoupper(t3lib_div::_GP('order'));
+					$sort_param = in_array(t3lib_div::_GP('sort'), array('tstamp', 'whitelist_ip')) ? t3lib_div::_GP('sort') : 'tstamp';
+					$order_param = strtoupper(t3lib_div::_GP('order')) == 'ASC' ? 'ASC' : 'DESC';
+					$order = $sort_param.' '.$order_param;
 				} else {
 					$order = 'tstamp DESC';
 				}
 				$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tx_mhhttpbl_whitelist', '', '', $order);
 				if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
@@ -310,11 +315,13 @@ class tx_mhhttpbl_module1 extends t3lib_SCbase {
 							<td valign="top" class="c-headLineTable"><b>'.$LANG->getLL('count').' <a href="?sort=count&amp;order=asc">&uArr;</a><a href="?sort=count&amp;order=desc">&dArr;</a></b></td>
 						</tr>
 				';
 
 				if (t3lib_div::_GP('sort') && t3lib_div::_GP('order')) {
-					$order = t3lib_div::_GP('sort').' '.strtoupper(t3lib_div::_GP('order'));
+					$sort_param = in_array(t3lib_div::_GP('sort'), array('block_ip', 'count')) ? t3lib_div::_GP('sort') : 'count';
+					$order_param = strtoupper(t3lib_div::_GP('order')) == 'ASC' ? 'ASC' : 'DESC';
+					$order = $sort_param.' '.$order_param;
 				} else {
 					$order = 'count DESC';
 				}
 				$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('block_ip, COUNT(block_ip) as count', 'tx_mhhttpbl_blocklog', '', 'block_ip', $order);
 				if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {

Vulnerable code: 					$where = "block_ip = '". t3lib_div::_GP('block_ip') ."'";
					$order = t3lib_div::_GP('sort').' '.strtoupper(t3lib_div::_GP('order'));
					$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_mhhttpbl_whitelist', array('cruser_id'=>$BE_USER->user['uid'], 'crdate'=>time(), 'tstamp'=>time(), 'whitelist_ip'=>implode('.', t3lib_div::_GP('whitelist_ip'))));
					$order = t3lib_div::_GP('sort').' '.strtoupper(t3lib_div::_GP('order'));
					$order = t3lib_div::_GP('sort').' '.strtoupper(t3lib_div::_GP('order'));
Fixed code: 					$where = 'block_ip = '. $GLOBALS['TYPO3_DB']->fullQuoteStr(t3lib_div::_GP('block_ip'), 'tx_mhhttpbl_blocklog');
					$sort_param = in_array(t3lib_div::_GP('sort'), array('tstamp', 'block_ip', 'block_type', 'block_score')) ? t3lib_div::_GP('sort') : 'tstamp';
					$order_param = strtoupper(t3lib_div::_GP('order')) == 'ASC' ? 'ASC' : 'DESC';
					$order = $sort_param.' '.$order_param;
					$whitelist_ip = implode('.', array_map('intval', t3lib_div::_GP('whitelist_ip')));
					$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_mhhttpbl_whitelist', array('cruser_id'=>$BE_USER->user['uid'], 'crdate'=>time(), 'tstamp'=>time(), 'whitelist_ip'=>$whitelist_ip));
					$sort_param = in_array(t3lib_div::_GP('sort'), array('tstamp', 'whitelist_ip')) ? t3lib_div::_GP('sort') : 'tstamp';
					$order_param = strtoupper(t3lib_div::_GP('order')) == 'ASC' ? 'ASC' : 'DESC';
					$order = $sort_param.' '.$order_param;
					$sort_param = in_array(t3lib_div::_GP('sort'), array('block_ip', 'count')) ? t3lib_div::_GP('sort') : 'count';
					$order_param = strtoupper(t3lib_div::_GP('order')) == 'ASC' ? 'ASC' : 'DESC';
					$order = $sort_param.' '.$order_param;