CVE-2015-10009: Improper Control of Generation of Code ('Code Injection') (CWE-94)
value: A vulnerability was found in nterchange up to 4.1.0. It has been rated as critical. This issue affects the function getContent of the file app/controllers/code_caller_controller.php. The manipulation of the argument q with the input %5C%27%29;phpinfo%28%29;/* leads to code injection. The exploit has been disclosed to the public and may be used. Upgrading to version 4.1.1 is able to address this issue. The patch is named fba7d89176fba8fe289edd58835fe45080797d99. It is recommended to upgrade the affected component. The associated identifier of this vulnerability is VDB-217187.
CWE description: The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
CVSS v3 base score: 9.8
Published: 2023-01-02T16:15Z
Repository: https://github.com/nonfiction/nterchange_backend
Language: PHP
Files changed: app/controllers/code_caller_controller.php
Commit date: 2015-04-21 22:25:40 -0600
Commit message: Addressing TLM vulnerability

A certain special escape sequence causes dynamic code callers to
execute arbitrary code.

    ?q=%5C%27%29;phpinfo%28%29;/*

Diff: diff --git a/app/controllers/code_caller_controller.php b/app/controllers/code_caller_controller.php
index daf9992..ca40239 100644
--- a/app/controllers/code_caller_controller.php
+++ b/app/controllers/code_caller_controller.php
@@ -84,16 +84,20 @@ class CodeCallerController extends AssetController {
 	}
 
 	function dynamicPHP(&$obj, $method, $include_file, $params=array()) {
 		$ret = '';
 		if (is_object($obj) && method_exists($obj, $method)) {
-			$ret .= "<?php\n" .
-				'include_once \'' . $include_file . '\';' . "\n" .
-				'$obj = unserialize(\'' . str_replace('\'', '\\\'', serialize($obj)) . '\');' . "\n" .
-				'$params = unserialize(\'' . str_replace('\'', '\\\'', serialize($params)) . '\');' . "\n" .
-				'print $obj->' . $method . '($params);' . "\n" .
-				"?>\n";
+			$ret .= '<?php include_once \'' . $include_file . '\';';
+			$ret .= '$obj = '    . $this->wrapSanitizedSerializer($obj)   . ';';
+			$ret .= '$params = ' . $this->wrapSanitizedSerializer($param) . ';';
+			$ret .= 'print $obj->' . $method . '($params);';
+			$ret .= '?>';
 		}
 		return $ret;
 	}
+
+	private function wrapSanitizedSerializer($obj) {
+		$encoded_serialized_string = base64_encode(serialize($obj));
+		return "unserialize(base64_decode('$encoded_serialized_string'))";
+	}
 }
 ?>

Vulnerable code: 			$ret .= "<?php\n" .
				'include_once \'' . $include_file . '\';' . "\n" .
				'$obj = unserialize(\'' . str_replace('\'', '\\\'', serialize($obj)) . '\');' . "\n" .
				'$params = unserialize(\'' . str_replace('\'', '\\\'', serialize($params)) . '\');' . "\n" .
				'print $obj->' . $method . '($params);' . "\n" .
				"?>\n";
Fixed code: 			$ret .= '<?php include_once \'' . $include_file . '\';';
			$ret .= '$obj = '    . $this->wrapSanitizedSerializer($obj)   . ';';
			$ret .= '$params = ' . $this->wrapSanitizedSerializer($param) . ';';
			$ret .= 'print $obj->' . $method . '($params);';
			$ret .= '?>';

	private function wrapSanitizedSerializer($obj) {
		$encoded_serialized_string = base64_encode(serialize($obj));
		return "unserialize(base64_decode('$encoded_serialized_string'))";
	}