Commit graph

557 commits

Author SHA1 Message Date
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
Gustavo Iñiguez Goia
aa7b1e1a02
misc: removed debug msg, fixed warning msg
- Fixed displaying verdict warning message.
 - Removed debug message.
2023-07-17 16:48:44 +02:00
Gustavo Iñiguez Goia
8740755f64
sys fw: report errors to the GUI after reloading
- Send errors to the server (GUI) if there's any error when reloading
   the system fw rules (far from being perfect/optimal, needs a
   rewrite).
 - Don't load the configuration after saving it, let the watcher reload
   it on write change to avoid double reload/duplicated errors.
2023-07-15 20:32:42 +02:00
Gustavo Iñiguez Goia
3de24febf8
sys fw: improved rules errors logs 2023-07-13 17:24:38 +02:00
Gustavo Iñiguez Goia
ad1cdd4015
tests: better sys-fw log,meta and ip tests 2023-07-12 12:53:13 +02:00
Gustavo Iñiguez Goia
eaec4a825c
tests: added sys-fw conntrack tests 2023-07-11 15:32:15 +02:00
Gustavo Iñiguez Goia
3ca5645c7e
tests: added quota tests 2023-07-11 13:53:01 +02:00
Gustavo Iñiguez Goia
7441aa2ccc
tests: rewritten nat tests
Move common nat checks to its own file.
2023-07-11 13:15:26 +02:00
Gustavo Iñiguez Goia
c2e6032a86
tests: added needed helpers 2023-07-11 01:16:23 +02:00
Gustavo Iñiguez Goia
dad8c0c65d
tests: added queue, nat tests
- Added queue, snat, dnat, redirect, tproxy and masquerade tests.
- Return errors if verdict parameters are not formatted as expected.
2023-07-11 00:57:15 +02:00
Gustavo Iñiguez Goia
6ddd4dcee6
tests: added meta tests, improved ip tests 2023-07-09 23:05:12 +02:00
Gustavo Iñiguez Goia
b1ebc0eb22
sys fw: fixed setting marks on packets
Fix for meta mark set 666
2023-07-09 23:03:50 +02:00
Gustavo Iñiguez Goia
a18404fba9
tests: added sys-fw ip and iface tests
- Added ip daddr, saddr tests.
- Added basic iface tests.
2023-07-08 21:50:46 +02:00
Gustavo Iñiguez Goia
603c4ab39a
tests: added sys-fw verdict tests
- Added accept, drop, return and jump tests.
- Added reject tests.
2023-07-07 13:56:25 +02:00
Gustavo Iñiguez Goia
1a063d10e2
tests: added new sys fw tests
- Added counter tests.
- Added ethernet addresses tests.

Added comments to some functions.
2023-07-07 00:46:09 +02:00
Gustavo Iñiguez Goia
e268a88cff
tests: added sys fw ports tests 2023-07-06 17:59:30 +02:00