Issues (91)

Security Analysis    not enabled

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

  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.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  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.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  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.
  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.
  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.
  Header Injection
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.

class/Common/FilesManagement.php (4 issues)

Severity
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Moduleinstaller\Common;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
use DirectoryIterator;
16
use RuntimeException;
17
use SplFileInfo;
18
use XoopsUser;
19
20
/**
21
 * @copyright   XOOPS Project (https://xoops.org)
22
 * @license     GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
23
 * @author      mamba <[email protected]>
24
 */
25
trait FilesManagement
26
{
27
    /**
28
     * Function responsible for checking if a directory exists, we can also write in and create an index.html file
29
     *
30
     * @param string $folder The full path of the directory to check
31
     */
32
    public static function createFolder($folder): void
33
    {
34
        try {
35
            if (!\is_dir($folder)) {
36
                if (!\is_dir($folder) && !\mkdir($folder) && !\is_dir($folder)) {
37
                    throw new RuntimeException(\sprintf('Unable to create the %s directory', $folder));
38
                }
39
40
                file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
41
            }
42
        } catch (\Throwable $e) {
43
            echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
44
        }
45
    }
46
47
    /**
48
     * @param $file
49
     * @param $folder
50
     * @return bool
51
     */
52
    public static function copyFile(string $file, string $folder): bool
53
    {
54
        return \copy($file, $folder);
55
    }
56
57
    /**
58
     * @param $src
59
     * @param $dst
60
     */
61
    public static function recurseCopy($src, $dst): void
62
    {
63
        $dir = \opendir($src);
64
        //        @mkdir($dst);
65
        if (!@\mkdir($dst) && !\is_dir($dst)) {
66
            throw new RuntimeException('The directory ' . $dst . ' could not be created.');
67
        }
68
        while (false !== ($file = \readdir($dir))) {
69
            if (('.' !== $file) && ('..' !== $file)) {
70
                if (\is_dir($src . '/' . $file)) {
71
                    self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
72
                } else {
73
                    \copy($src . '/' . $file, $dst . '/' . $file);
74
                }
75
            }
76
        }
77
        \closedir($dir);
78
    }
79
80
    /**
81
     * Remove files and (sub)directories
82
     *
83
     * @param string $src source directory to delete
84
     *
85
     * @return bool true on success
86
     * @uses \Xmf\Module\Helper::isUserAdmin()
87
     *
88
     * @uses \Xmf\Module\Helper::getHelper()
89
     */
90
    public static function deleteDirectory($src)
91
    {
92
        // Only continue if user is a 'global' Admin
93
        if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
94
            return false;
95
        }
96
97
        $success = true;
98
        // remove old files
99
        $dirInfo = new SplFileInfo($src);
100
        // validate is a directory
101
        if ($dirInfo->isDir()) {
102
            $fileList = \array_diff(\scandir($src, \SCANDIR_SORT_NONE), ['..', '.']);
103
            foreach ($fileList as $k => $v) {
104
                $fileInfo = new SplFileInfo("{$src}/{$v}");
105
                if ($fileInfo->isDir()) {
106
                    // recursively handle subdirectories
107
                    if (!$success = self::deleteDirectory($fileInfo->getRealPath())) {
108
                        break;
109
                    }
110
                } elseif (!($success = \unlink($fileInfo->getRealPath()))) {
111
                    break;
112
                }
113
            }
114
            // now delete this (sub)directory if all the files are gone
115
            if ($success) {
116
                $success = \rmdir($dirInfo->getRealPath());
117
            }
118
        } else {
119
            // input is not a valid directory
120
            $success = false;
121
        }
122
123
        return $success;
124
    }
125
126
    /**
127
     * Recursively remove directory
128
     *
129
     * @todo currently won't remove directories with hidden files, should it?
130
     *
131
     * @param string $src directory to remove (delete)
132
     *
133
     * @return bool true on success
134
     */
135
    public static function rrmdir($src)
136
    {
137
        // Only continue if user is a 'global' Admin
138
        if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
139
            return false;
140
        }
141
142
        // If source is not a directory stop processing
143
        if (!\is_dir($src)) {
144
            return false;
145
        }
146
147
        $success = true;
0 ignored issues
show
The assignment to $success is dead and can be removed.
Loading history...
148
149
        // Open the source directory to read in files
150
        $iterator = new DirectoryIterator($src);
151
        foreach ($iterator as $fObj) {
152
            if ($fObj->isFile()) {
153
                $filename = $fObj->getPathname();
154
                $fObj     = null; // clear this iterator object to close the file
0 ignored issues
show
The assignment to $fObj is dead and can be removed.
Loading history...
155
                if (!\unlink($filename)) {
156
                    return false; // couldn't delete the file
157
                }
158
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
159
                // Try recursively on directory
160
                self::rrmdir($fObj->getPathname());
161
            }
162
        }
163
        $iterator = null;   // clear iterator Obj to close file/directory
0 ignored issues
show
The assignment to $iterator is dead and can be removed.
Loading history...
164
165
        return \rmdir($src); // remove the directory & return results
166
    }
167
168
    /**
169
     * Recursively move files from one directory to another
170
     *
171
     * @param string $src  - Source of files being moved
172
     * @param string $dest - Destination of files being moved
173
     *
174
     * @return bool true on success
175
     */
176
    public static function rmove($src, $dest)
177
    {
178
        // Only continue if user is a 'global' Admin
179
        if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
180
            return false;
181
        }
182
183
        // If source is not a directory stop processing
184
        if (!\is_dir($src)) {
185
            return false;
186
        }
187
188
        // If the destination directory does not exist and could not be created stop processing
189
        if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) {
190
            return false;
191
        }
192
193
        // Open the source directory to read in files
194
        $iterator = new DirectoryIterator($src);
195
        foreach ($iterator as $fObj) {
196
            if ($fObj->isFile()) {
197
                \rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
198
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
199
                // Try recursively on directory
200
                self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
201
                //                rmdir($fObj->getPath()); // now delete the directory
202
            }
203
        }
204
        $iterator = null;   // clear iterator Obj to close file/directory
0 ignored issues
show
The assignment to $iterator is dead and can be removed.
Loading history...
205
206
        return \rmdir($src); // remove the directory & return results
207
    }
208
209
    /**
210
     * Recursively copy directories and files from one directory to another
211
     *
212
     * @param string $src  - Source of files being moved
213
     * @param string $dest - Destination of files being moved
214
     *
215
     * @return bool true on success
216
     * @uses \Xmf\Module\Helper::isUserAdmin()
217
     *
218
     * @uses \Xmf\Module\Helper::getHelper()
219
     */
220
    public static function rcopy($src, $dest)
221
    {
222
        // Only continue if user is a 'global' Admin
223
        if (!($GLOBALS['xoopsUser'] instanceof XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
224
            return false;
225
        }
226
227
        // If source is not a directory stop processing
228
        if (!\is_dir($src)) {
229
            return false;
230
        }
231
232
        // If the destination directory does not exist and could not be created stop processing
233
        if (!\is_dir($dest) && !\mkdir($dest) && !\is_dir($dest)) {
234
            return false;
235
        }
236
237
        // Open the source directory to read in files
238
        $iterator = new DirectoryIterator($src);
239
        foreach ($iterator as $fObj) {
240
            if ($fObj->isFile()) {
241
                \copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
242
            } elseif (!$fObj->isDot() && $fObj->isDir()) {
243
                self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename());
244
            }
245
        }
246
247
        return true;
248
    }
249
}
250