Commit graph

663 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
56eddafca8
loggers: handle errors properly
RemoteLogger: don't create the logger if we can't connect with the
server.
2025-03-29 17:21:19 +01:00
Gustavo Iñiguez Goia
aab65908c7
fixed condition checking operator Data field 2025-03-18 02:09:53 +01:00
Gustavo Iñiguez Goia
5828ba861c
fixed crash compiling unknown operator rules
If a rule contained an unknown rule type or unknown operand, the daemon
crashed.

Closes: #1295
2025-03-18 01:38:31 +01:00
Gustavo Iñiguez Goia
7b66e598b6
loggers: simplify structed data conversions
- unify conversion for rfc3164 and rfc5424 formats.
2025-03-11 20:18:34 +01:00
Gustavo Iñiguez Goia
98b8b06018
remote loggers improvements
- Convert remote syslog to remote. There's no real difference between
   both, and the code was the same.
    Maybe we could limit the logging formats allowed.
 - Remote logger: Added option to reopen the connection after n errors
   trying to send messages.
2025-03-11 17:57:13 +01:00
Gustavo Iñiguez Goia
da4761f1d6
log checksums and proctree for syslog formats
- Log the checksums and process tree when using rfc3164 and rfc5424
   formats.
 - Minor performance improvements.
2025-03-11 17:06:40 +01:00
Gustavo Iñiguez Goia
ac45c4103f
nftables tests: skip TestAddInterceptionChains
tested on several distros with different kernels, as well as in a
private fork and this test doesn't fail.

So until we figure out why it's failing here, let's skip it for now.
2025-03-10 17:02:38 +01:00
Gustavo Iñiguez Goia
221923da73
improved loggers , remote logger
- Fixed issue when configuring several loggers.
 - Remote logger:
    - open as many connections with the remote server as
      specified in the Workers field.
    - open and handle every connection in each own goroutine.
    - get rid of the locks.
2025-03-10 16:42:19 +01:00
Gustavo Iñiguez Goia
f23c1635ca
minor logging improvements
- Moved Info message to Trace.
 - When applying a default action on a connection (because the daemon is
   not connected to the GUI), log the connection details. It eases the
   task of creating rules without a GUI.
2025-03-04 22:19:07 +01:00
Gustavo Iñiguez Goia
8d1a7de0cc
moved some Debug msgs to Trace 2025-03-03 21:35:31 +01:00
Gustavo Iñiguez Goia
5fdb60dccb
ui,prefs: fixed QueueBypass option. 2025-02-18 23:40:56 +01:00
Gustavo Iñiguez Goia
c6b42890c0
proc.readEnv() improvements
- Minimize the risk of race conditions when we're prompting the user to
   allow/deny a connection, while we're still reading proc's environ file.
   (this was actually a leak).
 - Preallocate the Env map with the expected environ vars.
2025-02-17 14:15:28 +01:00
Gustavo Iñiguez Goia
ce006ee1ac
Bumped nftables lib to v0.2.0 2025-02-14 23:06:50 +01:00
Gustavo Iñiguez Goia
2509d21e30
daemon: allow to filter connections by parent path
Some use cases:

 - Reject connections initiated by certain paths:

   Deny all connections initiated by cron*:
        /usr/sbin/cron
            /usr/bin/curl

     "action": "reject",
     "operator: {
        "type": "list",
        "operand": "list",
        "data": "",
        "list": [
     	   {
                "type": "regexp",
                "operand": "process.parent.path",

                // /usr/bin/crond , /usr/bin/crontab, ...
                "data": "^/usr/(s|)bin/cron"
           }
        ]
     }

 - Reject or Allow connections of binaries launched by another app:

       "action": "allow",
       "operator": {
       	"type": "list",
       	"operand": "list",
       	"data": "",
       	"list": [
       	    {
                "type": "simple",
       	        "operand": "process.parent.path",
       	        "data": "/opt/spotify/bin/spotify"
       	    },
       	    {
       	        "type": "simple",
       	        "operand": "process.path",
       	        "data": "/usr/bin/wget"
       	    }
       	  ]
       }

You can also combine multiple parent paths, to allow a command launched
from a specific chain of processes:

    /usr/lib/systemd/systemd
        /usr/sbin/cron
             /bin/sh
                 /usr/bin/curl

The order is checked from the newest process to the oldest (curl -> sh
-> cron -> systemd)

The operand can be used with any of the existing types (simple, regexp,
etc).

Related: #406
2025-02-13 01:23:31 +01:00
Gustavo Iñiguez Goia
5eebaf40fc improved the process tree retrieval 2025-02-11 01:21:06 +01:00
Gustavo Iñiguez Goia
2a68561557
exclude disabled rules from the active rules
Disabled rules were part of the active rules. The fields were not
evaluated, but we still went through the entire list.

Not adding them to the list of active rules improves matching time,
especially when there're a lot of disabled rules.

It mainly affected when matching rules that were non-priority or
ordered alphabetically, with action Allow.
2025-02-08 15:12:11 +01:00
Gustavo Iñiguez Goia
07a4077a6a
schedule temp rules only if enabled
Avoid scheduling temporary rules if they're not enabled.
2025-02-08 00:37:04 +01:00
Gustavo Iñiguez Goia
1a39122c1d
netstat: dump AF_PACKET sockets from the kernel
We'll try to dump the AF_PACKET sockets from the kernel. If it's not
possible, we'll fallback to read /proc/net/packet.
2025-02-06 01:49:40 +01:00
Gustavo Iñiguez Goia
335f2a783d netstat: allow to list XDP sockets
- daemon: Allow to dump XDP sockets from kernel.
 - ui: Added options to filter by RAW protocol and AF_XDP family.
 - Bumped vishvananda/netlink version to v1.3.0.
 - Updated go.mod and go.sum
2025-02-05 00:05:02 +01:00
Gustavo Iñiguez Goia
83eb82a343 netstat: added option to monitor AF_PACKET sockets
For now, we parse /proc/net/packet, because vishvananda/netlink does not
have support to dump AF_PACKET sockets from kernel.
2025-02-03 21:09:51 +01:00
Gustavo Iñiguez Goia
e403b080bc
cache,events: added debug logs
- Added logs to debug the cache of events.
 - Reduce the expected number of checksums types we may compute
   simultaneously. Probably we only need one.
2025-01-28 23:44:54 +01:00
Gustavo Iñiguez Goia
c1fdfb1d73 cache: delay the deletion time of an process
Sometimes we may receive a connection event after the exit of a
process:

[exec] /bin/xxx, pid 1234
[exit] /bin/xxx, pid 1234
[new conn] pid 1234 -> process unknown (on exec event and no /proc entry)

In these scenarios, we delay the deletion from cache a little
bit, to keep the PID available for a longer time.
2025-01-27 01:08:19 +01:00
Gustavo Iñiguez Goia
ced8410d43
allow to use lists of md5s to block connections
Besides domains, net ranges and IPs, now it's possible to
filter connections by the MD5 of a binary, if it's enabled.
2025-01-24 00:47:02 +01:00
Gustavo Iñiguez Goia
5184c45086
changed dns log messages
Moved some messages to Trace.
2025-01-22 19:19:57 +01:00
Gustavo Iñiguez Goia
f7803ebdcb
added trace logs for packets and ebpf
- Log packets.
 - Log special case.
 - Updated information on some rare cases when intercepting connections
   via eBPF.
2025-01-22 01:06:10 +01:00
Gustavo Iñiguez Goia
7a32f32f7a
netlink/ more improvements
- Fixed serializing netlink data:
   d237ee16c3 (diff-f7f6108a60)
 - misc.
2025-01-22 00:33:10 +01:00
Gustavo Iñiguez Goia
d54f8d4777
netlink/ improvements
- Structs fields alignment fixed.
 - Dump more sockets via netlink, in order to display them with the
   SocketsMonitor task (netstat).
 - Fixed serializing netlink data:
d237ee16c3 (diff-f7f6108a60)
2025-01-22 00:16:17 +01:00
Gustavo Iñiguez Goia
45f5b62978
add new log level TRACE 2025-01-12 00:47:49 +01:00
Gustavo Iñiguez Goia
ff3ac6663a
allow to filter connections by username
Added new rule operand 'user.name' to filter connections by username.

More info #1236
2025-01-09 17:15:28 +01:00
Gustavo Iñiguez Goia
c526907d75
reload procmon method after fw rules
There was a situation where if the ebpf modules path did not exist,
the fw rules were not added, causing the daemon to crash after
connecting to the GUI.
2024-12-17 12:33:38 +01:00
Gustavo Iñiguez Goia
7d2ca8d039
updated network_aliases.json path
- Load network_aliases.json by default from /etc/opensnitchd.
 - Don't exit if network_aliases.json doesn't exist.
 - Updated Makefile to install network aliases definitions.
2024-12-17 00:38:30 +01:00
Nolan CAROUGE
31da993797
Merge branch 'evilsocket:master' into lan_access_control 2024-12-16 09:46:50 +01:00
Gustavo Iñiguez Goia
b1e279fb6b
get process tree when using process conector
When the Process Connector is used to intercept exec events, get and
build the process tree of a process.

PROCESS CONNECTOR feature was added here: 7a9bb17829
2024-12-13 20:14:55 +01:00
nolancarougepro
fa96aa317d remove test_range in .json 2024-12-11 11:42:53 +01:00
nolancarougepro
f4e7d38af5 modify daemon to accept aliases 2024-12-11 08:58:50 +01:00
nolancarougepro
0addd29c51 add_network_aliases 2024-12-11 08:55:04 +01:00
Gustavo Iñiguez Goia
4091962770
cache of events minor fixes
- fixed storing the old proc after rebuilding the pids tree, when an
   item is replaced in cache.
 - removed not needed rlock.
2024-10-19 23:59:44 +02:00
Gustavo Iñiguez Goia
5fa561607f
daemon/ui tests updated 2024-10-19 20:43:45 +02:00
Gustavo Iñiguez Goia
6622df9d38
allow to configure nfqueue bypass flag
Nfqueue bypass option skips the enqueue of packets to userspace
if no application is listening to the queue.
https://wiki.nftables.org/wiki-nftables/index.php/Queueing_to_userspace

If this flag is not specified, and for example the daemon dies
unexpectedly, all the outbound traffic will be blocked.

Up until now we've been using this flag by default not to block network
traffic if the daemon dies or is killed for some reason. But some users
want to use precisely this behaviour (#884, #1183, #1201).

Now you can configure it, to block connections if the daemon
unexpectedly dies.

The option is on by default in the configuration (QueueBypass: true).
If this item is not present in the daemon config file, then it'll be
false.
2024-10-19 10:51:40 +02:00
Gustavo Iñiguez Goia
ebac200642
ReadEnv() minor improvement
- Improved peformance parsing the environment variables of a process.
 - Added ReadEnv() test.

For a 4kb environ file:

Benchmark-Old    58070 ns/op   19264 B/op   68 allocs/op
Benchmark-New    49174 ns/op   17488 B/op   12 allocs/op
2024-10-18 01:08:43 +02:00
Gustavo Iñiguez Goia
f63a48deff
calculate the ram usage of a process in the daemon
- Calculate the ram usage of a process in the daemon, using the page
   size of the system.
 - Added new functions to read some details of a process, so we can use
   them in other parts of the code.
2024-10-15 00:49:58 +02:00
Gustavo Iñiguez Goia
609edefbb7
added cache of events tests 2024-10-15 00:15:05 +02:00
Gustavo Iñiguez Goia
c3939c7dfd
added tasks tests
added tests for TaskManager, nodeMonitor and pidmonitor.
2024-10-11 00:01:00 +02:00
Gustavo Iñiguez Goia
e20e79d686
tasks improvements 2024-10-10 23:48:56 +02:00
Gustavo Iñiguez Goia
c1c7138e37
refactored tasks notifications
moved to their own file.
2024-10-10 00:24:29 +02:00
Gustavo Iñiguez Goia
3bf429b9ca
getProcPids() minor improvement
reduce allocs a little bit.
2024-10-09 23:54:40 +02:00
Gustavo Iñiguez Goia
83fad69316
tasks: added sockets monitor task (netstat)
Added new task to monitor local sockets of nodes, similar to ss or
netstat.

More info: #1112
2024-10-07 23:40:40 +02:00
Gustavo Iñiguez Goia
58613543e2 added new task nodemonitor
Added new task to monitor the resources of remote nodes, like
ram, swap, number of processes or load average of the system.

The task is initiated when the user selects a node, and the data
received from the node is added to the right panel of the Nodes tab.

The task is stopped when changing to another tab, or when deselecting a
node.

Particularly useful for monitoring remote nodes.
2024-09-28 10:09:19 +02:00
Gustavo Iñiguez Goia
9e0f3a4797
introducing daemon tasks
daemon tasks are actions that are executed in background by the daemon.

They're started from the GUI (server) via a Notification (protobuf),
with the type TASK_START (protobuf).

Once received in the daemon, the TaskManager starts the task in
background.

Tasks may run at interval times (every 5s, 2days, etc), until they
finish an operation, until a timeout, etc.

Each task has each own configuration options, which will customize the
behaviour of its operations.

In this version, if the GUI is closed, the daemon will stop all the
running tasks.
Each Task has a flag to ignore this behaviour, for example if they need
to run until they finish and only send a notification to the GUI,
instead of streaming data continuously to the GUI (server).

 - Up until now we only had one task that could be initiated from the GUI:
   the process monitor dialog. It has been migrated to a Task{}.
 - go.mod bumped to v1.20, to use unsafe string functions.
 - go.sum updated accordingly.
2024-09-25 01:00:38 +02:00
Gustavo Iñiguez Goia
f882cf428b
fw: fixed adding 'counter' obj to rules
https://wiki.nftables.org/wiki-nftables/index.php/Quick_reference-nftables_in_10_minutes#Counter
2024-07-03 14:26:11 +02:00