CVE-2017-1000214 (published 2017-11-27T14:29Z)

GitPHP by xiphux is vulnerable to OS Command Injections

Severity: HIGH
CVSS v2 base score: 10.0 (AV:N/AC:L/Au:N/C:C/I:C/A:C)
CVSS v3 base score: 9.8, CRITICAL (CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-78
cwe_name: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
description: The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.
extended_description: 
		   This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications. Alternately, if the weakness occurs in a privileged program, it could allow the attacker to specify commands that normally would not be accessible, or to call alternate commands with privileges that the attacker does not have. The problem is exacerbated if the compromised process does not follow the principle of least privilege, because the attacker-controlled commands may run with special system privileges that increases the amount of damage.
            There are at least two subtypes of OS command injection:
               
				 The application intends to execute a single, fixed program that is under its own control. It intends to use externally-supplied inputs as arguments to that program. For example, the program might use system("nslookup [HOSTNAME]") to run nslookup and allow the user to supply a HOSTNAME, which is used as an argument. Attackers cannot prevent nslookup from executing. However, if the program does not remove command separators from the HOSTNAME argument, attackers could place the separators into the arguments, which allows them to execute their own program after nslookup has finished executing.
				 The application accepts an input that it uses to fully select which program to run, as well as which commands to use. The application simply redirects this entire command to the operating system. For example, the program might use "exec([COMMAND])" to execute the [COMMAND] that was supplied by the user. If the COMMAND is under attacker control, then the attacker can execute arbitrary commands or programs. If the command is being executed using functions like exec() and CreateProcess(), the attacker might not be able to combine multiple commands together in the same line.
               
            From a weakness standpoint, these variants represent distinct programmer errors. In the first variant, the programmer clearly intends that input from untrusted parties will be part of the arguments in the command to be executed. In the second variant, the programmer does not intend for the command to be accessible to any untrusted party, but the programmer probably has not accounted for alternate ways in which malicious attackers can provide input.
         
         

Fix information:
repo_url: https://github.com/Enalean/gitphp
commit_details: repo_url: https://github.com/Enalean/gitphp
author: Thomas Gerbet
author_date: 2017-07-07 14:11:47+02:00
msg: Fix shell injections

No dynamic parameters should be passed shell_exec() without
being properly escaped
repository: repo_url: https://github.com/Enalean/gitphp
repo_name: Enalean/gitphp
description: A web based git repository browser written in PHP
repo_language: PHP
owner: Enalean
file_changes: filename: Controller_GraphData.class.php
change_type: ModificationType.MODIFY
diff: @@ -76,7 +76,7 @@ class GitPHP_Controller_GraphData extends GitPHP_ControllerBase
 
 			$data = array();
 
-			$commits = explode("\n", $this->exe->Execute($this->GetProject()->GetPath(), 'rev-list', array('--format=format:"%H %ct"', $head->GetHash())));
+			$commits = explode("\n", $this->exe->Execute($this->GetProject()->GetPath(), 'rev-list', array('--format=format:"%H %ct"', escapeshellarg($head->GetHash()))));
 			foreach ($commits as $commit) {
 				if (preg_match('/^([0-9a-fA-F]{40}) ([0-9]+)$/', $commit, $regs)) {
 					$data[] = array('CommitEpoch' => (int)$regs[2]);
@@ -90,7 +90,7 @@ class GitPHP_Controller_GraphData extends GitPHP_ControllerBase
 			include_once(GITPHP_GESHIDIR . "geshi.php");
 			$geshi = new GeSHi("",'php');
 
-			$files = explode("\n", $this->exe->Execute($this->GetProject()->GetPath(), 'ls-tree', array('-r', '--name-only', $head->GetTree()->GetHash())));
+			$files = explode("\n", $this->exe->Execute($this->GetProject()->GetPath(), 'ls-tree', array('-r', '--name-only', escapeshellarg($head->GetTree()->GetHash()))));
 			foreach ($files as $file) {
 				$filename = GitPHP_Util::BaseName($file);
 				$lang = GitPHP_Util::GeshiFilenameToLanguage($filename);

programming_language: PHP
filename: FileBlame.class.php
change_type: ModificationType.MODIFY
diff: @@ -141,9 +141,9 @@ class GitPHP_FileBlame
 		$args = array();
 		$args[] = '-s';
 		$args[] = '-l';
-		$args[] = $this->commitHash;
+		$args[] = escapeshellarg($this->commitHash);
 		$args[] = '--';
-		$args[] = $this->path;
+		$args[] = escapeshellarg($this->path);
 
 		$blamelines = explode("\n", $this->exe->Execute($this->project->GetPath(), GIT_BLAME, $args));
 

programming_language: PHP
filename: FileHistory.class.php
change_type: ModificationType.MODIFY
diff: @@ -265,19 +265,19 @@ class GitPHP_FileHistory implements Iterator, GitPHP_Pagination_Interface
 
 		if ($canSkip) {
 			if ($this->limit > 0) {
-				$args[] = '--max-count=' . $this->limit;
+				$args[] = '--max-count=' . escapeshellarg($this->limit);
 			}
 			if ($this->skip > 0) {
-				$args[] = '--skip=' . $this->skip;
+				$args[] = '--skip=' . escapeshellarg($this->skip);
 			}
 		} else {
 			if ($this->limit > 0) {
-				$args[] = '--max-count=' . ($this->limit + $this->skip);
+				$args[] = '--max-count=' . escapeshellarg($this->limit + $this->skip);
 			}
 		}
 
 		$args[] = '--';
-		$args[] = $this->path;
+		$args[] = escapeshellarg($this->path);
 		$args[] = '|';
 		$args[] = $this->exe->GetBinary();
 		$args[] = '--git-dir=' . escapeshellarg($this->project->GetPath());
@@ -285,7 +285,7 @@ class GitPHP_FileHistory implements Iterator, GitPHP_Pagination_Interface
 		$args[] = '-r';
 		$args[] = '--stdin';
 		$args[] = '--';
-		$args[] = $this->path;
+		$args[] = escapeshellarg($this->path);
 		
 		$historylines = explode("\n", $this->exe->Execute($this->project->GetPath(), GIT_REV_LIST, $args));
 

programming_language: PHP
filename: FileSearch.class.php
change_type: ModificationType.MODIFY
diff: @@ -382,8 +382,8 @@ class GitPHP_FileSearch implements Iterator, GitPHP_Pagination_Interface
 		$args[] = '--ignore-case';
 		$args[] = '-n';
 		$args[] = '-e';
-		$args[] = '"' . addslashes($this->search) . '"';
-		$args[] = $this->treeHash;
+		$args[] = escapeshellarg($this->search);
+		$args[] = escapeshellarg($this->treeHash);
 
 		$lines = explode("\n", $this->exe->Execute($this->project->GetPath(), GIT_GREP, $args));
 

programming_language: PHP
filename: TreeDiff.class.php
change_type: ModificationType.MODIFY
diff: @@ -121,9 +121,9 @@ class GitPHP_TreeDiff implements Iterator
 		if (empty($this->fromHash))
 			$args[] = '--root';
 		else
-			$args[] = $this->fromHash;
+			$args[] = escapeshellarg($this->fromHash);
 
-		$args[] = $this->toHash;
+		$args[] = escapeshellarg($this->toHash);
 
 		$diffTreeLines = explode("\n", $this->exe->Execute($this->GetProject()->GetPath(), GIT_DIFF_TREE, $args));
 		foreach ($diffTreeLines as $line) {

programming_language: PHP
filename: BlobLoad_Base.class.php
change_type: ModificationType.MODIFY
diff: @@ -42,7 +42,7 @@ abstract class GitPHP_BlobLoad_Base implements GitPHP_BlobLoadStrategy_Interface
 
 		$args = array();
 		$args[] = '-s';
-		$args[] = $blob->GetHash();
+		$args[] = escapeshellarg($blob->GetHash());
 
 		return $this->exe->Execute($blob->GetProject()->GetPath(), GIT_CAT_FILE, $args);
 	}

programming_language: PHP
filename: CommitLoad_Base.class.php
change_type: ModificationType.MODIFY
diff: @@ -42,7 +42,7 @@ abstract class GitPHP_CommitLoad_Base implements GitPHP_CommitLoadStrategy_Inter
 
 		$args = array();
 		$args[] = '--tags';
-		$args[] = $commit->GetHash();
+		$args[] = escapeshellarg($commit->GetHash());
 		$revs = explode("\n", $this->exe->Execute($commit->GetProject()->GetPath(), GIT_NAME_REV, $args));
 
 		foreach ($revs as $revline) {

programming_language: PHP
filename: ProjectLoad_Git.class.php
change_type: ModificationType.MODIFY
diff: @@ -89,7 +89,7 @@ class GitPHP_ProjectLoad_Git implements GitPHP_ProjectLoadStrategy_Interface
 		$args = array();
 		$args[] = '-1';
 		$args[] = '--format=format:%H';
-		$args[] = $abbrevHash;
+		$args[] = escapeshellarg($abbrevHash);
 
 		$fullData = explode("\n", $this->exe->Execute($project->GetPath(), GIT_REV_LIST, $args));
 		if (empty($fullData[0])) {
@@ -125,7 +125,7 @@ class GitPHP_ProjectLoad_Git implements GitPHP_ProjectLoadStrategy_Interface
 		$args = array();
 		$args[] = '-1';
 		$args[] = '--format=format:%h';
-		$args[] = $hash;
+		$args[] = escapeshellarg($hash);
 
 		$abbrevData = explode("\n", $this->exe->Execute($project->GetPath(), GIT_REV_LIST, $args));
 		if (empty($abbrevData[0])) {

programming_language: PHP
filename: RefListLoad_Git.class.php
change_type: ModificationType.MODIFY
diff: @@ -45,7 +45,7 @@ abstract class GitPHP_RefListLoad_Git
 			return;
 
 		$args = array();
-		$args[] = '--' . $type;
+		$args[] = '--' . escapeshellarg($type);
 		$args[] = '--dereference';
 		$ret = $this->exe->Execute($refList->GetProject()->GetPath(), GIT_SHOW_REF, $args);
 
@@ -86,17 +86,17 @@ abstract class GitPHP_RefListLoad_Git
 			return null;
 
 		$args = array();
-		$args[] = '--sort=' . $order;
+		$args[] = '--sort=' . escapeshellarg($order);
 		$args[] = '--format="%(refname)"';
 		if ($count > 0) {
 			if ($skip > 0) {
-				$args[] = '--count=' . ($count + $skip);
+				$args[] = '--count=' . escapeshellarg($count + $skip);
 			} else {
-				$args[] = '--count=' . $count;
+				$args[] = '--count=' . escapeshellarg($count);
 			}
 		}
 		$args[] = '--';
-		$args[] = 'refs/' . $type;
+		$args[] = escapeshellarg('refs/' . $type);
 		$ret = $this->exe->Execute($refList->GetProject()->GetPath(), GIT_FOR_EACH_REF, $args);
 
 		$lines = explode("\n", $ret);

programming_language: PHP
filename: RevList_Git.class.php
change_type: ModificationType.MODIFY
diff: @@ -52,14 +52,14 @@ class GitPHP_RevList_Git
 
 		if ($canSkip) {
 			if ($count > 0) {
-				$extraargs[] = '--max-count=' . $count;
+				$extraargs[] = '--max-count=' . escapeshellarg($count);
 			}
 			if ($skip > 0) {
-				$extraargs[] = '--skip=' . $skip;
+				$extraargs[] = '--skip=' . escapeshellarg($skip);
 			}
 		} else {
 			if ($count > 0) {
-				$extraargs[] = '--max-count=' . ($count + $skip);
+				$extraargs[] = '--max-count=' . escapeshellarg($count + $skip);
 			}
 		}
 

programming_language: PHP
filename: TagLoad_Git.class.php
change_type: ModificationType.MODIFY
diff: @@ -112,7 +112,7 @@ class GitPHP_TagLoad_Git implements GitPHP_TagLoadStrategy_Interface
 			case 'tag':
 				$args = array();
 				$args[] = 'tag';
-				$args[] = $objectHash;
+				$args[] = escapeshellarg($objectHash);
 				$ret = $this->exe->Execute($tag->GetProject()->GetPath(), GIT_CAT_FILE, $args);
 				$lines = explode("\n", $ret);
 				foreach ($lines as $i => $line) {

programming_language: PHP
filename: TreeLoad_Base.class.php
change_type: ModificationType.MODIFY
diff: @@ -47,7 +47,7 @@ abstract class GitPHP_TreeLoad_Base implements GitPHP_TreeLoadStrategy_Interface
 		$args[] = '--full-name';
 		$args[] = '-r';
 		$args[] = '-t';
-		$args[] = $tree->GetHash();
+		$args[] = escapeshellarg($tree->GetHash());
 
 		$lines = explode("\n", $this->exe->Execute($tree->GetProject()->GetPath(), GIT_LS_TREE, $args));
 

programming_language: PHP
filename: TreeLoad_Git.class.php
change_type: ModificationType.MODIFY
diff: @@ -29,7 +29,7 @@ class GitPHP_TreeLoad_Git extends GitPHP_TreeLoad_Base
 		if ($this->exe->CanShowSizeInTree())
 			$args[] = '-l';
 		$args[] = '-t';
-		$args[] = $tree->GetHash();
+		$args[] = escapeshellarg($tree->GetHash());
 		
 		$lines = explode("\n", $this->exe->Execute($tree->GetProject()->GetPath(), GIT_LS_TREE, $args));
 

programming_language: PHP