Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/undo-ransomware/ransomware_detection.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/scan.js28
-rw-r--r--lib/Controller/ScanController.php34
-rw-r--r--lib/Exception/NotAFileException.php26
3 files changed, 69 insertions, 19 deletions
diff --git a/js/scan.js b/js/scan.js
index 1412c08..8d864ce 100644
--- a/js/scan.js
+++ b/js/scan.js
@@ -229,19 +229,21 @@
}).done(function(response) {
count = count + 1;
$('#scanned').text(count);
- self.$section[index] = self._createSection(index);
- self.$table[index] = self._createTableSkeleton(index, response.suspicion_score);
- self.$fileList[index] = self.$table[index].find('tbody.file-list');
- self.files[index] = [];
- $.each(response.sequence, function(i, file) {
- self.files[index][file.id] = file;
- self.$fileList[index].append(self._createFileRow(file, index));
- self.$el.find('#section-suspicious-files-text').remove();
- self.$el.find('#scan-results').show();
- });
- self.$section[index].append(self.$table[index]);
- self.$el.append(self.$section[index]);
- self.updateSelectionSummary(index);
+ if (response.status === "success") {
+ self.$section[index] = self._createSection(index);
+ self.$table[index] = self._createTableSkeleton(index, response.suspicion_score);
+ self.$fileList[index] = self.$table[index].find('tbody.file-list');
+ self.files[index] = [];
+ $.each(response.sequence, function(i, file) {
+ self.files[index][file.id] = file;
+ self.$fileList[index].append(self._createFileRow(file, index));
+ self.$el.find('#section-suspicious-files-text').remove();
+ self.$el.find('#scan-results').show();
+ });
+ self.$section[index].append(self.$table[index]);
+ self.$el.append(self.$section[index]);
+ self.updateSelectionSummary(index);
+ }
}).fail(function(response, code) {
console.log("Scan failed.");
count = count + 1;
diff --git a/lib/Controller/ScanController.php b/lib/Controller/ScanController.php
index 0958357..b5c7a7d 100644
--- a/lib/Controller/ScanController.php
+++ b/lib/Controller/ScanController.php
@@ -29,8 +29,10 @@ use OCA\RansomwareDetection\Analyzer\FileCorruptionAnalyzer;
use OCA\RansomwareDetection\Analyzer\FileNameAnalyzer;
use OCA\RansomwareDetection\AppInfo\Application;
use OCA\RansomwareDetection\Db\FileOperation;
+use OCA\RansomwareDetection\Exception\NotAFileException;
use OCA\RansomwareDetection\Service\FileOperationService;
use OCA\RansomwareDetection\Scanner\StorageStructure;
+use OCP\Files\NotFoundException;
use OCA\Files_Trashbin\Trashbin;
use OCA\Files_Trashbin\Helper;
use OCP\AppFramework\Http;
@@ -238,16 +240,28 @@ class ScanController extends OCSController
if (sizeof($sequence) > $this->config->getAppValue(Application::APP_ID, 'minimum_sequence_length', 0)) {
$sequenceResults = array();
foreach ($sequence as $file) {
- $fileOperation = $this->buildFileOperation($file);
+ try {
+ $fileOperation = $this->buildFileOperation($file);
+ } catch (NotAFileException $exception) {
+ $this->logger->debug('scanSequence: Path to file doesn\'t lead to file object.', array('app' => Application::APP_ID));
+ continue;
+ } catch (NotFoundException $exception) {
+ $this->logger->debug('scanSequence: Not found.', array('app' => Application::APP_ID));
+ continue;
+ }
$this->classifier->classifyFile($fileOperation);
- $sequenceResults[] = ['userId' => $fileOperation->getUserId(), 'path' => $fileOperation->getPath(), 'originalName' => preg_replace('/.d[0-9]{10}/', '', $fileOperation->getOriginalName()),
+ $jsonSequence[] = ['userId' => $fileOperation->getUserId(), 'path' => $fileOperation->getPath(), 'originalName' => preg_replace('/.d[0-9]{10}/', '', $fileOperation->getOriginalName()),
'type' => $fileOperation->getType(), 'mimeType' => $fileOperation->getMimeType(), 'size' => $fileOperation->getSize(), 'corrupted' => $fileOperation->getCorrupted(), 'timestamp' => $fileOperation->getTimestamp(), 'entropy' => $fileOperation->getEntropy(),
'standardDeviation' => $fileOperation->getStandardDeviation(), 'command' => $fileOperation->getCommand(), 'fileNameEntropy' => $fileOperation->getFileNameEntropy(), 'fileClass' => $fileOperation->getFileClass(), 'fileNameClass' => $fileOperation->getFileNameClass(), 'suspicionClass' => $fileOperation->getSuspicionClass()];
- $sequenceForAnalyzer[] = $fileOperation;
+ $fileOperationSequence[] = $fileOperation;
+ }
+ if (count($fileOperationSequence) > 0) {
+ $sequenceResult = $this->sequenceAnalyzer->analyze(0, $fileOperationSequence);
+ return new JSONResponse(['status' => 'success', 'suspicion_score' => $sequenceResult->getSuspicionScore(), 'sequence' => $jsonSequence], Http::STATUS_OK);
+ } else {
+ return new JSONResponse(['status' => 'error', 'message' => 'The file(s) requested do(es) not exist.']);
}
- $sequenceResult = $this->sequenceAnalyzer->analyze(0, $sequenceForAnalyzer);
- return new JSONResponse(['status' => 'success', 'suspicion_score' => $sequenceResult->getSuspicionScore(), 'sequence' => $sequenceResults], Http::STATUS_OK);
} else {
return new JSONResponse(['status' => 'error', 'message' => 'Sequence is to short.'], Http::STATUS_OK);
}
@@ -273,6 +287,9 @@ class ScanController extends OCSController
$fileOperation->setCommand(Monitor::WRITE);
$fileOperation->setTimestamp($lastActivity['timestamp']);
}
+ if (!($node instanceof File)) {
+ throw new NotAFileException();
+ }
$fileOperation->setOriginalName($node->getName());
$fileOperation->setType('file');
$fileOperation->setMimeType($node->getMimeType());
@@ -319,7 +336,12 @@ class ScanController extends OCSController
$rows[] = $row;
}
$result->closeCursor();
- return array_pop($rows);
+ if (is_array($rows)) {
+ return array_pop($rows);
+ } else {
+ $this->logger->debug('getLastActivity: No activity found.', array('app' => Application::APP_ID));
+ return 0;
+ }
}
/**
diff --git a/lib/Exception/NotAFileException.php b/lib/Exception/NotAFileException.php
new file mode 100644
index 0000000..5ec487c
--- /dev/null
+++ b/lib/Exception/NotAFileException.php
@@ -0,0 +1,26 @@
+<?php
+
+/**
+ * @copyright Copyright (c) 2018 Matthias Held <matthias.held@uni-konstanz.de>
+ * @author Matthias Held <matthias.held@uni-konstanz.de>
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\RansomwareDetection\Exception;
+/**
+ * Exception if object is not a file
+ */
+class NotAFileException extends \Exception {}