Commit graph

646 commits

Author SHA1 Message Date
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-f7f6108a60b107adfb0930f5f73a6ae229f9943bb01949d1f8f3e247f869b2abL59-L60)
 - 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-f7f6108a60b107adfb0930f5f73a6ae229f9943bb01949d1f8f3e247f869b2abL59-L60)
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
Gustavo Iñiguez Goia
58aa979cae
fixed loading rules when Created field is a timestamp
When exporting rules from the GUI, the Created field was exported as
timestamp. Importing rules worked fine, because json.Marshall() accepts
the timestamp format.

However, when the daemon was loading a rule with the Created field as
timestamp, since the field was defined as time.Time, it expected a RFC3339
string (https://pkg.go.dev/time#Time.UnmarshalJSON)
so it failed to parse the timestamp and the rule was not loaded.

Now the field is defined as string, it's always saved as RFC3339, and if
we fail to parse these fields we'll use a temporary date instead of
failing loading the rule.

More info:
https://github.com/evilsocket/opensnitch/issues/1140#issuecomment-2140904847

Closes #1140
2024-06-10 23:54:54 +02:00
Gustavo Iñiguez Goia
41690b2d2d
set default rules directory if empty
Use /etc/opensnitchd/rules as the default directory if it has not been
provided via configuration.
2024-05-29 23:43:46 +02:00
redanaheim
fa2f1068f6
Remove duplicate regex in system.go for -check-requirements 2024-05-26 23:22:53 +00:00
Gustavo Iñiguez Goia
03747ea0e3
improved config file reloading behaviour
Start monitoring the config file every time we read the file, to survive:
 - malformed json file
 - intermediate file removal (when writing we receive 2 write events,
   one of0 bytes)

"A watch will be automatically removed if the watched path is deleted or
renamed"
"A path can only be watched once; watching it more than once is a no-op and
will not return an error"
https://pkg.go.dev/github.com/fsnotify/fsnotify#Watcher.Add
2024-05-23 01:47:59 +02:00
Gustavo Iñiguez Goia
2238e63892
updated go.mod, added go.sum 2024-05-22 01:39:19 +02:00
Gustavo Iñiguez Goia
c0d1da20d2
improved rules reloading, cli parameters
- When reloading rules from a path:
   stop existing (domains,ips,regexp) lists monitors, stop rules
   watcher and start watching the new dir for changes, delete existing
   rules from memory, etc.
 - Previously, cli parameters (queue number, log file, etc) were taking
   into account before loading the configuration.
   Now the configuration file is loaded first (default-config.json), and
   if any of the cli parameter has been specified, it'll overwrite the
   loaded configuration from file.

   This means for example that if you use "-process-monitor-method proc",
   and "ebpf" is configured in default-config.json, firstly "ebpf" will
   be configured, and later "proc".

   (-queue-num option for now requires to match config option
   cfg.FwOptions.QueueNumber)
2024-05-22 00:47:54 +02:00
Gustavo Iñiguez Goia
661e3da48f
kill established connections only on fw/monitor changes 2024-05-19 23:43:12 +02:00
Gustavo Iñiguez Goia
1e6d2d464b
updated default-config.json with latest added opts
More info about these options:
https://github.com/evilsocket/opensnitch/wiki/Configurations
2024-05-16 00:51:30 +02:00
Gustavo Iñiguez Goia
eede54c525
allow to customize ebpf options
Allow to customize:

 - EventsWorkers: number of goroutines to handle kernel events.
   Default 8.

 - QueueEventsSize: max number of events in the queue.
   By default 0, meaning that it'll relay on the available goroutines to
   process the events. If it's > 0, and the daemon can't process the
   events fast enough, they'll be queued. Once the queue is full, it'll
   behave as it was of size 0.

If there're lost events, a message will be logged: "Lost ebpf events..."
2024-05-16 00:31:54 +02:00
Gustavo Iñiguez Goia
84361449f2
loggers, remote_syslog: check if we're connected
when writing, check if we're connected, or reconnecting.
2024-05-15 00:06:26 +02:00
Gustavo Iñiguez Goia
efc05663eb
fw: allow to configure interception queue number
- Added new configuration field to allow configure fw interception
   number queue (default to 0):
   "FwOptions": {
      "QueueNum": 0
   }
   (we still need to reconfigure nfqueue queues in order for this to
take effect).
 - If the fw configuration path is not supplied, default to
   /etc/opensnitchd/system-fw.json
2024-05-14 23:41:25 +02:00
Gustavo Iñiguez Goia
9afadcb009
fixed segfaults when loading fw/loggers
- The loggers were not being properly initialized.
 - The fw was only being load on reload, instead of on startup
   and reload.

Kudos to @1fishe2fishe for reporting this problem and proposing a
fix in #1130!
2024-05-14 19:47:35 +02:00
Gustavo Iñiguez Goia
c9ad9005e3
fw minor changes
use struct{} instead of bool for exit channels, func parms cosmetic
change.
2024-05-13 01:38:57 +02:00
Gustavo Iñiguez Goia
8935bfe6b0
do not flush conns when adding the inteception rules
part of previous commit.
2024-05-13 01:33:28 +02:00
Gustavo Iñiguez Goia
8e9c1d2178
make connections flushing configurable
By default when adding the interception rules, we were killing all
existing connections, to force them go to the netfilter queue.

However in some environments this is not acceptable, so now it's configurable.

Besides, we were doing this only for nftables, so now it also works for
iptables.
2024-05-13 00:27:41 +02:00
Gustavo Iñiguez Goia
c3bbb9250e
stop proc monitor when disabling interception
When disabling the interception from the server (GUI), the network
interception was stopped, but the procs monitor kept running.

Now the procs monitor in use is also stopped, not to interfere with
the rest of the system (except 'proc').
2024-05-12 10:46:11 +02:00
Gustavo Iñiguez Goia
bc32094945
removed fw rules initialization from main
now they're added after loading the configuration.
2024-05-12 00:59:48 +02:00