Commit graph

647 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
b546fb9e7a
Bump nftables-go lib version to 0.1.0 2023-01-22 14:40:08 +01:00
Gustavo Iñiguez Goia
18dc32c51f
removed ftrace monitor method
deprecated, was not in use.
2023-01-21 21:03:53 +01:00
Gustavo Iñiguez Goia
9dfcca295a
fixed adding interception chains on old kernels (4.x) 2023-01-07 22:28:52 +01:00
Gustavo Iñiguez Goia
d31c4e86bf
fixed adding interception rule on some kernels
On some kernels (4.19), adding the interception rule to the
inet-mangle-output chain failed.

According to the nftables wiki, the mangle-output chain have (must?) to
be of type Route:
"route type: ... mangle table ... for the output hook (for other
hooks use type filter instead)."

https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains#Base_chain_types

So if we fail adding the interception rule, we retry it with type Filter
instead of Route.

Related: #781 , ced9a24
2023-01-04 21:44:46 +01:00
Gustavo Iñiguez Goia
274a3483d7
improvements to ui, ebpf, netfilter
- Fixed firewall dialog label alignment.
 - Fixed potential race condition when stopping the daemon, and there're
   connections being enqueued.
 - Added "clear" button to GUI's filter line (#786)
 - Create ebpf cache object only if the modules have been loaded.
 - Set default stats workers to the sme amount defined in configuration.

Closes #785
2022-12-23 14:39:49 +01:00
Gustavo Iñiguez Goia
05e63e97a7
sys fw: improved chains creation
This is part of latest commit ced9a24933

 - When reusing a chain, configure the new policy.
 - Don't backup existing rules when reloading the configuration.
2022-12-23 00:50:22 +01:00
Gustavo Iñiguez Goia
39473439b2
ebpf monitor: fixed crash if modules are malformed
If a eBPF module is malformed, we crashed trying reading the eBPF maps.
2022-12-22 11:40:34 +01:00
Gustavo Iñiguez Goia
85776f4d17
Bump ui and daemon versions to 1.6.0rc4 2022-12-22 10:20:36 +01:00
Gustavo Iñiguez Goia
ced9a24933
nftables: fixed adding interception rules
On some systems after disabling and enabling the interception, the
DNS rule was not being re-added, with error: chain already exists.

When the interception is disabled, we firstly remove the rules,
and secondly if the chain and table is empty we try to remove them
as well.

However, on some systems even if "nft list ruleset" didn't list the
chains to hold our rules, it failed with error "already exists".

Before adding a chain now we check if it exists, and if it does we
reuse it.

Closes #781
2022-12-22 00:19:16 +01:00
clayton craft
8f49816dee
daemon/Makefile: improvements to make distro packaging easier (#780)
* daemon/Makefile: add support for PREFIX, DESTDIR, SYSCONFDIR in install

This is helpful for package maintainers who need to install components
into specific locations for building packages of this project.

example:
$ make \
    PREFIX=/usr \
    DESTDIR=/some/package/dir \
    SYSCONFDIR=/foo/etc \
    install

* daemon/Makefile: use 'install' to copy files / make dirs
2022-12-21 10:35:52 +01:00
Gustavo Iñiguez Goia
7b99383546
find connections with connection fields swapped
Under certain situations, like when using systemd-resolved as DNS
resolver, we receive outbound connections with the fields swapped:

Instead of: local-port:local-ip -> public-ip:public-port
we receive: public-port:public-ip -> local-ip:local-port

Sometimes this behaviour causes network slowdowns, or no network at all.

If we swap the fields of these connections, then we're able to get the
process and keep functioning as usual. But what causes this behaviour is
yet unknown, and needs further analysis.

See these issues for more information: #779 , #711
2022-12-20 17:16:20 +01:00
Gustavo Iñiguez Goia
a45ba914e3
better ebpf tasks cancellation
It should improve daemon stopping times.
2022-12-19 18:38:13 +01:00
Gustavo Iñiguez Goia
afa23f5ac2
sys fw: improved rules, profiles policies
- Allow to use commas to define conntrack states:
  ("related,established")
- Remove profile's rules when switching from Deny to Allow.
- Fixed checking duplicated rules.

Closes #778
2022-12-19 10:59:43 +01:00
Gustavo Iñiguez Goia
50217afc9f
added initial support for ICMP and SCTP
Closes: 714
2022-12-18 00:41:06 +01:00
Gustavo Iñiguez Goia
342c75a6e1
better errors, fixed default sys fw conf 2022-12-16 17:09:37 +01:00
Gustavo Iñiguez Goia
c81dc22c02
sys fw: allow to change fw type from the GUI
- Configuration of system firewall rules from the GUI is not supported for
 iptables. Up until now only a warning was displayed, encouring to change
 fw type manually.

 Now if configured fw type is iptables (default-config.json, Firewall:),
 and the user opens the fw dialog, we'll ask the user to change it from
 the GUI.

- Add fw rules before connecting to the GUI. Otherwise we send to the
  GUI an invalid fw state.
2022-12-16 17:03:36 +01:00
Gustavo Iñiguez Goia
1775da2b48
sys fw: silence error parsing configuration 2022-12-11 22:11:37 +01:00
Gustavo Iñiguez Goia
93e1135b4a
better ebpf errors printing
Provide more information when loading ebpf modules fails.
2022-12-11 17:25:05 +01:00
Gustavo Iñiguez Goia
23b1a6b75e
fw: restore chains policy where applicable
If the user configures chains' policy to Drop, we need to restore it to
Accept when exiting, otherwise we could block connections
unintentionally.
2022-12-11 14:15:17 +01:00
Gustavo Iñiguez Goia
2e2f1768f2
improved errors printing 2022-12-11 11:41:47 +01:00
Gustavo Iñiguez Goia
e2a822b731
better errors printing
Explain a littler bit better some errors.
2022-12-10 21:49:48 +01:00
Gustavo Iñiguez Goia
daae591d05
impoved alerts
- Increased number of alerts to queue.
- Fixed sending alerts to server.
2022-12-09 17:03:02 +01:00
Gustavo Iñiguez Goia
1a493b9da1
ebpf: improved process details gathering
In order to detect short-lived processes we intercept new processes
executions as they happen, and cache them for later use.

When a new connection is established, then we check if the PID of the
connection is cached, and use the details of the process to ask the user
to allow or deny it.

However, there're some situations where the path or cmdline of a PID,
doesn't correspond with the one that's establishing the connection.

Given the same PID:
 - Sometimes we receive from the tracepoint a wrong/non-existent path.
 - Other times we receive a "helper" which is the one executing the
   real binary that opens the connection.

For these reasons now when a new connection is established, we read the
path to the binary from proc. If the PID is cached and the cached path
differs, then we'll use the path from proc.

We lose a bit of performance, but hopefully we'll be more consistent
with what the user expect, while at the same time keeping intercepting
short-lived processes.

Downsides: for execveat() executions we won't display the original binary.

Closes #771
2022-11-27 14:03:13 +01:00
Gustavo Iñiguez Goia
314ee820ce
centralized ebpf modules loading 2022-11-18 20:38:52 +01:00
Gustavo Iñiguez Goia
c64b2df03c
ebpf: delete expired exec events from cache
Whenever a process exits, we delete the corresponding entry from
cache.

But when a process executes a new process (sh -c ls), we receive an
exit event for the parent, while the child continues working with *the
same PID*. Sometimes we don't receive exit events for the child, so the
entry was never removed from cache.

We should properly detect the exits, but forthe time being, delete
expired processes from cache every minute.
2022-11-15 23:30:26 +01:00
Gustavo Iñiguez Goia
6bfe6cef8d
Bump versions to 1.6.0-rc.3 2022-11-15 00:52:23 +01:00
Gustavo Iñiguez Goia
a3538a728f
systemd service: wait 10s to stop, otherwise kill daemon 2022-10-27 17:53:42 +02:00
Gustavo Iñiguez Goia
ec31ee0814
sys fw: added option to filter by MAC 2022-10-23 11:36:51 +02:00
Gustavo Iñiguez Goia
736c3f9c51
rules: make .json files accessible only to root by default 2022-10-20 21:01:29 +02:00
Gustavo Iñiguez Goia
0d46b2e42f
stop ebpf monitor cleanly 2022-10-18 23:29:50 +02:00
Gustavo Iñiguez Goia
474a6373cf
ebpf: allow to load modules from more directories
Up until now we loaded the eBPF modules from /etc/opensnitchd.

However there has been some problems upgrading the modules to newer
versions with the deb packages, because every file under /etc/ is
treated as a conffile, and whenever a conffile changes it prompt you to
update it or not. Some users decided to no upgrade it, ending up with
eBPF modules incompatible with the new daemon.

https://www.debian.org/doc/manuals/maint-guide/dother.en.html#conffiles

On the other hand, the FHS dictates that /etc/ is for configuration
files, and /usr/lib for object files:

"/usr/lib includes object files and libraries. [21] On some systems,
it may also include internal binaries that are not intended to be
executed directly by users or shell scripts."

https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04s06.html

So now, we look for the eBPF modules under /usr/local/lib/opensnitchd/ebpf/
or /usr/lib/opensnitchd/ebpf/, and as a last resort under
/etc/opensnitchd/
2022-10-18 18:46:40 +02:00
Gustavo Iñiguez Goia
7cbfca6b1f
ebpf: increased ring buffer size, hook execveat
Increased perf map buffer size to avoid lose events under heavy loads.

Hook execveat to intercept executions from memory.
2022-10-13 01:44:23 +02:00
Gustavo Iñiguez Goia
09e9a8ac79
fw: report initialization errors
Allow send fw initialization errors to the server (UI).
2022-10-13 00:08:52 +02:00
Gustavo Iñiguez Goia
477e6aadb0
new feature: send alerts to the server/UI
Up until now some error and warning messages were only logged out to the
system, not allowing the user know what was happening under the hood.

Now the following events are notified:
 - eBPF related errors.
 - netfilter queue errors.
 - configuration errors.

WIP, we'll keep improving it and build new features on top of this one.
2022-10-12 13:31:45 +02:00
Gustavo Iñiguez Goia
cfeba55515
systemd service: start the daemon earlier
The daemon doesn't need network connectivity to work, so we don't need
to wait until we're online.

Closes #723
2022-10-05 22:10:04 +02:00
Gustavo Iñiguez Goia
8f70af47e2
resolve absolute path of a process if it's relative
We may receive relative paths from kernel (eBPF), so we need to resolve
the absolute path of the process in order to create valid rules.
2022-10-01 22:27:07 +02:00
Gustavo Iñiguez Goia
564c263d71
packaging: moving files out of the gui/daemon dirs 2022-09-26 23:03:49 +02:00
Gustavo Iñiguez Goia
b7c5785a00
fixed conman/ tests 2022-09-24 17:24:12 +02:00
Gustavo Iñiguez Goia
4a0f7a3e2b
rules: allow to filter by network interface name
Now you can create rules to filter network interface name.
Regular expresions allowed: "eth[0-9]"

Closes #726
2022-09-24 17:12:09 +02:00
Gustavo Iñiguez Goia
fc96b24000
sys fw: added more meta options (uid,gid,l4proto..
Added more options to match connections against packets metainformation:
 skuid, skgid, l4proto, protocol

Fixed setting mark on packets via meta (although it results in an error
-> [invalid type]).
2022-09-16 14:01:41 +02:00
phk
cb19716ebc sys firewall: fixed wrong wireguard protocol
Changed 'tcp' to 'udp' to make wireguard rule work
2022-09-15 15:36:49 +02:00
Gustavo Iñiguez Goia
b8d6ead363
sys firewall: fixed matching ip protocols
Fixed using: ip protocol ah (or tcp, udp, gre, l2tp, etc)
2022-09-14 22:03:14 +02:00
Gustavo Iñiguez Goia
25bd8251be
fixed deadlock stopping ebpf monitor method
+ init events streamer as soon as possible.

Closes #739
2022-09-14 14:37:16 +02:00
Gustavo Iñiguez Goia
09ec8692f7
firewall: fixed adding rules with IPs
Instead of "ip daddr 1.1.1.1", "nh,128,32 16843009" was added.

Reproduced on ubuntu 20/22, manjaro, with different kernels (5.1x)
2022-09-13 21:58:52 +02:00
Gustavo Iñiguez Goia
5c7b1c1558
fw: allow to set rules log level
Allow to set log level in (system) firewall rules.

  "Statement": {
   "Op": "",
   "Name": "log",
   "Values": [
     {
       "Key": "prefix",
       "Value": "invalid-in-packet"
     },
     {
       "Key": "level",
       "Value": "emerg"
     }
   ]
  }

https://github.com/evilsocket/opensnitch/wiki/System-rules#examples-of-supported-statements
2022-09-12 01:14:39 +02:00
Gustavo Iñiguez Goia
f0a9d02e94 fw: fixed adding daddr/saddr to inet tables
If the table family where we're adding a daddr/saddr is inet, we need to
specify the protocol of the IP being added.

Otherwise, listing the rules they appear as:
@nh,128,32 3232235777 accept
instead of: daddr 192.168.1.111 accept

seen here: #704
2022-07-30 00:25:28 +02:00
Gustavo Iñiguez Goia
77f52574fc Bump versions to v1.6.0rc2 2022-07-14 12:29:02 +02:00
Gustavo Iñiguez Goia
fc3d7382de ebpf: get cmdline arguments from kernel
- Get cmdline arguments from kernel along with the absolute path to the
  binary.
  If the cmdline has more than 20 arguments, or one of the arguments is
  longer than 256 bytes, get it from ProcFS.
- Improved stopping ebpf monitor method.
2022-07-12 15:40:01 +02:00
Gustavo Iñiguez Goia
7557faf3a6 prevent crash resolving /proc/self/exe 2022-07-09 22:17:17 +02:00
Gustavo Iñiguez Goia
45212db908 clean path of a process if it's needed
Sometimes the path of a path has " (deleted)" added or the path is
reported as "/proc/self/exe" which is a link and needs to be resolved.

 -> #694
2022-07-08 21:59:11 +02:00