Issues (244)

Security Analysis    not enabled

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.

src/N98/Util/WindowsSystem.php (1 issue)

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
 * this file is part of magerun
4
 *
5
 * @author Tom Klingenberg <https://github.com/ktomk>
6
 */
7
8
namespace N98\Util;
9
10
/**
11
 * Class WindowsSystem
12
 *
13
 * Utility class with global static functions.
14
 *
15
 * @package N98\Util
16
 */
17
final class WindowsSystem
18
{
19
    const PATH_SEPARATOR = ';';
20
21
    const FORBIDDEN_CHARS = '<>:"/\|?*';
22
23
    /**
24
     * @var WindowsSystem
25
     */
26
    private static $instance;
27
28
    /**
29
     * @var array
30
     */
31
    private $exts;
32
33
    /**
34
     * an instance is bootstrapped in to prevent initialization overhead
35
     *
36
     * @return WindowsSystem
37
     */
38
    private static function getInstance()
39
    {
40
        self::$instance || self::$instance = new WindowsSystem();
41
42
        return self::$instance;
43
    }
44
45
    private function __construct()
46
    {
47
    }
48
49
    /**
50
     * @return array keys are uppercase extensions incl. dot
51
     */
52
    private function getExecuteableExtesions()
53
    {
54
        // PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1
55
        $this->exts || $this->exts = array_flip(
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->exts of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
56
            array_map('strtoupper', explode(self::PATH_SEPARATOR, getenv('PATHEXT')))
57
        );
58
59
        return $this->exts;
60
    }
61
62
    /**
63
     * a name is executable based on it's extension
64
     *
65
     * @param string $name
66
     *
67
     * @return bool
68
     */
69
    public static function isExecutableName($name)
70
    {
71
        // invalid name is never executable
72
        if (false !== strpbrk($name, self::FORBIDDEN_CHARS)) {
73
            return false;
74
        }
75
76
        $compare = '.' . strtoupper(pathinfo($name, PATHINFO_EXTENSION));
77
78
        if ($compare === '.') {
79
            return false;
80
        }
81
82
        $exts = self::getInstance()->getExecuteableExtesions();
83
84
        return isset($exts[$compare]);
85
    }
86
87
    /**
88
     * a program (by it's basename) is available on system for execution
89
     *
90
     * @param string $program
91
     * @return bool
92
     */
93
    public static function isProgramInstalled($program)
94
    {
95
        // programs with an invalid name do not exist
96
        if (false !== strpbrk($program, self::FORBIDDEN_CHARS)) {
97
            return false;
98
        }
99
100
        $isExecutable = self::isExecutableName($program);
101
102
        $paths = explode(self::PATH_SEPARATOR, getenv('PATH'));
103
        array_unshift($paths, getcwd());
104
        $exts = self::getInstance()->getExecuteableExtesions();
105
106
        foreach ($paths as $path) {
107
            if (!is_dir($path)) {
108
                continue;
109
            }
110
            $file = $path . '/' . $program;
111
112
            if ($isExecutable && is_readable($file)) {
113
                return true;
114
            }
115
116
            foreach ($exts as $ext => $index) {
117
                $fileEx = $file . $ext;
118
                if (is_readable($fileEx)) {
119
                    return true;
120
                }
121
            }
122
        }
123
124
        return false;
125
    }
126
}
127