Commit graph

744 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
481dc1cd53
avoid to send empty stats to the GUI (server)
By default, every second we send to the GUI the collected statistics by
the daemon: metrics + events (connections).

This call has a hard-coded timeout of one second, and if it reaches the
deadline, a warning message is printed to the log.

After several timeouts, the daemon closes the connection and tries to
reconnect again.

The daemon invokes this call even if there're no statistics to send.
With one daemon and one GUI, it's not much of a problem. But if there're
n nodes, the GUI will receive a minimum of n connections every second.
In many scenarios, these empty calls are unnecessary.

So, in order to optimize this behaviour, if the daemon has not collected
new statistics, we won't invoke this call. This will slightly reduce the
load on the GUI (server) when managing multiple nodes, and will save
some CPU cycles on the daemon side.

The connection status between the daemon and the GUI is managed with the
following gRPC options:

 - The server and the daemon configures a 5-seconds keepalive to keep
   the channel open:
   'grpc.keepalive_time_ms', 5000
 - If after 5 seconds the keepalive msg is not received, then after 20
   seconds the connection with the daemon will be closed if the server
   doesn't receive a response:
   'grpc.keepalive_timeout_ms', 20000

So after about 30 seconds, if the daemon can't communicate with the GUI
(server), it'll close the connection and retry it every second.
2025-12-11 12:07:10 +01:00
Gustavo Iñiguez Goia
f2e2e52aef removed parameters from init services
The daemon no longer requires the parameter -rules-path.

The default path is /etc/opensnitchd/rules, and it's configurable from
the configuration.
2025-12-10 21:31:33 +01:00
Gustavo Iñiguez Goia
9b33f7bdc8 discard notification replies if channel is closed
Sometimes, when closing the notifications channel, we could end up
trying to reply to a notification after the channel was already
closed. For example when changing the server address of a node.

In that scenario, the goroutine never finished and attempted to
reply to the notification.
2025-12-09 23:35:32 +01:00
Gustavo Iñiguez Goia
5b67e2e53e stop notifications at the server's request 2025-12-07 13:14:50 +01:00
Gustavo Iñiguez Goia
8270be1278
check TaskMgr validity 2025-12-05 23:12:51 +01:00
Gustavo Iñiguez Goia
fefbf385f1
lower ping() log level to DEBUG
When sending the events to the GUI (server), there's a hardcoded timeout
of one second. If the call takes longer, we were writing a warning to
the logs for each call, which in some cases could be excessive.

Hitting the timeout can be normal under some circumstances, such as when
connecting to a GUI with multiple nodes and a lot of activity.

More info: #1453
2025-12-05 22:45:42 +01:00
Gustavo Iñiguez Goia
7a0c96c17e initiate Ping() timeout after collecting the stats
We have a hardcoded timeout of one second to send the daemon stats to
the GUI. In some cases it's not unusual to hit the deadline.

So in order to just measure the network call, we now initiate the
timeout after collecting the daemon statistics.

See: #1453
2025-12-05 15:32:18 +01:00
Gustavo Iñiguez Goia
528091f513 avoid crashing when executing fw tests
Found while debugging an issue with several Verdict errors on kernel
6.17.x. Something has changed.
2025-12-03 22:33:15 +01:00
Gustavo Iñiguez Goia
55ac4b7fa4
tasks improvements
- fixed some race conditions.
- added more errors logging.
2025-11-28 00:02:52 +01:00
Gustavo Iñiguez Goia
7224acc7bd print the notifications type on error 2025-11-27 21:32:39 +01:00
Gustavo Iñiguez Goia
9891d106cc
init services moved to data/init/ 2025-11-24 00:07:07 +01:00
Gustavo Iñiguez Goia
fbc72bb96a
mount tracefs path if it's not mounted
Some kernels or systems may not have tracefs mounted or available
by default.

We need the path /sys/kernel/tracing to be mounted, in order to add
syscalls ebpf probes.

So from now on we'll try to mount /sys/kernel/tracing if it's not
already mounted.

-check-requirements parameter updated to check if this option is
available.

Closes #1450.
2025-11-23 23:40:37 +01:00
Gustavo Iñiguez Goia
c57114deed
Bumped versions to v1.8.0 2025-11-23 23:18:35 +01:00
Gustavo Iñiguez Goia
2c142620c4
daemon default configuration files moved to data/ 2025-11-23 23:11:31 +01:00
Gustavo Iñiguez Goia
543241f7cd
improved tasks stopping
We don't need to close the channels on stopping a task. We use a Context
to exit from the task results loop.
2025-11-20 01:25:31 +01:00
Gustavo Iñiguez Goia
2c3120b936
tasks: send results to the loggers
elastic, grafana, syslog, etc.
2025-11-20 01:16:33 +01:00
Gustavo Iñiguez Goia
c719c34de3
tasks,iocscanner: scheduler improvements
note: if the pc is suspended, the timers do not take into account the
time spent suspended.
2025-11-19 21:36:20 +01:00
Gustavo Iñiguez Goia
24f7e6ff1b
tasks,iocscanner: improved running cmds
Sometimes we never reset the running status of the command.
2025-11-14 01:12:57 +01:00
Gustavo Iñiguez Goia
906ad17b12
tasks, iocscanner: minor changes
added tools name as constants, and explain how to use them.

The name of a tool identifies an instance of that tool. Each tool has
its own configuration and logic.

In order to create multiple instances of a tool (for example to run
multiple commands or scripts), just append details to the tool name:

 "name": "script",
 "cmd": ["/usr/bin/clamscan"]

 "name": "script-unhide",
 "cmd": ["/usr/sbin/unhide"]
2025-11-14 00:52:39 +01:00
Gustavo Iñiguez Goia
ab6638f9a0
tasks, iocscanner: simplify messages to the GUI 2025-11-14 00:35:08 +01:00
Gustavo Iñiguez Goia
450adf6485
tasks, iocscanner: updated README 2025-11-12 01:11:08 +01:00
Gustavo Iñiguez Goia
3d2d99648f
tasks: iocscanner minor improvements
- stop scheduler properly.
 - skip closing channels for now.
2025-11-12 00:52:12 +01:00
Gustavo Iñiguez Goia
cb2feeb6a3
tasks: updated iocscanner README.md 2025-09-24 12:50:16 +02:00
Gustavo Iñiguez Goia
be34c8e84f
tasks: added iocscanner README 2025-09-22 19:11:44 +02:00
Gustavo Iñiguez Goia
98595eae5b tasks: dont exit until stop signal 2025-09-22 02:01:37 +02:00
Gustavo Iñiguez Goia
1673856037
tasks: added IOC scanner
Preliminary version of a task for scanning IOCs in background
(Indicator Of Compromise).

It can execute scripts and commands in background periodically.

 - Added a new task scheduler to configure when the task is launched.
   Previously we only had an "Interval" field to run the task
periodically. Now it's possible to select the day of the week, specify
multiple times, hours or minutes.

        "schedule": [
            {
                "weekday": [5,6],
                "time": ["09:55:00", "20:15:20"],
            },
            {
                "weekday": [0,1,2,3,4],
                "time": ["15:00:00"],
            }
        ],
   Used only in this task for now.

 - This task supports 4 "tools": yara, scripts and debsums/dpkg.

   * The "yara" tool acts as a frontend to the yara cli tool, used to scan
     for IOCs with YARA rules.
   * The "debsums"/"dpkg" tools can be used to:
     - report changes in the MD5 checksums of installed Debian
       packages (debsums -c).
     - report changes in configuration files of installed Debian
       packages (debsums -ce).
     - verify the integrity of Debian packages (dpkg --verify, dpkg
       --verify <package1> <packag2>).
       The output of the format (rpm) is not parsed yet.

Configuration example of the task to report the output of the command
debsums:
{
  "name": "IOC-scanner",
  "data": {
     "interval": "15s",
     "schedule": [
         {
             "weekday": [0,1,2,3,4,5,6],
             "time": ["22:00:00"]
         }
     ],
     "tools": [
     {
         "name": "debsums",
         "msgStart": "IOC scanner debsums started",
         "msgEnd": "IOC scanner debsums finished",
         "enabled": false,
         "cmd": ["debsums", "-c"],
         "options": {
             "dirs": [],
             "files": [],
             "reports": {
                 "path": "/etc/opensnitchd/tasks/iocscanner/reports",
                 "format": ""
             }
         }
     }
   ]
}

The field "name" defines which tool to use. It's also used to parse and
format the output of the specified command.

The output of the command is sent to the GUI as an alert, and the
results can be reviewed under the Rules tab -> Alerts.
2025-09-22 00:11:28 +02:00
Gustavo Iñiguez Goia
ed23f48723
tasks: created Downloader README.md 2025-09-12 12:34:13 +02:00
Gustavo Iñiguez Goia
afa0500539
rules: updated default localhost rules
Restrict permissions to 127.0.0.1 and ::1 instead of the whole loopback
range.

This way, we allow localhost connections from common processes (dirmngr,
kdeinit5, xbrlapi, etc.), while giving users control to allow or deny
DNS queries to the local DNS stub resolver (which for example usually
listens on 127.0.0.53).

More info: #1416.
2025-09-12 11:19:12 +02:00
Gustavo Iñiguez Goia
cad02ae320
Merge pull request #1423 from alice945/master
Use application specific nft table
2025-09-12 00:45:09 +02:00
Gustavo Iñiguez Goia
149e0f61b8
tasks: added downloader task
Added a new task to schedule files downloads.

Whenever the task is loaded, the files will be downloaded. From that on,
files will be downloaded according to the duration specified in the
"interval" field.
The format of the interval field is time.Duration:
https://pkg.go.dev/time#Duration

configuration example:

/etc/opensnitchd/tasks/tasks.json:
{
    "tasks":[
        {
            "enabled": false,
            "name": "downloader",
            "configfile": "/etc/opensnitchd/tasks/downloader/downloader.json"
        }
    ]
}

/etc/opensnitchd/downloader/downloader.json:
{
  "name": "downloader",
  "parent": "downloader",
  "description": "",
  "data": {
      "interval": "6h",
      "timeout": "5s",
      "urls": [
          {
              "name": "adaway",
              "enabled": true,
              "remote": "https://adaway.org/hosts.txt",
              "localfile": "/tmp/bl3/ads-adaway-hosts.txt"
          }
      ],
      "notify": {
          "enabled": true
      }
}
2025-09-12 00:24:59 +02:00
Gustavo Iñiguez Goia
be80bd140a
tasks: added new example task
Added an example of a task that simply prints/sends a message to
stdout/the GUI.

Configuration example:

/etc/opensnitchd/tasks/tasks.json:
{
    "tasks": [
        {
            "enabled": true,
            "name": "looper",
            "configfile": "/etc/opensnitchd/tasks/looper/looper.json"
        }
    ]
}

/etc/opensnitchd/tasks/looper/looper.json:
{
    "name": "looper",
    "parent": "looper",
    "data": {
        "interval": "5s"
    }
}
2025-09-11 14:17:25 +02:00
Gustavo Iñiguez Goia
8e5bbb0d1b
tasks: updated tests 2025-09-11 13:41:01 +02:00
alice945
369c035558 Don't use seperate interception chains 2025-09-11 11:30:14 +00:00
Gustavo Iñiguez Goia
66ee50bf7d
tasks: allow to load tasks from disk
Now it's possible to load tasks from disk.

There's a central file which contains the defined tasks:
/etc/opensnitchd/tasks/tasks.json

with this format:
{
    "tasks": [
        {
            "enabled": false,
            "name": "downloader",
            "configfile":
"/etc/opensnitchd/tasks/downloader/downloader.json",
        }
    ]
}

The field "name" defines the type of task to load, defined in each task.
It's static.

Whenever the tasks.json is modified, if the tasks are enabled, the task
configuration file defined in the "configfile" field will be loaded.

Configuration format of each task:

{
  "name": "downloader",
  "parent": "downloader",
  "data": {}
}

The field "name" is dynamic, unique, and identifies the instance of the
task. If there're two tasks configured with the same name, only one will
be loaded.
The "parent" field is used to know what's the base task. If it's not
specified, we'll try to use the "name" as the base task.

This allows you to run multiple instances of the same task with
different configurations: a downloader to update malware blocklists,
another to update IP blocklists, etc.

The "data" field depends of each task. It's generic, and each task is
responsible for defining it. For example for the Downloader task:

"data": {
    "interval": "1h",
    "timeout": "5s",
    "urls": [
        {
            "name": "adaway",
            "enabled": true,
            "remote": "https://adaway.o/hosts.txt",
            "localfile": "/tmp/blocklist/ads-adaway-hosts.txt"
        }
    ]
}

The tasks configuration file are also monitored for changes, and
whenever a change is detected the task is reloaded.

----

Notifications (WIP)

It's not yet fully defined and it'll change, but this is the state as
of today.

For real-time tasks, like pid-monitor, sockets monitor and node monitor,
the GUI initiates the task with a unique ID (a timestamp), to know who
is sending what, and display the data properly on the GUI.

For permanent tasks we use a unique ID defined for each task.

Right now, if we don't have the notifications channel opened and the
notification ID corresponds with one of the tasks, we'll post an alert
to the GUI, to display a desktop notification.

Each task can define if send notifications or not. For example:

{
  "name": "downloader",
  "data": {
      (...)
      "notify": {
          "enabled": true
      }
  }
}

then in each task, act accordingly to what is defined in the
configuration.
2025-09-11 12:19:38 +02:00
alice945
24079ae209
Keep iptables rule 2025-09-11 00:20:25 +00:00
Gustavo Iñiguez Goia
4b38ca1260
config tests: added missing comma 2025-09-11 00:29:02 +02:00
Gustavo Iñiguez Goia
f9358a464f
Merge pull request #1418 from LordGrimmauld/audit-socket-path-config
daemon/audit: allow configuring audispd_events socket path
2025-09-11 00:24:21 +02:00
alice945
1e2f594911 Use application specific nft table
Implements #1260, fixes #1393
2025-09-06 12:47:21 +00:00
Gustavo Iñiguez Goia
85635051aa
tasks: improved sending first results
Don't wait until the timer fires to send the results of a task.
2025-09-04 23:42:02 +02:00
Gustavo Iñiguez Goia
0e80970035
tasks: fixed stop 2025-09-04 01:34:38 +02:00
Gustavo Iñiguez Goia
970f8c356b
minor tasks notification change
Simplify tasks' notifications handling.
2025-09-03 17:45:33 +02:00
Gustavo Iñiguez Goia
ee1678d7c3
removed unused channel 2025-09-03 17:42:51 +02:00
Grimmauld
ec75833dd5
daemon/audit: allow configuring audispd_events socket path 2025-08-26 20:30:02 +02:00
Gustavo Iñiguez Goia
0f4f3b0f9e
Bumped versions to v1.7.3 2025-08-18 17:30:23 +02:00
Gustavo Iñiguez Goia
8c3fa40cf4
distribute default rules with the pkgs
Some checks failed
CI - build eBPF modules / build (6.0, 1.5.0) (push) Has been cancelled
CI - build eBPF modules / build (6.0, master) (push) Has been cancelled
Test resources validation / Install tools (push) Has been cancelled
Build status / Build (push) Has been cancelled
- distribute daemon/data/rules/ with the daemon packages.
 - added a new system fw rule to allow localhost connections (disabled
   by default).

Closes: #965.
2025-08-08 13:45:26 +02:00
Gustavo Iñiguez Goia
d513c9312a
updated predefined rules description 2025-08-08 01:33:53 +02:00
Gustavo Iñiguez Goia
d2fbdd9700
task pid monitor: fixed stopping the monitor 2025-08-08 01:27:00 +02:00
Gustavo Iñiguez Goia
3f63a0844e
bumped versions to v1.7.2 2025-08-06 20:51:27 +02:00
Gustavo Iñiguez Goia
f71f42b54e
fw,config: use context pkg instead of channels
Stop monitoring file changes using the context package instead of
channels.
2025-07-30 18:14:16 +02:00
Gustavo Iñiguez Goia
ca2c56d5cd cache: improved replacing processes
When replacing a process with the same PID (fork/clone),
and ebpf.QueueEventsSize is > 0 we may receive out or order events.
For example if the checksum calculation takes too much time.

Now we avoid updating the process in this scenario.
2025-07-30 16:57:32 +02:00