Issues (41)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

source/Threema/Console/Command/Base.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @author Threema GmbH
4
 * @copyright Copyright (c) 2015-2016 Threema GmbH
5
 */
6
7
8
namespace Threema\Console\Command;
9
10
use Threema\Console\Common;
11
use Threema\Core\Exception;
12
use Threema\Console\Command\CryptTool;
13
14
abstract class Base {
15
	const argThreemaId = 'threemaId';
16
	const argFrom = 'from';
17
	const argSecret = 'secret';
18
	const argPrivateKey = 'privateKey';
19
	const argPublicKey = 'publicKey';
20
	const argPrivateKeyFile = 'privateKeyFile';
21
	const argPublicKeyFile = 'publicKeyFile';
22
	const argNonce = 'nonce';
23
24
	/**
25
	 * @var string
26
	 */
27
	private $subject;
28
29
	/**
30
	 * @var string[]
31
	 */
32
	private $arguments = array();
33
34
	/**
35
	 * @var string[]
36
	 */
37
	private $requiredArguments;
38
39
	/**
40
	 * @var string
41
	 */
42
	private $description;
43
	/**
44
	 * @var array
45
	 */
46
	private $optionalArguments;
47
48
	/**
49
	 * @param string $subject
50
	 * @param string[] $requiredArguments
51
	 * @param string $description
52
	 * @param array $optionalArguments
53
	 */
54
	public function __construct($subject, array $requiredArguments, $description, array $optionalArguments = array()) {
55
		$this->subject = $subject;
56
		$this->requiredArguments = $requiredArguments;
57
		$this->description = $description;
58
		$this->optionalArguments = $optionalArguments;
59
	}
60
61
	/**
62
	 * @return int
63
	 */
64
	public function getRequiredArgumentCount() {
65
		return null !== $this->requiredArguments ? count($this->requiredArguments) : 0;
66
	}
67
68
	/**
69
	 * @return int
70
	 */
71
	public function getAllArgumentsCount() {
72
		return $this->getRequiredArgumentCount() + (null !== $this->optionalArguments ? count($this->optionalArguments) : 0);
73
	}
74
75
	/**
76
	 * @param string $pos
77
	 * @return int
78
	 * @throws \Threema\Core\Exception
79
	 */
80
	private function getIndexByPos($pos){
81
		$i = array_search($pos, $this->requiredArguments);
82
		if(false === $i) {
83
			$i = array_search($pos, $this->optionalArguments);
84
			if(false !== $i) {
85
				$i += count($this->requiredArguments);
86
			}
87
		}
88
		if(false === $i) {
89
			throw new Exception('argument '.$pos.' not found');
90
		}
91
92
		return $i;
93
	}
94
95
	/**
96
	 * @param string $pos
97
	 * @return null|string
98
	 * @throws \Threema\Core\Exception
99
	 */
100
	public function getArgument($pos) {
101
		$i = $this->getIndexByPos($pos);
102
		$required = $i < count($this->requiredArguments);
103
104
		if(false === array_key_exists($i, $this->arguments)) {
105
			if(true === $required) {
106
				throw new Exception('no argument at position '.$i.' ('.$pos.')');
107
			}
108
			else {
109
				return null;
110
			}
111
		}
112
		return $this->arguments[$i];
113
	}
114
115
	/**
116
	 * return a valid file path
117
	 *
118
	 * @param string $pos
119
	 * @return null|string
120
	 * @throws \Threema\Core\Exception
121
	 */
122
	public function getArgumentFile($pos) {
123
		$i = $this->getIndexByPos($pos);
124
125
		if(false === is_file($this->arguments[$i])) {
126
			throw new Exception('argument '.$i.' is not a file');
127
		}
128
129
		return $this->arguments[$i];
130
	}
131
132
	/**
133
	 * @param string $pos
134
	 * @return null|string
135
	 */
136 View Code Duplication
	public function getArgumentPrivateKey($pos) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
		$content = Common::getPrivateKey($this->getArgumentStringOrFileContent($pos));
138
		$cryptTool = CryptTool::getInstance();
139
		if(null !== $content) {
140
			return $cryptTool->hex2bin($content);
141
		}
142
		return null;
143
	}
144
145
	/**
146
	 * @param string $pos
147
	 * @return null|string
148
	 */
149 View Code Duplication
	public function getArgumentPublicKey($pos) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
		$content = Common::getPublicKey($this->getArgumentStringOrFileContent($pos));
151
		$cryptTool = CryptTool::getInstance();
152
		if(null !== $content) {
153
			return $cryptTool->hex2bin($content);
154
		}
155
		return null;
156
	}
157
158
	/**
159
	 * @param string $pos
160
	 * @return null|string
161
	 */
162
	private function getArgumentStringOrFileContent($pos) {
163
		$content = $this->getArgument($pos);
164
		if(file_exists($content)) {
165
			$content = trim(file_get_contents($content));
166
		}
167
		return $content;
168
	}
169
170
	/**
171
	 * @param string $pos
172
	 * @return null|string
173
	 */
174
	public function getArgumentThreemaId($pos) {
175
		$content = $this->getArgument($pos);
176
		if(null !== $content && strlen($content) == 8) {
177
			return strtoupper($content);
178
		}
179
		return null;
180
	}
181
182
	/**
183
	 * @return string
184
	 */
185
	protected function readStdIn() {
186
		$f = fopen( 'php://stdin', 'r' );
187
188
		$lines = array();
189
		while( $line = trim(fgets($f)) ) {
190
191
			if(strlen($line) == 0 || $line == "\n") {
192
				continue;
193
			}
194
195
			$lines[] = $line;
196
		}
197
198
		return implode("\n", $lines);
199
	}
200
201
	/**
202
	 * @param array $arguments
203
	 * @throws \Threema\Core\Exception
204
	 */
205
	final public function run(array $arguments) {
206
		$this->arguments = $arguments;
207
208
		$argCount = null !== $this->arguments ? count($this->arguments) : 0;
209
210
		if($argCount < count($this->requiredArguments)) {
211
			throw new Exception('invalid count of arguments');
212
		}
213
		$this->doRun();
214
	}
215
216
	/**
217
	 * @param bool $shellColors
218
	 * @return string
219
	 */
220
	final public function help($shellColors = true) {
221
		$args = array_merge($this->requiredArguments, $this->optionalArguments);
222
223
		if(count($args) > 0) {
224
			$colorPrefix = '';
225
			$colorPostfix = '';
226
			if(true === $shellColors) {
227
				$colorPrefix = "\033[0;36m\033[40m";
228
				$colorPostfix = "\033[0m";
229
			}
230
			return  $colorPrefix.'<'.implode('> <', $args).'>'.$colorPostfix;
231
		}
232
		return '';
233
	}
234
235
	/**
236
	 * @return string
237
	 */
238
	final public function description() {
239
		return $this->description;
240
	}
241
242
	/**
243
	 * @return string
244
	 */
245
	final public function subject() {
246
		return $this->subject;
247
	}
248
249
	abstract protected function doRun();
250
}
251