CVE-2015-7698 (PHP, published 2015-10-21T18:59Z)
Description: value: icewind1991 SMB before 1.0.3 allows remote authenticated users to execute arbitrary SMB commands via shell metacharacters in the user argument in the (1) listShares function in Server.php or the (2) connect or (3) read function in Share.php.
Severity: HIGH (CVSS v3 base score: )
Weakness: CWE-78 \u2014 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
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.
Repository: https://github.com/icewind1991/SMB
Files changed:
src/NativeServer.php
src/NativeShare.php
src/Server.php
src/Share.php
Commit message: improve support for workgroups/domains


Vulnerable code:
		$user = $this->getUser();
		$workgroup = null;
		if (strpos($user, '/')) {
			list($workgroup, $user) = explode('/', $user);
		}
		$this->state->init($workgroup, $user, $this->getPassword());
		$user = $this->server->getUser();
		if (strpos($user, '/')) {
			list($workgroup, $user) = explode('/', $user);
		} elseif (strpos($user, '\\')) {
			list($workgroup, $user) = explode('\\', $user);
		} else {
			$workgroup = null;
		}
		$this->state->init($workgroup, $user, $this->server->getPassword());
		$command = Server::CLIENT . ' --authentication-file=/proc/self/fd/3' .
		$command = sprintf('%s --authentication-file=/proc/self/fd/3 //%s/%s',
		$command = sprintf('%s --authentication-file=/proc/self/fd/3 //%s/%s -c \'get %s /proc/self/fd/5\'',
		$command = sprintf('%s --authentication-file=/proc/self/fd/3 //%s/%s -c \'put /proc/self/fd/4 %s\'',

Fixed code:
		$this->state->init($this->getWorkgroup(), $this->getUser(), $this->getPassword());
		$this->state->init($this->server->getWorkgroup(), $this->server->getUser(), $this->server->getPassword());
	/**
	 * @var string $workgroup
	 */
	protected $workgroup;

		list($workgroup, $user) = $this->splitUser($user);
		$this->workgroup = $workgroup;
	/**
	 * Split workgroup from username
	 *
	 * @param $user
	 * @return string[] [$workgroup, $user]
	 */
	public function splitUser($user) {
		if (strpos($user, '/')) {
			return explode('/', $user, 2);
		} elseif (strpos($user, '\\')) {
			return explode('\\', $user);
		} else {
			return [null, $user];
		}
	}

	/**
	 * @return string
	 */
	public function getWorkgroup() {
		return $this->workgroup;
	}

		$workgroupArgument = ($this->workgroup) ? ' -W ' . escapeshellarg($this->workgroup) : '';
		$command = Server::CLIENT . $workgroupArgument . ' --authentication-file=/proc/self/fd/3' .
		$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
		$command = sprintf('%s %s --authentication-file=/proc/self/fd/3 //%s/%s',
			$workgroupArgument,
		$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
		$command = sprintf('%s %s --authentication-file=/proc/self/fd/3 //%s/%s -c \'get %s /proc/self/fd/5\'',
			$workgroupArgument,
		$workgroupArgument = ($this->server->getWorkgroup()) ? ' -W ' . escapeshellarg($this->server->getWorkgroup()) : '';
		$command = sprintf('%s %s --authentication-file=/proc/self/fd/3 //%s/%s -c \'put /proc/self/fd/4 %s\'',
			$workgroupArgument,