Commit graph

47 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
6b3a5da343
Control checksums feature from a global cfg item
Previously it was enabled only if at least 1 rule had a checksum item
configured.
Enable by default md5.
2023-11-10 11:28:54 +01:00
Gustavo Iñiguez Goia
b93051026e
rules: improved operator list parsing and conversion
Previously when creating a new rule we followed these steps:
 - Create a new protobuf Rule object from the ruleseditor or the
   pop-ups.
 - If the rule contained more than one operator, we converted the
   list of operators to a JSON string.
 - This JSON string was sent back to the daemon, and saved to the
   DB.
 - The list of operators were never expanded on the GUI, i.e., they
   were not saved as a list of protobuf Operator objects.
 - Once received in the daemon, the JSON string was parsed and
   converted to a protobuf Operator list of objects.
   Both, the JSON string and the list of protobuf Operator objects were
   saved to disk, but the JSON string was ignored when loading the
   rules.

Saving the list of operators as a JSON string was a problem if you
wanted to create or modify rules without the GUI.

Now when creating or modifying rules from the GUI, the list of operators
is no longer converted to JSON string. Instead the list is sent to the
daemon as a list of protobuf Operators, and saved as JSON objects.

Notes:
 - The JSON string is no longer saved to disk as part of the rules.
 - The list of operators is still saved as JSON string to the DB.
 - About not enabled rules:
   Previously, not enabled rules only had the list of operators as JSON
   string, with the field list:[] empty.
   Now the list of operators is saved as JSON objects, but if the rule
   is not enabled, it won't be parsed/loaded.

Closes #1047
2023-10-09 14:55:15 +02:00
Gustavo Iñiguez Goia
81a964bf83
updated rules tests 2023-09-22 01:21:27 +02:00
Gustavo Iñiguez Goia
7a9bb17829
allow to filter connections by process checksum
Now you can create rules to filter processes by checksum. Only md5 is
available at the moment.

There's a global configuration option that you can use to enable or
disable this feature, from the config file or from the Preferences
dialog.

As part of this feature there have been more changes:

   - New proc monitor method (PROCESS CONNECTOR) that listens for
     exec/exit events from the kernel.
     This feature depends on CONFIG_PROC_EVENTS kernel option.

   - Only one cache of active processes for ebpf and proc monitor
     methods.

More info and details: #413.
2023-09-22 00:36:26 +02:00
Gustavo Iñiguez Goia
ec31ee0814
sys fw: added option to filter by MAC 2022-10-23 11:36:51 +02:00
Gustavo Iñiguez Goia
736c3f9c51
rules: make .json files accessible only to root by default 2022-10-20 21:01:29 +02:00
Gustavo Iñiguez Goia
743ef71d7e rules: don't load rules that fail to compile
Be sure that we don't load invalid regexp rules.

related: #536
2021-11-12 12:08:31 +01:00
Gustavo Iñiguez Goia
8d3540f7f9 added action reject
When blocking a connection via libnetfilter-queue using NF_DROP the
connection is discarded. If the blocked connection is a DNS query, the app
that initiated it will wait until it times out, which is ~30s.

This behaviour can for example cause slowdowns loading web pages: #481

This change adds the option to reject connections by killing the socket
that initiated them.

Denying:
    $ time telnet 1.1.1.1 22
    Trying 1.1.1.1...
    telnet: Unable to connect to remote host: Connection timed out

    real	2m10,039s

Rejecting:
    $ time telnet 1.1.1.1 22
    Trying 1.1.1.1...
    telnet: Unable to connect to remote host: Software caused connection abort

    real	0m0,005s
2021-09-12 10:54:24 +02:00
Gustavo Iñiguez Goia
cec619aa3b removed debugging log message 2021-07-16 23:24:52 +02:00
Gustavo Iñiguez Goia
3d11134363 fixed race condition when deleting a rule from disk 2021-06-05 16:33:50 +02:00
Gustavo Iñiguez Goia
ff40e99f77 tests, rules: added Duration change test
Verify that if the user changes the Duration of a temporary rule, the
old timer does not delete the rule.
2021-06-03 17:35:48 +02:00
Gustavo Iñiguez Goia
403c218209 prevent deleting temporary rules when the Duration changes
When the Duration of a rule changed (from 1h to 5m, from 5m to until
restart, etc), the timer of the old rule was fired, causing deleting the
rule from the list.

This erroneous behaviour could be one of the reasons of #429
2021-06-01 23:52:02 +02:00
Gustavo Iñiguez Goia
60414931d6 when deleting a rule stop lists of domains monitor 2021-05-25 22:21:05 +02:00
Gustavo Iñiguez Goia
408150073a fix deadlock
closes #365
2021-03-04 12:10:53 +01:00
Gustavo Iñiguez Goia
c7d93d83a5 improved rules (re)loading
- Delete lists of domains if the rule about to change is of type Lists.
- Monitor the lists of domains, and reload them if they're modified.
- Delete rules from disk when the Duration changes from
  Always (saved on disk) to !Always (temporary).
- After the above operation a fsnotify Remove event is fired. Don't
  delete the rule from memory if it's temporary.
- Rules are only compiled if they're enabled, avoiding unnecessary
  allocations.
2021-03-01 12:41:35 +01:00
Gustavo Iñiguez Goia
44e8561e0c load/reload rules from disk one by one
Any rule changed on disk caused reloading of all rules, usually
up to three times. This caused some problems.

- Don't compile Operators if the rule is disabled.
- Empty lists of domains if the user disables the rule.
- Delete rule from disk if the duration is not Always anymore.
2021-02-27 01:39:04 +01:00
Gustavo Iñiguez Goia
4532c2513e delete loaded lists when needed
There're some situations where we need to delete loaded lists:
 - When an enabled rule of type Lists is disabled (after changed on
   disk, or when configured from the GUI).
 - When an enabled rule of type List with an Operator of type Lists is
   disabled.
2021-02-25 20:09:23 +01:00
Gustavo Iñiguez Goia
26671ded24 added support for list of domains
Initial support to filter connections using lists of domains.

The lists must be in hosts format:
- 0.0.0.0 www.domain.com
- 127.0.0.1 www.domain.com

From the rules editor, create a new rule, and select
[x] To this lists of domains

Select a directory with files in hosts format, select [x] Priority rule,
select [x] Deny and click on Apply.

An example of a list in hosts format:
https://www.github.developerdan.com/hosts/lists/ads-and-tracking-extended.txt

Note: you can also add a list of domains to allow, not only domains to
block.

TODOs:
- support for URLs besides directories (local lists).
- support for scheduled updates of the above URLs.

related #298
2021-02-25 13:38:48 +01:00
Gustavo Iñiguez Goia
b066b11c47 improved complex rules
Every rule has an entry point besides a constructor, which configures
all it needs to match connections, based on user defined criteria (ip,
regexp, etc).

This only needs to be done the first time we load a rule, because the
fields of a rule are static. However for rules of type "lists" we were
iniatializing each rule of this type once per connection that it
matched.
2021-02-19 01:03:45 +01:00
freddii
9e4248e923
fixed german translation (#327)
* fixed german translation

* fixed typing mistake

Co-authored-by: freddii <https://freddii@github.com>
2021-01-05 11:53:12 +01:00
Gustavo Iñiguez Goia
3a3363cb9a rules: delete file from disk if Duration changes
If the user changed the Duration of a rule, from Always to !Always
(temporary), we were not deleting from disk the file of the old
rule.
2021-01-04 12:48:05 +01:00
Gustavo Iñiguez Goia
e59133beb2 rules: skip checking not enabled rules 2020-12-18 16:42:34 +01:00
Gustavo Iñiguez Goia
4443673ed1 fixed how we check rules
- Rules are checked in alphabetical order.
- Deny and Priority rules must take precedence.
- If a rule matches and it's Allow-NoPriority, then return the rule.
- Otherwise we'll return nil.
2020-12-15 16:09:28 +01:00
Gustavo Iñiguez Goia
e13015ce67 updated import paths 2020-12-09 18:18:42 +01:00
Gustavo Iñiguez Goia
820a6f2930 added option to set priority on the rules
If a rule has the priority flag set, no others rules will be checked.
So if you name the rule as 000-allow-xx and set the priority flag, the
rule wil lbe the only one that will be checked if it matches a
connection.

See #36 to know more on this feature.
2020-10-23 00:02:16 +02:00
Gustavo Iñiguez Goia
c2ee61076d sort rules by name
Sort rules by name, so they're checked in alphabetical order.

This way, you can place deny rules at the top of the list to get better
performance, since it won't check the rest of the rules.

Discussion: #36
2020-10-21 08:13:41 +02:00
Gustavo Iñiguez Goia
6d24c5464c fixed race conditions when manipulating rules 2020-06-20 18:58:59 +02:00
Gustavo Iñiguez Goia
cfc32cbd1c fixed race condition when deleting a rule 2020-06-14 20:30:19 +02:00
Gustavo Iñiguez Goia
061d7a2ecd ignore malformed rules
Don't exist if a rule is malformed.

Reported by @jonau01 here #17
2020-05-11 10:39:56 +02:00
Gustavo Iñiguez Goia
c44fdf4342 added delete, getall, replace to the rules loader 2020-05-10 17:33:39 +02:00
Gustavo Iñiguez Goia
cc27be2bae Added initial support for advanced rules (lists)
Probably not the best UI, just the one I came up with.
2019-11-20 10:27:28 +01:00
Gustavo Iñiguez Goia
912f85f5d1 Added more timeout options (30s, 5m, 15m, 30m, 1h)
Added 30s, 5m, 15m, 30m and 1h timeout options to deny or allow
connections.

It helps to avoid repetitive new connection dialogs, while at the same
time it allows you to deny/allow a connection for a short period of time,
and apply the default for the rest.
2019-11-09 01:35:13 +01:00
Gustavo Iñiguez Goia
ce71c383a9 fixed missing funcs declarations and non used var 2019-10-21 00:04:15 +02:00
Gustavo Iñiguez Goia
067d0d8eed Merge branch 'fixed_unwanted_rules_reloading' of github.com:gustavo-iniguez-goya/opensnitch into main 2019-10-20 23:46:04 +02:00
Gustavo Iñiguez Goia
a7e9b5072f project import paths changed 2019-10-20 21:51:35 +02:00
Gustavo Iñiguez Goia
843924fff4 Fixed unwanted rules reloading after adding a new one
fixes #271
2019-08-13 19:19:17 +02:00
evilsocket
3a5932de38
misc: small fix or general refactoring i did not bother commenting 2018-04-10 20:04:59 +02:00
evilsocket
6803808137
misc: small fix or general refactoring i did not bother commenting 2018-04-10 14:21:29 +02:00
evilsocket
fb5ccb03a3
added the number of loaded rules in the statistics 2018-04-08 17:20:37 +02:00
evilsocket
ead3725bbe
added rules live reloading (closes #128) 2018-04-08 16:36:12 +02:00
evilsocket
a33c463ffb
support rules with type=regexp (closes #127) 2018-04-07 13:52:25 +02:00
evilsocket
e9902d2761
misc: small fix or general refactoring i did not bother commenting 2018-04-06 18:31:16 +02:00
evilsocket
b6bdeb7173
misc: small fix or general refactoring i did not bother commenting 2018-04-05 23:56:07 +02:00
evilsocket
8cd2917ba1
misc: small fix or general refactoring i did not bother commenting 2018-04-05 20:16:04 +02:00
evilsocket
50e8be10f3
misc: small fix or general refactoring i did not bother commenting 2018-04-05 16:27:48 +02:00
evilsocket
540335056b
misc: small fix or general refactoring i did not bother commenting 2018-04-03 14:51:58 +02:00
evilsocket
534ec8cd73
misc: small fix or general refactoring i did not bother commenting 2018-04-02 05:25:32 +02:00