Commit graph

772 commits

Author SHA1 Message Date
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
Gustavo Iñiguez Goia
53b948b11a
fixed exception loading outdated configuration
TODO: send the error to the GUI. It's important enough to warn the user
about it.

Issue: #1380
2025-07-19 18:49:15 +02:00
Andrew Voynov
c4285878f8
fixed empty host name not being matched 2025-07-19 02:24:49 +05:00
Gustavo Iñiguez Goia
14e306ecad Bumped cilium/ebpf version to 0.19.0
This version introduces a lot of improvements.

It's worth mentioning this one https://github.com/cilium/ebpf/pull/1755,
which reduces memory usage by ~25MB.

It also bumps go version to 1.23.
2025-07-07 23:06:19 +02:00
Gustavo Iñiguez Goia
1c94da7cb6
updated default-config.json
Added the default Authentication fields, to avoid detecting that the
config has changed.

It was causing the daemon to disconnect and reconnect on the first
config change made by the user.
2025-07-02 21:14:57 +02:00
Gustavo Iñiguez Goia
c82daddbae
ebpf dns improvements
- Better handling of burst messages.
 - Empty the queue if it gets full.
2025-06-25 00:57:07 +02:00
Gustavo Iñiguez Goia
7eb1cbf90d
improved proc monitors errors
- Avoid sending duplicated errors.
 - Fixed sending error message when the ebpf events module fails to
   load.
2025-06-22 22:23:36 +02:00
Gustavo Iñiguez Goia
e13b4b9f76
updated config tests 2025-06-19 23:49:45 +02:00
Gustavo Iñiguez Goia
a4d8d1bb27
improved daemon's connection logic with the server (GUI)
- New: if Server.Address is not set, stop the routine that attempts
   to connect with the remote server.
 - Spawn only one polling routine.
 - When changing the configuration:
   - if the new server.address changed and is not empty -> reconnect.
   - if the new server.address changed and is empty -> disconnect.
   - if previous server.address was empty and the new one is not -> connect.
   - if the authentication settings changed -> reconnect.

   If the server.address is not available, we'll try to connect
   indefinitely.
2025-06-19 01:59:30 +02:00
Gustavo Iñiguez Goia
acd5b8886b
Bumped versions to v1.7.1 2025-06-18 01:10:23 +02:00
Gustavo Iñiguez Goia
f1318ef12d
fixed loading config when the procmon fails
- Fixed configuration loading, when the Process Monitor Method
   selected failed to work (e.g.: when ebpf modules are missing,
   auditd is not configured, etc).
   In this scenario, on the first run, the daemon was not loading the
   configuration from disk, and was instead using the default values, which
   led to some glitches (unexpected reconnections to the GUI, checksums
   option ignored, etc).
 - added more tests.
2025-06-18 00:35:17 +02:00
Gustavo Iñiguez Goia
9f570ea9ad ebpf events improvements
Discard events from the queue if we can't send events to the channel.
It can happen if the case of a deadlock such as in ac3053af327e38acad4ff4024ed688ed68d6ae30

In this situation, reading from the ring buffer is blocked, which
eventually causes it to fill up.
When the ring buffer is full, bpf_ringbuf_output() fails with error -11.
2025-06-15 23:10:09 +02:00
Gustavo Iñiguez Goia
c198f0119f improved events cache
Under very high load of kernel events, combined with a
non-zero value for the ebpf.QueueEventsSize config option,
the cache could end up blocking the events workers if the option to
compute process checksums was enabled.
2025-06-15 23:10:09 +02:00
Gustavo Iñiguez Goia
f0b1173d9d added Process path+args tests 2025-06-12 23:43:59 +02:00
Gustavo Iñiguez Goia
376b06ef97
improved binary absolute path retrieval
When receiving the paths of a binary from kernel, the path can be a
symlink to the real binary on disk, and we were not obtaining the real
path to the binary.

Now we'll try to obtain it. If we fail, we'll use the path received from
the kernel. And if it's empty, we'll fallback to read it from proc.

Closes #1357
2025-06-07 23:51:13 +02:00
Gustavo Iñiguez Goia
aa37ac3e3a loggers: changed log level from Warn to Debug
When the remote logger cannot connect to the server, avoid flooding the
logs with warnings.
2025-06-05 20:47:29 +02:00
Gustavo Iñiguez Goia
a3826c50c9
improved remote logger
- Added MaxConnectAttempts configuration option:
   If not specified, it defaults to 0, which means that we'll try to connect
   indefinitely to the remote server.

 - Improved connection retry behaviour:
   We were not reconnecting to the server if we failed to connect on the
   first attempt. Now we'll try to connect until MaxConnectAttempts, or
   indefinitely if not specified (default value 0).

 - If the logger is not connected to the remote server, don't send
   messages to the queue.

Closes #1350.
2025-06-02 23:25:43 +02:00
Gustavo Iñiguez Goia
ef926050c2
fixed listening for link changes (#1343)
netlink.AddrSubscribeWithOptions() was causing systemd-resolved not to
obtain DNS servers, and therefore the system was unable to resolve
domain names.

This ssue started happening on Fedora 42, with systemd-resolved 257 and
kernels 6.14.x.

Using netlink.AddrSubscribe() solves this issue for now.

Closes #1343
2025-05-23 12:53:29 +02:00
Gustavo Iñiguez Goia
e0c659992a
fixed leak reconfiguring rules monitor task 2025-05-23 11:40:43 +02:00
Gustavo Iñiguez Goia
b20fd15335
changed ebpf log levels
Changed Error to Warning log level when failing to load hooks.

Except for udp_tunnel6_xmit_skb, which depends on the module
ip6_udp_tunnel to be loaded, which by default is not the case.
In order not to flood the logs with this error, log level changed to
Debug.
2025-05-21 21:49:15 +02:00
Gustavo Iñiguez Goia
56b2d28b66
ebpf: added support for ipv6 tunnels
In order to intercept UDP tunnels traffic, we use iptunnel_xmit for IPv4
connections. The equivalent of IPv6 would be ip6tunnel_xmit, but
unfortunately it's not public.

So instead of ip6tunnel_xmit, we'll use udp_tunnel6_xmit_skb.

This function receives two parameters besides the struct sock*, in6_addr
*saddr and in6_addr *daddr. If these addresses are not set, usually the
connection is a localhost connection.

On the other hand, this function is defined in the module
ip6_udp_tunnel. If this module is not loaded when the daemon starts,
we'll fail to intercept the connections.

Closes: #1250
2025-05-05 00:34:25 +02:00
Gustavo Iñiguez Goia
568d69520f
fixed reporting connection UID
When getting a connection from the cache, use the UID of the connection,
instead of the process UID.

more info: https://github.com/evilsocket/opensnitch/issues/1315#issuecomment-2829072245

Closes: #1315
2025-04-27 23:54:52 +02:00
Gustavo Iñiguez Goia
aeb2018d27
log the UID of exec events 2025-04-24 23:55:42 +02:00