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.
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.
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
}
}
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.
- distribute daemon/data/rules/ with the daemon packages.
- added a new system fw rule to allow localhost connections (disabled
by default).
Closes: #965.
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.
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.
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.
- 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.
- 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.
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.
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.
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
- 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.
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
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.
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