Issues (195)

lib/Classifier.php (2 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * @copyright Copyright (c) 2017 Matthias Held <[email protected]>
5
 * @author Matthias Held <[email protected]>
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace OCA\RansomwareDetection;
23
24
use OCA\RansomwareDetection\Analyzer\FileExtensionResult;
25
use OCA\RansomwareDetection\Analyzer\EntropyResult;
26
use OCA\RansomwareDetection\Db\FileOperationMapper;
27
use OCA\RansomwareDetection\Service\FileOperationService;
28
use OCP\ILogger;
0 ignored issues
show
The type OCP\ILogger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
30
class Classifier
31
{
32
    /**
33
     * File suspicion levels.
34
     *
35
     * @var int
36
     */
37
    const SUSPICIOUS = 3;
38
    const MAYBE_SUSPICIOUS = 2;
39
    const NOT_SUSPICIOUS = 1;
40
    const NO_INFORMATION = 0;
41
42
    /** @var ILogger */
43
    private $logger;
44
45
    /** @var FileOperationMapper */
46
    private $mapper;
47
48
    /** @var FileOperationService */
49
    private $service;
50
51
    /**
52
     * @param ILogger              $logger
53
     * @param FileOperationMapper  $mapper
54
     * @param FileOperationService $service
55
     */
56
    public function __construct(
57
        ILogger $logger,
58
        FileOperationMapper $mapper,
59
        FileOperationService $service
60
    ) {
61
        $this->logger = $logger;
62
        $this->mapper = $mapper;
63
        $this->service = $service;
64
    }
65
66
    /**
67
     * Classifies a file.
68
     *
69
     * @param Entity $file
0 ignored issues
show
The type OCA\RansomwareDetection\Entity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
70
     *
71
     * @return Entity Classified file.
72
     */
73
    public function classifyFile($file)
74
    {
75
        $file->setSuspicionClass(self::NO_INFORMATION);
76
        if ($file->getCommand() === Monitor::WRITE ||
77
            $file->getCommand() === Monitor::RENAME ||
78
            $file->getCommand() === Monitor::DELETE ||
79
            $file->getCommand() === Monitor::CREATE
80
        ) {
81
            if ($file->getFileClass() === EntropyResult::ENCRYPTED) {
82
                if ($file->getFileExtensionClass() === FileExtensionResult::SUSPICIOUS) {
83
                    $file->setSuspicionClass(self::SUSPICIOUS);
84
                } else {
85
                    $file->setSuspicionClass(self::MAYBE_SUSPICIOUS);
86
                }
87
            } elseif ($file->getFileClass() === EntropyResult::COMPRESSED) {
88
                if ($file->getFileExtensionClass() === FileExtensionResult::SUSPICIOUS) {
89
                    $file->setSuspicionClass(self::MAYBE_SUSPICIOUS);
90
                } else {
91
                    $file->setSuspicionClass(self::NOT_SUSPICIOUS);
92
                }
93
            } else {
94
                $file->setSuspicionClass(self::NOT_SUSPICIOUS);
95
            }
96
        }
97
98
        return $file;
99
    }
100
}
101