Commit graph

772 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
12c21c7a26
removed debug line 2025-04-24 23:53:50 +02:00
Gustavo Iñiguez Goia
82b09c3ac6
removed not needed log line 2025-04-24 18:00:31 +02:00
Gustavo Iñiguez Goia
c8bec89d70
reorganized network aliases feature
- Moved to their own files/dirs.
 - Added Nolan Carouge as author and contributor.
2025-04-24 16:06:11 +02:00
Self Denial
056e2ec2ee
refactor: Update localhost rules and add IPv6
- Changed the local host rule from using regexp to network operator
- Updated destination IP check from specific addresses to CIDR notation (127.0.0.0/8)
- Added new rule for IPv6 localhost connections (::1/128)
- Added nolog property to prevent logging of localhost traffic
2025-04-23 12:48:28 -06:00
Gustavo Iñiguez Goia
2a8f13d439
process path parsing improvements
- Preprend the chroot of a process to the path:
   Even if a process is executed from a chroot (or a different mount
   namespace), the kernel reports the path as it were from the host.
   For chrooted processes, now we prepend the chroot to the path:
   Instead of /usr/bin/curl -> /var/cache/pbuilder/usr/bin/curl

   Note: if the process is emulated (with qemu for example), the
   checksum will be of the emulator.

 - For proceses launched from /proc, like /proc/self/exe or
   /proc/<pid>/fd/<number>, we were replacing in the cmdline "/proc/*"
   with the absolute path of the binary:

   Path: /usr/bin/curl
   Cmdline reported: /proc/<pid>/fd/<number> -L 1.1.1.1
   Cmdline "fixed": /usr/bin/curl -L 1.1.1.1

   Now we only do that for /proc/self/exe, and leave
   /proc/<pid>/fd/<number> as is, since Path is already the absolute
   path to the binary.

   Path: /usr/bin/spotify
   Cmdline reported: /proc/self/exe
   Cmdline "fixed": /usr/bin/spotify

   Path: /usr/bin/curl
   Cmdline reported: /proc/<pid>/fd/<number> -L 1.1.1.1
   Cmdline final: /proc/<pid>/fd/<number> -L 1.1.1.1
2025-04-18 13:30:51 +02:00
Gustavo Iñiguez Goia
8ec86c638c
ebpf: arm improvements
- better process interception on aarch64 and armhf.
 - on armhf getting proc arguments is ignored due to an error, but we
   were not marking the event as INCOMPLETE_ARGS, so we were not reading
   the compete cmdline.
2025-04-14 17:43:41 +02:00
Gustavo Iñiguez Goia
f99700076c
ebpf dns: better error handling
- Avoid crashes if the module is malformed.
 - Better error handling.
2025-04-11 21:07:31 +02:00
Gustavo Iñiguez Goia
452233901d
avoid printing in debug possible invalid var 2025-04-10 21:26:26 +02:00
Gustavo Iñiguez Goia
feafe87604
migrated ebpf lib from gobpf to cilium
Up until now we've been using https://github.com/iovisor/gobpf/ for
intercepting events from the kernel, and it has worked very well.

Unfortunately it's deprecated since 2021 (iovisor/gobpf#304), which means
that some of the known issues and limitations won't be fixed.

After evaluating some options, I've migrated the code from gobpf to
github.com/cilium/ebpf.

More info: #1222, #1312
2025-04-09 00:15:38 +02:00
Gustavo Iñiguez Goia
56eddafca8
loggers: handle errors properly
RemoteLogger: don't create the logger if we can't connect with the
server.
2025-03-29 17:21:19 +01:00
Gustavo Iñiguez Goia
aab65908c7
fixed condition checking operator Data field 2025-03-18 02:09:53 +01:00
Gustavo Iñiguez Goia
5828ba861c
fixed crash compiling unknown operator rules
If a rule contained an unknown rule type or unknown operand, the daemon
crashed.

Closes: #1295
2025-03-18 01:38:31 +01:00
Gustavo Iñiguez Goia
7b66e598b6
loggers: simplify structed data conversions
- unify conversion for rfc3164 and rfc5424 formats.
2025-03-11 20:18:34 +01:00
Gustavo Iñiguez Goia
98b8b06018
remote loggers improvements
- Convert remote syslog to remote. There's no real difference between
   both, and the code was the same.
    Maybe we could limit the logging formats allowed.
 - Remote logger: Added option to reopen the connection after n errors
   trying to send messages.
2025-03-11 17:57:13 +01:00
Gustavo Iñiguez Goia
da4761f1d6
log checksums and proctree for syslog formats
- Log the checksums and process tree when using rfc3164 and rfc5424
   formats.
 - Minor performance improvements.
2025-03-11 17:06:40 +01:00
Gustavo Iñiguez Goia
ac45c4103f
nftables tests: skip TestAddInterceptionChains
tested on several distros with different kernels, as well as in a
private fork and this test doesn't fail.

So until we figure out why it's failing here, let's skip it for now.
2025-03-10 17:02:38 +01:00
Gustavo Iñiguez Goia
221923da73
improved loggers , remote logger
- Fixed issue when configuring several loggers.
 - Remote logger:
    - open as many connections with the remote server as
      specified in the Workers field.
    - open and handle every connection in each own goroutine.
    - get rid of the locks.
2025-03-10 16:42:19 +01:00
Gustavo Iñiguez Goia
f23c1635ca
minor logging improvements
- Moved Info message to Trace.
 - When applying a default action on a connection (because the daemon is
   not connected to the GUI), log the connection details. It eases the
   task of creating rules without a GUI.
2025-03-04 22:19:07 +01:00
Gustavo Iñiguez Goia
8d1a7de0cc
moved some Debug msgs to Trace 2025-03-03 21:35:31 +01:00
Gustavo Iñiguez Goia
5fdb60dccb
ui,prefs: fixed QueueBypass option. 2025-02-18 23:40:56 +01:00
Gustavo Iñiguez Goia
c6b42890c0
proc.readEnv() improvements
- Minimize the risk of race conditions when we're prompting the user to
   allow/deny a connection, while we're still reading proc's environ file.
   (this was actually a leak).
 - Preallocate the Env map with the expected environ vars.
2025-02-17 14:15:28 +01:00
Gustavo Iñiguez Goia
ce006ee1ac
Bumped nftables lib to v0.2.0 2025-02-14 23:06:50 +01:00
Gustavo Iñiguez Goia
2509d21e30
daemon: allow to filter connections by parent path
Some use cases:

 - Reject connections initiated by certain paths:

   Deny all connections initiated by cron*:
        /usr/sbin/cron
            /usr/bin/curl

     "action": "reject",
     "operator: {
        "type": "list",
        "operand": "list",
        "data": "",
        "list": [
     	   {
                "type": "regexp",
                "operand": "process.parent.path",

                // /usr/bin/crond , /usr/bin/crontab, ...
                "data": "^/usr/(s|)bin/cron"
           }
        ]
     }

 - Reject or Allow connections of binaries launched by another app:

       "action": "allow",
       "operator": {
       	"type": "list",
       	"operand": "list",
       	"data": "",
       	"list": [
       	    {
                "type": "simple",
       	        "operand": "process.parent.path",
       	        "data": "/opt/spotify/bin/spotify"
       	    },
       	    {
       	        "type": "simple",
       	        "operand": "process.path",
       	        "data": "/usr/bin/wget"
       	    }
       	  ]
       }

You can also combine multiple parent paths, to allow a command launched
from a specific chain of processes:

    /usr/lib/systemd/systemd
        /usr/sbin/cron
             /bin/sh
                 /usr/bin/curl

The order is checked from the newest process to the oldest (curl -> sh
-> cron -> systemd)

The operand can be used with any of the existing types (simple, regexp,
etc).

Related: #406
2025-02-13 01:23:31 +01:00
Gustavo Iñiguez Goia
5eebaf40fc improved the process tree retrieval 2025-02-11 01:21:06 +01:00
Gustavo Iñiguez Goia
2a68561557
exclude disabled rules from the active rules
Disabled rules were part of the active rules. The fields were not
evaluated, but we still went through the entire list.

Not adding them to the list of active rules improves matching time,
especially when there're a lot of disabled rules.

It mainly affected when matching rules that were non-priority or
ordered alphabetically, with action Allow.
2025-02-08 15:12:11 +01:00
Gustavo Iñiguez Goia
07a4077a6a
schedule temp rules only if enabled
Avoid scheduling temporary rules if they're not enabled.
2025-02-08 00:37:04 +01: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
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-f7f6108a60)
 - 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-f7f6108a60)
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