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\AppInfo; |
23
|
|
|
|
24
|
|
|
use OC\Files\Filesystem; |
|
|
|
|
25
|
|
|
use OCA\RansomwareDetection\Monitor; |
26
|
|
|
use OCA\RansomwareDetection\Events\FilesEvents; |
27
|
|
|
use OCA\RansomwareDetection\FilesHooks; |
28
|
|
|
use OCA\RansomwareDetection\Classifier; |
29
|
|
|
use OCA\RansomwareDetection\Analyzer\EntropyAnalyzer; |
30
|
|
|
use OCA\RansomwareDetection\Analyzer\SequenceAnalyzer; |
31
|
|
|
use OCA\RansomwareDetection\Analyzer\SequenceSizeAnalyzer; |
32
|
|
|
use OCA\RansomwareDetection\Analyzer\FileTypeFunnellingAnalyzer; |
33
|
|
|
use OCA\RansomwareDetection\Analyzer\EntropyFunnellingAnalyzer; |
34
|
|
|
use OCA\RansomwareDetection\Analyzer\FileCorruptionAnalyzer; |
35
|
|
|
use OCA\RansomwareDetection\Analyzer\FileExtensionAnalyzer; |
36
|
|
|
use OCA\RansomwareDetection\Entropy\Entropy; |
37
|
|
|
use OCA\RansomwareDetection\Notification\Notifier; |
38
|
|
|
use OCA\RansomwareDetection\StorageWrapper; |
|
|
|
|
39
|
|
|
use OCA\RansomwareDetection\Connector\Sabre\RequestPlugin; |
40
|
|
|
use OCA\RansomwareDetection\Service\FileOperationService; |
41
|
|
|
use OCA\RansomwareDetection\Mapper\FileOperationMapper; |
|
|
|
|
42
|
|
|
use OCP\AppFramework\App; |
|
|
|
|
43
|
|
|
use OCP\App\IAppManager; |
|
|
|
|
44
|
|
|
use OCP\Files\IRootFolder; |
|
|
|
|
45
|
|
|
use OCP\AppFramework\Utility\ITimeFactory; |
|
|
|
|
46
|
|
|
use OCP\Files\Storage\IStorage; |
|
|
|
|
47
|
|
|
use OCP\Notification\IManager; |
|
|
|
|
48
|
|
|
use OCP\Util; |
|
|
|
|
49
|
|
|
use OCP\SabrePluginEvent; |
|
|
|
|
50
|
|
|
use OCP\ILogger; |
|
|
|
|
51
|
|
|
use OCP\IConfig; |
|
|
|
|
52
|
|
|
use OCP\IUserSession; |
|
|
|
|
53
|
|
|
use OCP\ISession; |
|
|
|
|
54
|
|
|
use OCP\IRequest; |
|
|
|
|
55
|
|
|
|
56
|
|
|
class Application extends App |
57
|
|
|
{ |
58
|
|
|
const APP_ID = 'ransomware_detection'; |
59
|
|
|
|
60
|
|
|
public function __construct() |
61
|
|
|
{ |
62
|
|
|
parent::__construct(self::APP_ID); |
63
|
|
|
|
64
|
|
|
$container = $this->getContainer(); |
65
|
|
|
|
66
|
|
|
// mapper |
67
|
|
|
$container->registerService('FileOperationMapper', function ($c) { |
68
|
|
|
return new FileOperationMapper( |
69
|
|
|
$c->query('ServerContainer')->getDb() |
70
|
|
|
); |
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
// services |
74
|
|
|
$container->registerService('FileOperationService', function ($c) { |
75
|
|
|
return new FileOperationService( |
76
|
|
|
$c->query(FileOperationMapper::class), |
77
|
|
|
$c->query('ServerContainer')->getUserSession()->getUser()->getUID() |
78
|
|
|
); |
79
|
|
|
}); |
80
|
|
|
|
81
|
|
|
// classifier |
82
|
|
|
$container->registerService('Classifier', function ($c) { |
83
|
|
|
return new Classifier( |
84
|
|
|
$c->query(ILogger::class), |
85
|
|
|
$c->query(FileOperationMapper::class), |
86
|
|
|
$c->query(FileOperationService::class) |
87
|
|
|
); |
88
|
|
|
}); |
89
|
|
|
|
90
|
|
|
// entropy |
91
|
|
|
$container->registerService('Entropy', function ($c) { |
92
|
|
|
return new Entropy( |
93
|
|
|
$c->query(ILogger::class) |
94
|
|
|
); |
95
|
|
|
}); |
96
|
|
|
|
97
|
|
|
// analyzer |
98
|
|
|
$container->registerService('SequenceSizeAnalyzer', function ($c) { |
|
|
|
|
99
|
|
|
return new SequenceSizeAnalyzer(); |
100
|
|
|
}); |
101
|
|
|
|
102
|
|
|
$container->registerService('FileTypeFunnellingAnalyzer', function ($c) { |
|
|
|
|
103
|
|
|
return new FileTypeFunnellingAnalyzer(); |
104
|
|
|
}); |
105
|
|
|
|
106
|
|
|
$container->registerService('EntropyFunnellingAnalyzer', function ($c) { |
107
|
|
|
return new EntropyFunnellingAnalyzer( |
108
|
|
|
$c->query(ILogger::class) |
109
|
|
|
); |
110
|
|
|
}); |
111
|
|
|
|
112
|
|
|
$container->registerService('FileExtensionAnalyzer', function ($c) { |
113
|
|
|
return new FileExtensionAnalyzer( |
114
|
|
|
$c->query(ILogger::class), |
115
|
|
|
$c->query(Entropy::class) |
|
|
|
|
116
|
|
|
|
117
|
|
|
); |
118
|
|
|
}); |
119
|
|
|
|
120
|
|
|
$container->registerService('SequenceAnalyzer', function ($c) { |
121
|
|
|
return new SequenceAnalyzer( |
122
|
|
|
$c->query(SequenceSizeAnalyzer::class), |
123
|
|
|
$c->query(FileTypeFunnellingAnalyzer::class), |
124
|
|
|
$c->query(EntropyFunnellingAnalyzer::class) |
125
|
|
|
); |
126
|
|
|
}); |
127
|
|
|
|
128
|
|
|
$container->registerService('EntropyAnalyzer', function ($c) { |
129
|
|
|
return new EntropyAnalyzer( |
130
|
|
|
$c->query(ILogger::class), |
131
|
|
|
$c->query(IRootFolder::class), |
132
|
|
|
$c->query(Entropy::class), |
133
|
|
|
$c->query('ServerContainer')->getUserSession()->getUser()->getUID() |
134
|
|
|
); |
135
|
|
|
}); |
136
|
|
|
|
137
|
|
|
$container->registerService('FileCorruptionAnalyzer', function ($c) { |
138
|
|
|
return new FileCorruptionAnalyzer( |
139
|
|
|
$c->query(ILogger::class), |
140
|
|
|
$c->query(IRootFolder::class), |
141
|
|
|
$c->query('ServerContainer')->getUserSession()->getUser()->getUID() |
142
|
|
|
); |
143
|
|
|
}); |
144
|
|
|
|
145
|
|
|
$container->registerService('Monitor', function ($c) { |
146
|
|
|
return new Monitor( |
147
|
|
|
$c->query(IRequest::class), |
148
|
|
|
$c->query(IConfig::class), |
149
|
|
|
$c->query(ITimeFactory::class), |
150
|
|
|
$c->query(IAppManager::class), |
151
|
|
|
$c->query(ILogger::class), |
152
|
|
|
$c->query(IRootFolder::class), |
153
|
|
|
$c->query(EntropyAnalyzer::class), |
154
|
|
|
$c->query(FileOperationMapper::class), |
155
|
|
|
$c->query(FileExtensionAnalyzer::class), |
156
|
|
|
$c->query(FileCorruptionAnalyzer::class), |
157
|
|
|
$c->query('ServerContainer')->getUserSession()->getUser()->getUID() |
158
|
|
|
); |
159
|
|
|
}); |
160
|
|
|
|
161
|
|
|
$container->registerService('FilesEvents', function ($c) { |
162
|
|
|
return new FilesEvents( |
163
|
|
|
$c->query(ILogger::class), |
164
|
|
|
$c->query(Monitor::class), |
165
|
|
|
$c->query('ServerContainer')->getUserSession()->getUser()->getUID() |
166
|
|
|
); |
167
|
|
|
}); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Register hooks. |
172
|
|
|
*/ |
173
|
|
|
public function register() |
174
|
|
|
{ |
175
|
|
|
// register sabre plugin to catch the profind requests |
176
|
|
|
$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
177
|
|
|
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) { |
178
|
|
|
$logger = $this->getContainer()->query(ILogger::class); |
179
|
|
|
$config = $this->getContainer()->query(IConfig::class); |
180
|
|
|
$userSession = $this->getContainer()->query(IUserSession::class); |
181
|
|
|
$session = $this->getContainer()->query(ISession::class); |
182
|
|
|
$service = $this->getContainer()->query(FileOperationService::class); |
183
|
|
|
$notifications = $this->getContainer()->query(IManager::class); |
184
|
|
|
$classifier = $this->getContainer()->query(Classifier::class); |
185
|
|
|
$sequenceAnalyzer = $this->getContainer()->query(SequenceAnalyzer::class); |
186
|
|
|
$event->getServer()->addPlugin(new RequestPlugin($logger, $config, $userSession, $session, $service, $notifications, $classifier, $sequenceAnalyzer)); |
187
|
|
|
}); |
188
|
|
|
Util::connectHook('OC_Filesystem', 'post_create', FilesHooks::class, 'onFileCreate'); |
189
|
|
|
// Util::connectHook('OC_Filesystem', 'post_update', FilesHooks::class, 'onFileUpdate'); |
190
|
|
|
Util::connectHook('OC_Filesystem', 'post_rename', FilesHooks::class, 'onFileRename'); |
191
|
|
|
Util::connectHook('OC_Filesystem', 'post_write', FilesHooks::class, 'onFileWrite'); |
192
|
|
|
Util::connectHook('OC_Filesystem', 'post_delete', FilesHooks::class, 'onFileDelete'); |
193
|
|
|
// Util::connectHook('OC_Filesystem', 'post_touch', FilesHooks::class, 'onFileTouch'); |
194
|
|
|
// Util::connectHook('OC_Filesystem', 'post_copy', FilesHooks::class, 'onFileCopy'); |
195
|
|
|
$this->registerNotificationNotifier(); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
protected function registerNotificationNotifier() |
199
|
|
|
{ |
200
|
|
|
$this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class); |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths