Commit graph

30 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
df8390e57f
minor performance improvements
Replaced calls Sprint/Sprintf in hot paths with internal ConcatStrings,
improving string concatenation performance by approximately ~2x-~10x.
2026-07-06 01:46:11 +02:00
Gustavo Iñiguez Goia
442b466b63
tasks: improved scheduler
Restart the daily timers appropiately if the clock has drifted, for
example when the computer is put to sleep.
2026-01-12 00:04:54 +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
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
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
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
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
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
d2fbdd9700
task pid monitor: fixed stopping the monitor 2025-08-08 01:27:00 +02: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
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
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