Detect and warn about suspicious IPs logging into Nextcloud
Перейти к файлу
Simon L af091f4977
Merge pull request #719 from nextcloud/bugfix/noid/compile-js
Compile JS
2022-10-10 09:15:19 +02:00
.github Merge pull request #719 from nextcloud/bugfix/noid/compile-js 2022-10-10 09:15:19 +02:00
.tx [tx-robot] Update transifex configuration 2022-10-01 02:59:47 +00:00
appinfo Update info.xml 2022-09-22 19:20:22 +02:00
doc Rename table so the primary key is not too long 2022-09-22 10:07:40 +02:00
img add icon to notification 2021-09-28 14:22:11 +02:00
js Commit compiled JS 2022-10-10 07:10:48 +00:00
l10n [tx-robot] updated from transifex 2022-08-06 03:23:32 +00:00
lib Add return type hints for occ commands 2022-10-06 12:25:15 +02:00
screenshots Add screenshots 2019-04-04 10:12:54 +02:00
src Bump webpack-merge from 4.2.2 to 5.1.3 2020-08-31 08:52:45 +02:00
templates Show stats on the admin settings page 2019-02-28 16:43:13 +01:00
tests Update master php testing versions 2022-04-07 12:06:19 +02:00
.babelrc.js Show stats on the admin settings page 2019-02-28 16:43:13 +01:00
.gitignore Commit compiled JS 2022-10-10 07:10:48 +00:00
.l10nignore Ignore js/ from translations 2022-10-07 16:15:21 +02:00
.nextcloudignore Bump nextcloud/coding-standard from 0.5.0 to 1.0.0 2022-06-15 16:10:30 +02:00
.php-cs-fixer.dist.php Bump nextcloud/coding-standard from 0.5.0 to 1.0.0 2022-06-15 16:10:30 +02:00
CHANGELOG.md v4.2.0 RC1 2022-06-27 16:32:18 +02:00
COPYING Fix license 2019-04-02 10:05:13 +02:00
README.md README.md: Fixed git clone command 2019-09-18 11:52:55 +02:00
composer.json Bump league/flysystem to v2.5.0 2022-10-06 17:00:49 +02:00
composer.lock Bump league/flysystem to v2.5.0 2022-10-06 17:00:49 +02:00
krankerl.toml Migrate to .nextcloudignore file 2020-02-11 09:19:29 +01:00
package-lock.json Bump @vue/babel-preset-app from 4.5.13 to 5.0.8 2022-10-07 13:52:44 +00:00
package.json Bump @vue/babel-preset-app from 4.5.13 to 5.0.8 2022-10-07 13:52:44 +00:00

README.md

🔮 Nextcloud Suspicious Login Detection

Detect and warn about suspicious IPs logging into Nextcloud

Downloads Build Status Dependabot Status

The app is still under development, so its time for you to get involved! 👩‍💻

How it works

Data collection

Once this app is enabled, it will automatically start tracking (IP, uid) tuples from successful logins on the instance and feed them into the login_address table. This insert operation is executed for the majority of requests (client authenticate on almost all requests) and therefore has to be fast. In a background job, these rows will be transformed into an aggregated format that is suitable for the training of the neural net. The (IP, uid) tuple becomes (IP, uid, first_seen, last_seen, seen) so that we know which (IP, uid) tuple has been seen first and last. The aggregated data is a compressed format of the raw data. The original data gets deleted and thus the database does not need much space for the collected login data.

Neural net

When enough data is collected – which by default is 60 days (!) – a first training run can be started.

The app registers a background job that invokes the training once a day. As long as there isn't sufficient data, no trained model is generated.

Manual training

The training can also be invoked via the OCC command line tool:

php -f occ suspiciouslogin:train

This command uses several sensible default that should work for instances of any size. The --stats flag is useful to see the measured performance of the trained model after the training finishes. The duration of the training run depends on the size of the input training set, but is usually between two to 15 minutes.

The full list of parameters, their description and default values can be seen with

php -f occ suspiciouslogin:train --help

Hyper parameter optimization (optional)

To find the best possible parameters for the training it's possible to start a hyper parameter optimization run via the CLI:

php -f occ suspiciouslogin:optimize

This command uses the heuristic simulated annealing algorithm to find optimal parameter sets in the multidimensional parameter space. By default this will do 100 steps consisting of five training runs per step, hence this command might take a few days to execute on large instances. On smaller ones it will also take a few hours.

Login classification

As soon as the first model is trained, the app will start classifying (IP, uid) tuples on login. In contrast to the data collection it won't consider requests authenticated via an app password as suspicious. Should it detect a password login where the (IP, uid) is classified as suspicious by the trained model, it will add an entry to the suspicious_login table, including the timestamp, request id and URL.

Development setup

  1. ☁ Clone the app into the apps folder of your Nextcloud: git clone https://github.com/nextcloud/suspicious_login.git
  2. 💻 Run npm i or krankerl up to install the dependencies
  3. 🏗 To build the Javascript whenever you make changes, run npm run dev
  4. ☁ Enable the app through the app management of your Nextcloud or run krankerl enable
  5. 👍 Partytime! Help fix some issues and review pull requests