Commit graph

572 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
d423e7addc
Bump versions to v1.6.9
Some checks failed
CI - build eBPF modules / build (6.0, 1.6.0) (push) Has been cancelled
Test resources validation / Install tools (push) Has been cancelled
Build status / Build (push) Has been cancelled
2025-04-28 01:39:04 +02:00
Gustavo Iñiguez Goia
dd39fe3060
make connections flushing configurable
By default when adding the interception rules, we were killing all
existing connections, to force them go to the netfilter queue.

However in some environments this is not acceptable, so now it's configurable.

Besides, we were doing this only for nftables, so now it also works for
iptables.

This option will only take effect if FlushConnsOnStart is true, and the
user has (re)configured the ProcMonitorMethod option (typically on
start, or when changing it manually).

cherry picked from commits:
  8e9c1d2178
  8935bfe6b0

related commits:
  661e3da48f
  1e6d2d464b
2025-04-25 23:48:11 +02:00
Gustavo Iñiguez Goia
ae1ace693d
allow to configure GC percentage
Added config option to set how often the garbage collector runs.

For example:

  "Internal": {
      "GCPercent": 75
  },

If this option is not specified in the config file, or the value
is 0, then the GC percentage is not configured.

More info:

https://pkg.go.dev/runtime/debug#SetGCPercent

(cherry picked from commit dc43d5913c)
2025-04-25 22:20:18 +02:00
selfdenial
113d41bc98 chore: update version to 1.6.8
Synchronize version with latest release & tag.
2025-03-30 13:35:39 -06:00
Gustavo Iñiguez Goia
a1b4885468
fixed crash compiling unknown rules operator
If a rule contained an unknown rule type or unknown operand, the daemon
crashed.

Issue: #1295
2025-03-18 01:09:00 +01:00
Gustavo Iñiguez Goia
ae9aa40c37
deserialize rules operator list correctly
In b93051026e we disabled sending/parsing
list operators as JSON strings. Instead, now it's sent/parsed as
protobuf Rule, and saved to disk as JSON array, which ease the task of
manually creating new rules if needed.

This change was missing in the previous commit.

(cherry picked from commit 2fc9ed276b)
2024-06-21 14:35:15 +02:00
Gustavo Iñiguez Goia
987a227a42
updated rules tests
(cherry picked from commit 40b738ffea)
2024-06-21 14:11:54 +02:00
Gustavo Iñiguez Goia
fe66f9aa17
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

(cherry picked from commit b93051026e)
2024-06-21 11:38:46 +02:00
Gustavo Iñiguez Goia
4e7f1aeae7
Bumped versions to v1.6.6 2024-06-20 00:45:33 +02:00
Gustavo Iñiguez Goia
7519db7aeb
fixed loading rules when Created field is a timestamp
When exporting rules from the GUI, the Created field was exported as
timestamp. Importing rules worked fine, because json.Marshall() accepts
the timestamp format.

However, when the daemon was loading a rule with the Created field as
timestamp, since the field was defined as time.Time, it expected a RFC3339
string (https://pkg.go.dev/time#Time.UnmarshalJSON)
so it failed to parse the timestamp and the rule was not loaded.

Now the field is defined as string, it's always saved as RFC3339, and if
we fail to parse these fields we'll use a temporary date instead of
failing loading the rule.

More info:
https://github.com/evilsocket/opensnitch/issues/1140#issuecomment-2140904847

(cherry picked from commit 58aa979cae)
2024-06-19 00:16:29 +02:00
Gustavo Iñiguez Goia
496e9055a1
Remove duplicate regex in system.go for -check-requirements
(cherry picked from commit fa2f1068f6)
2024-06-14 01:18:39 +02:00
Gustavo Iñiguez Goia
93a3fb7eb6
added more kernel config paths for checking system requirements
On Fedora Silverblue the kernel config of the current kernel is under
/usr/lib/modules/<kernel>/config

(cherry picked from commit 81dd625a1c)
2024-06-13 22:13:56 +02:00
Gustavo Iñiguez Goia
ead45b062c
bumped minimum require go version to 1.17 2024-06-13 00:49:35 +02:00
Gustavo Iñiguez Goia
91190c80aa
added Reject to the list of DefaultActions(s)
We only offered two options for the DefaultAction option: allow/deny.

Since a long time ago we support "reject"ing connections, but it was not
configurable as the DefaultAction.

(cherry picked from commit f5f30b1e58)
2024-06-13 00:09:00 +02:00
Gustavo Iñiguez Goia
8895d6f024
disable (process) ebpf events when to many errors
if an invalid opensnitch-procs.o module was loaded, we were flooding
the log with errors.
In these cases stop processing events after 20 errors (random, we should
have no errors).

This may occur if the module is malformed (valid .o ebpf module but
different structs, etc), or when loading modules from other versions.

(cherry picked from commit 0a911ef791)
2024-06-12 23:58:10 +02:00
Gustavo Iñiguez Goia
da99686ab0
clean dns ebpf hooks on exit
We were not reacting to common exit signals, only to kill/interrupt
signals, so the DNS uprobes were never properly removed. Each uprobe
has the PID of the daemon in the identifier, so in theory, there
shouldn't be conflicts, but better clean our probes on exit.

previous to this commit with the daemon running
(and lot of starts/stops):

~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
367

after stopping the daemon:
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
364

~ # > /sys/kernel/debug/tracing/uprobe_events
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
0

~ # cp opensnitchd-new /usr/bin/opensnitchd ; service opensnitchd start
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
3
~ # service opensnitchd stop
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
0

(cherry picked from commit 785500cd08)
2024-01-28 01:14:15 +01:00
Gustavo Iñiguez Goia
0a8827d051 added more debug info to the dns ebpf hook
Added the path to the libc as well as the calculated offset for the
uprobe.
Don't return on the first error found loading a uprobe, instead try all
the uprobes and return if the loaded uprobes are 0.

(cherry picked from commit 55678b4d3b)
2024-01-26 14:53:43 +01:00
Gustavo Iñiguez Goia
34b595e50a
updated daemon/ui tests
They were failing when building the deb packages.
2024-01-24 20:22:34 +01:00
Gustavo Iñiguez Goia
871238e07a
on errors stop established conns monitor
There's a long running task that monitors established connections every
~2s.

When a connection is not found via ebpf or proc, sometimes it's found
there so we can use the inode to search for the process.

However on some systems the netlink call to dump the sockets may fail
continuously, wasting resources. It'll also fail if you block connections
to port 0 (common case for ICMP packets).

So if there're too many errors dumpng the sockets, stop this task for
these cases.
2024-01-21 11:13:07 +01:00
Gustavo Iñiguez Goia
43477ebcbe
rules: fixed typo checking proc arguments 2024-01-15 21:56:55 +01:00
Gustavo Iñiguez Goia
b9ec5242f2
strings concatenation improvements
Use strings.Join() to concatenate strings, instead of Sprint*(), for
better performance.
2024-01-15 17:44:32 +01:00
Gustavo Iñiguez Goia
0340e77aa1
added go.sum 2024-01-14 19:15:53 +01:00
Gustavo Iñiguez Goia
fdba19c0c3
structs fields reorganized
Structs' fields reorganized based on fieldalignment tool feedback.
2024-01-13 22:15:23 +01:00
Gustavo Iñiguez Goia
60c6ac4aa8
Bump daemon and ui versions to 1.6.5 2024-01-10 01:05:34 +01:00
Gustavo Iñiguez Goia
1ae20c3aa3
ebpf: fixed getting ppid, skip failed execve's
- Fixed getting ppid (precompiled .o won't probably work).
 - Skip failed execve* calls.

(cherry picked from commit 68c2c8ae1a)
2024-01-09 11:53:23 +01:00
Gustavo Iñiguez Goia
eafb70fb55
fixed loading dns ebpf module
Closes #1076

(cherry picked from commit 159494d1e2)
2024-01-09 10:16:23 +01:00
Gustavo Iñiguez Goia
5c6da0a8ab
allow to configure ebpf modules path
Now it's possible to configure eBPF modules path from the
default-config.json file:
 "Ebpf": {
   "ModulesPath": "..."
 }

If the option is not provided, or if it's empty, we'll keep loading from
the default directories:

 - /usr/local/lib/opensnitchd/ebpf
 - /usr/lib/opensnitchd/ebpf
 - /etc/opensnitchd/ebpf (deprecated, will be removed in the future).

Closes #928

(cherry picked from commit ffb76683aa)
2024-01-08 23:49:36 +01:00
Gustavo Iñiguez Goia
946799b5e9
removed checksum references 2024-01-08 22:15:08 +01:00
Gustavo Iñiguez Goia
f16b27afb9
updated ui/client tests
(cherry picked from commit 6873fd3a2d)
2024-01-08 18:23:18 +01:00
Gustavo Iñiguez Goia
6bd1fe8b1e
allow to configure rules and config file paths
- Added cli option -config-file to specify an alternate path to the
   config file.
 - Allow to configure rules path from the configuration file (cli option
   takes precedence).
 - Default options are now /etc/opensnitchd/rules and
   /etc/opensnitchd/default-config.json. Previously the default rules
   directory was "rules" (relative path).

Closes #449

(cherry picked from commit 211c864d76)
2024-01-08 18:21:43 +01:00
Gustavo Iñiguez Goia
1608ab7730
fixed proc/self/exe path 2024-01-08 17:10:09 +01:00
Gustavo Iñiguez Goia
0dde6f57ea fixed leak checking fw status
(cherry picked from commit 9cee3b3a73)
2024-01-08 15:56:25 +01:00
Gustavo Iñiguez Goia
24fd94c168 netfilter: do not unbind the queues on exit
On exit we were calling nfq_unbind_pf for AF_INET and AF_INET6, which
usually stcuked the daemon for a very long time, and other times
caused a segfault.

According to the docs (..), calling nfq_destroy_queue() is enough to
exit cleanly:
"This call also unbind from the nfqueue handler, so you don't have to
call nfq_unbind_pf."
https://netfilter.org/projects/libnetfilter_queue/doxygen/html/group__Queue.html#ga32a1461e9a36c95a03cb4476109f33bb

Closes #919

(cherry picked from commit 430c280687)
2024-01-08 15:55:58 +01:00
Gustavo Iñiguez Goia
f82431b642 replace /proc/self from bin paths
Sometimes we receive /proc/self/exe as the path of the process (electron
apps).
Since a couple of systemd versions ago, some processes spawned by
systemd are reported as /proc/self/fd/<number>.

In these cases reading the symbolic link /proc/<pid>/exe points to the
file on disk.

(cherry picked from commit fb2c9893d0)
2024-01-08 15:55:32 +01:00
Gustavo Iñiguez Goia
ce7c3f8002
Bump versions to v1.6.2 2023-07-31 00:36:33 +02:00
Gustavo Iñiguez Goia
00a1dc4249
added Created column to the rules list
Closes #683
2023-07-30 18:16:56 +02:00
Gustavo Iñiguez Goia
efded9edab
added icmp destination-unreachable to system-fw.json
Allow destination-unreachable ICMP types by default, not to display ICMP
pop-ups under certain circumstances.
More info:
https://github.com/evilsocket/opensnitch/discussions/946#discussioncomment-6035934
2023-07-26 11:40:17 +02:00
Gustavo Iñiguez Goia
57a7f5b63d
removed debugging logs, fixed build 2023-07-25 02:11:35 +02:00
Gustavo Iñiguez Goia
26b8415925
force to reestablish non-local connections on start
When we start to intercept connections, we flush out the conntrack
table, to force already established connections reconnect again so we
can intercept them, and let the user choose if allow or deny them.

Since we no longer use conntrack states to intercept TCP connections, we
now close existing connections, leaving to the applications reestablish
them again.
Local connections are excluded, because it may cause problems with some
local servers.

Both options interfere with the established connections, so you may
experience ocasional network interruptions when enabling the
interception for the first time.

Discussion: #995
2023-07-25 01:42:54 +02:00
Gustavo Iñiguez Goia
d1598fdf67
sys fw: allow to use wildcards to match interfaces
Now it's possible to use "br*" to match all network interfaces that
start with "br".

Closes #996
2023-07-24 16:11:12 +02:00
Gustavo Iñiguez Goia
a828ccdcba
reorganized sockets code
Moved sockets code block to netlink package.
2023-07-24 11:18:09 +02:00
Gustavo Iñiguez Goia
662cd2eda3
Better ebpf module errors
Report to the GUI and the logs, whether the modules have been found
or not, and if found, whether there have been any errors loading them.

Closes #868
2023-07-23 23:35:19 +02:00
Gustavo Iñiguez Goia
cb4d82f9ac
respect packet mark when requeueing packet 2023-07-23 22:33:08 +02:00
Gustavo Iñiguez Goia
8b4c8922c5
Added sample rule to allow localhost connections 2023-07-23 22:30:49 +02:00
Gustavo Iñiguez Goia
28f98e4fb6
misc
- Removed 'rules' from .gitignore
- Fixed typo.
2023-07-23 22:29:47 +02:00
Gustavo Iñiguez Goia
6e340a7e39
remote loggers improvements
- Remote logger: fixed a couple of leaks.
- Allow to use multiple remote loggers.
- Allow to use rfc3164 format.
2023-07-23 22:27:28 +02:00
Gustavo Iñiguez Goia
cdf6497ea7
Bump versions to v1.6.1 2023-07-23 22:18:58 +02:00
Gustavo Iñiguez Goia
f652174f75
changed addrs polling by async events
For the eBPF monitoring method, we listed and stored local addresses
every second, so that we could later check if the source IP of an
outbound connection was local or not, because sometimes we received
outbound connections like:
 443:1.1.1.1 -> 192.168.1.123:12345

This could have been alread solved on this change e090833, so maybe
we no longer need this code.

 - Now we subscribe to local addresses events, to receive add/remove
   events asynchronously, without having to list local addrs
   every second, alliviating CPU usage.

 - Fixed creating context object to cancel subroutines. It was not
   working properly when switching between proc monitor methods.
2023-07-23 21:14:47 +02:00
Gustavo Iñiguez Goia
e090833d29
intercept packets only with the SYN flag set
Using "ct state NEW" to intercept packets causes some undesired effects:
  We intercept packets that not only have the SYN flag set, like ACK,
  ACK+PSH or SYN+ACK. Mainly response packets.

  This means that the IPs are not always in the expected order:
  443:1.1.1.1 -> 192.168.1.123:12345
  which causes sometimes not to obtain the process of the connection,
  because the connection in the system appears as
  12345:192.168.1.123 -> 1.1.1.1:443

Intercepting packets with *only* the SYN flag set seems to resolve
this problem.
2023-07-23 15:14:05 +02:00
Gustavo Iñiguez Goia
c97c322bcb
allow to secure (abstract) unix socket comms
- Allow to use SSL certificates to secure unix sockets communications.
- Allow to use abstract users sockets for server and nodes.

Go gRPC doesn't seem to understand unix sockets addresses that start
with "unix-abstract:", and python gRPC doesn't seem to understand
"unix:@" addresses.
Therefore, on the server (python gRPC) we use the format "unix:@" to
specify the address where the server will listen on, and rewrite it to
"unix-abstract:" before starting the server.

Note about certs and abstract unix sockets:
 When creating the SSL certificates, you'll have to specify the
 address of the unix socket as the Common Name of the certificates:

  Address: "unix:@my-abstract-socket"

  Common Name: @my-abstract-socket
2023-07-19 01:31:13 +02:00