Issues (358)

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.

src/N98/Util/WindowsSystem.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 Tom Klingenberg <[email protected]>
4
 */
5
6
namespace N98\Util;
7
8
/**
9
 * Class WindowsSystem
10
 *
11
 * Utility class with global static functions.
12
 *
13
 * @package N98\Util
14
 */
15
class WindowsSystem
0 ignored issues
show
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
16
{
17
    const PATH_SEPARATOR = ';';
18
19
    const FORBIDDEN_CHARS = '<>:"/\|?*';
20
21
    /**
22
     * @var WindowsSystem
23
     */
24
    private static $instance;
25
26
    /**
27
     * @var array
28
     */
29
    private $exts;
30
31
    /**
32
     * an instance is bootstrapped in to prevent initialization overhead
33
     *
34
     * @return WindowsSystem
35
     */
36
    private static function getInstance()
37
    {
38
        self::$instance || self::$instance = new WindowsSystem();
39
40
        return self::$instance;
41
    }
42
43
    private function __construct()
44
    {
45
    }
46
47
    /**
48
     * @return array keys are uppercase extensions incl. dot
49
     */
50
    private function getExecuteableExtesions()
51
    {
52
        // PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1
53
        $this->exts || $this->exts = array_flip(array_map(
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...
54
            'strtoupper',
55
            explode(self::PATH_SEPARATOR, getenv('PATHEXT'))
56
        ));
57
58
        return $this->exts;
59
    }
60
61
    /**
62
     * a name is executable based on it's extension
63
     *
64
     * @param string $name
65
     *
66
     * @return bool
67
     */
68
    public static function isExecutableName($name)
69
    {
70
        // invalid name is never executable
71
        if (false !== strpbrk($name, self::FORBIDDEN_CHARS)) {
72
            return false;
73
        }
74
75
        $compare = '.' . strtoupper(pathinfo($name, PATHINFO_EXTENSION));
76
77
        if ($compare === '.') {
78
            return false;
79
        }
80
81
        $exts = self::getInstance()->getExecuteableExtesions();
82
83
        return isset($exts[$compare]);
84
    }
85
86
    /**
87
     * a program (by it's basename) is available on system for execution
88
     *
89
     * @param string $program
90
     * @return bool
91
     */
92
    public static function isProgramInstalled($program)
93
    {
94
        // programs with an invalid name do not exist
95
        if (false !== strpbrk($program, self::FORBIDDEN_CHARS)) {
96
            return false;
97
        }
98
99
        $isExecutable = self::isExecutableName($program);
100
101
102
        $paths = explode(self::PATH_SEPARATOR, getenv('PATH'));
103
        array_unshift($paths, getcwd());
104
        $exts = self::getInstance()->getExecuteableExtesions();
105
106
107
        foreach ($paths as $path) {
108
            if (!is_dir($path)) {
109
                continue;
110
            }
111
            $file = $path . '/' . $program;
112
113
            if ($isExecutable && is_readable($file)) {
114
                return true;
115
            }
116
117
            foreach ($exts as $ext => $index) {
118
                $fileEx = $file . $ext;
119
                if (is_readable($fileEx)) {
120
                    return true;
121
                }
122
            }
123
        }
124
125
        return false;
126
    }
127
}
128