Issues (94)

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.

Platform.php (5 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 namespace nyx\utils;
2
3
/**
4
 * Platform
5
 *
6
 * Utilities related to the operating system PHP is running on, retrieving information about and executing
7
 * system processes etc.
8
 *
9
 * Requires:
10
 * - Function: shell_exec() (getting the shells available on this system)
11
 * - Function: exec() (checking whether TTY is available on this system)
12
 *
13
 * @package     Nyx\Utils\Platform
14
 * @version     0.1.0
15
 * @author      Michal Chojnacki <[email protected]>
16
 * @copyright   2012-2016 Nyx Dev Team
17
 * @link        http://docs.muyo.io/nyx/utils/platform.html
18
 */
19
class Platform
20
{
21
    /**
22
     * The traits of the Platform class.
23
     */
24
    use traits\StaticallyExtendable;
25
26
    /**
27
     * Platform type constants.
28
     */
29
    const TYPE_UNIX    = 1;
30
    const TYPE_WINDOWS = 2;
31
    const TYPE_BSD     = 3;
32
    const TYPE_CYGWIN  = 4;
33
    const TYPE_DARWIN  = 5;
34
35
    /**
36
     * @var int     The platform PHP is running on.
37
     */
38
    private static $type;
39
40
    /**
41
     * @var array   An array of shell names and the paths to their binaries once populated or false when PHP is
42
     *              running on a system that does not support them (Windows).
43
     */
44
    private static $shells;
45
46
    /**
47
     * @var bool    Whether this platform has the 'stty' binary (always false on Windows).
48
     */
49
    private static $hasStty;
50
51
    /**
52
     * Guesses and returns the platform PHP is running on. If it can't be determined, the default
53
     * of self::TYPE_UNIX will be returned.
54
     *
55
     * @return  int     One of the platform TYPE_ constants defined in this class.
56
     */
57
    public static function getType() : int
58
    {
59
        // Return the cached result if it's already available.
60
        if (null !== static::$type) {
61
            return static::$type;
62
        }
63
64
        $os = strtolower(php_uname("s"));
65
66
        // Check in order of likeliness.
67
        if (false !== strpos($os, 'unix')) {
68
            return static::$type = self::TYPE_UNIX;
69
        }
70
71
        if (0 === strpos($os, 'win')) {
72
            return static::$type = self::TYPE_WINDOWS;
73
        }
74
75
        if (false !== strpos($os, 'bsd')) {
76
            return static::$type = self::TYPE_BSD;
77
        }
78
79
        if (false !== strpos($os, 'darwin')) {
80
            return static::$type = self::TYPE_DARWIN;
81
        }
82
83
        if (false !== strpos($os, 'cygwin')) {
84
            return static::$type = self::TYPE_CYGWIN;
85
        }
86
87
        // Use the default otherwise.
88
        return static::$type = self::TYPE_UNIX;
89
    }
90
91
    /**
92
     * Checks whether PHP is running on a Unix platform
93
     *
94
     * @return  bool    True when PHP is running on a Unix platform, false otherwise.
95
     */
96 View Code Duplication
    public static function isUnix() : bool
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...
97
    {
98
        // Return the cached result if it's already available.
99
        if (null !== static::$type) {
100
            return static::$type === self::TYPE_UNIX;
101
        }
102
103
        return static::getType() === self::TYPE_UNIX;
104
    }
105
106
    /**
107
     * Checks whether PHP is running on a Windows platform
108
     *
109
     * @return  bool    True when PHP is running on a Windows platform, false otherwise.
110
     */
111 View Code Duplication
    public static function isWindows() : bool
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...
112
    {
113
        // Return the cached result if it's already available.
114
        if (null !== static::$type) {
115
            return static::$type === self::TYPE_WINDOWS;
116
        }
117
118
        return static::getType() === self::TYPE_WINDOWS;
119
    }
120
121
    /**
122
     * Checks whether PHP is running on a BSD platform
123
     *
124
     * @return  bool    True when PHP is running on a BSD platform, false otherwise.
125
     */
126 View Code Duplication
    public static function isBsd() : bool
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...
127
    {
128
        // Return the cached result if it's already available.
129
        if (null !== static::$type) {
130
            return static::$type === self::TYPE_BSD;
131
        }
132
133
        return static::getType() === self::TYPE_BSD;
134
    }
135
136
    /**
137
     * Checks whether PHP is running on a Darwin platform
138
     *
139
     * @return  bool    True when PHP is running on a Darwin platform, false otherwise.
140
     */
141 View Code Duplication
    public static function isDarwin() : bool
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...
142
    {
143
        // Return the cached result if it's already available.
144
        if (null !== static::$type) {
145
            return static::$type === self::TYPE_DARWIN;
146
        }
147
148
        return static::getType() === self::TYPE_DARWIN;
149
    }
150
151
    /**
152
     * Checks whether PHP is running on a Cygwin platform
153
     *
154
     * @return  bool    True when PHP is running on a Cygwin platform, false otherwise.
155
     */
156 View Code Duplication
    public static function isCygwin() : bool
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...
157
    {
158
        // Return the cached result if it's already available.
159
        if (null !== static::$type) {
160
            return static::$type === self::TYPE_CYGWIN;
161
        }
162
163
        return static::getType() === self::TYPE_CYGWIN;
164
    }
165
166
    /**
167
     * Returns the path to the given shell's binary or null when it is not available.
168
     *
169
     * @param   string          $name
170
     * @return  string|null
171
     */
172
    public static function getShell(string $name)
173
    {
174
        return static::getShells()[$name] ?? null;
175
    }
176
177
    /**
178
     * Checks whether a shell of the given name is available in the system.
179
     *
180
     * @param   string  $name
181
     * @return  bool
182
     */
183
    public static function hasShell(string $name) : bool
184
    {
185
        return isset(static::getShells()[$name]);
186
    }
187
188
    /**
189
     * Returns an array of shell names and the paths to their binaries once populated. Will return an empty
190
     * array on unsupported platforms (Windows).
191
     *
192
     * @return  array
193
     */
194
    public static function getShells() : array
195
    {
196
        // Return the cached result if it's already available.
197
        if (static::$shells !== null) {
198
            return static::$shells;
199
        }
200
201
        // Ensure this method will be ran once at most.
202
        static::$shells = [];
203
204
        // Can't easily check on Windows even if Cygwin or the likes are available.
205
        if (static::isWindows()) {
206
            return static::$shells;
207
        }
208
209
        if (file_exists($file = '/etc/shells')) {
210
            $cat = trim(shell_exec('cat '.$file.' 2> /dev/null'));
211
212
            foreach (explode(PHP_EOL, $cat) as $path) {
213
                // Ignore this line if it doesn't begin with a filepath.
214
                if ($path[0] != '/') {
215
                    continue;
216
                }
217
218
                $name = substr($path, strrpos($path, '/') + 1);
219
220
                static::$shells[$name] = $path;
221
            }
222
        }
223
224
        return static::$shells;
225
    }
226
227
    /**
228
     * Checks whether this platform has the 'stty' binary.
229
     *
230
     * @return  bool    True when 'stty' is available on this platform, false otherwise (always false on Windows).
231
     */
232
    public static function hasStty() : bool
233
    {
234
        // Return the cached result if it's already available.
235
        if (static::$hasStty !== null) {
236
            return static::$hasStty;
237
        }
238
239
        // Definitely no Stty on Windows.
240
        if (static::isWindows()) {
241
            return static::$hasStty = false;
242
        }
243
244
        // Run a simple exec() call and check whether it returned with an error code.
245
        exec('/usr/bin/env stty', $output, $exitCode);
246
247
        return static::$hasStty = $exitCode === 0;
248
    }
249
}
250