Commit graph

614 commits

Author SHA1 Message Date
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
Gustavo Iñiguez Goia
72483bdcde improved process detection
latest changes to detect short-lived processes caused undesired
behaviour (#694)

Closes #685
2022-07-08 17:15:57 +02:00
Gustavo Iñiguez Goia
868974f593 don't send events to gui is nolog is true
part of 6666eb8ccf
2022-07-06 16:26:28 +02:00
Gustavo Iñiguez Goia
6666eb8ccf ui,rules: added option to exclude connection events
New option to exclude connections from being logged.

Closes #691
2022-07-04 11:14:26 +02:00
Nico Berlee
5721ca9479
fw: support for icmpv6 nftables in system rules
- Add support for all available nftables ICMPv6 types (ip6tables -m icmpv6 --help)
- Build nftables ICMPv6 rules
- Create a default outbound ICMPv6 echo-request/reply rule
  (currently outbound echo-request ICMPv6 is by default denied)

Signed-off-by: Nico Berlee <nico.berlee@on2it.net>
2022-07-02 18:14:40 +02:00
Gustavo Iñiguez Goia
e7024e3fe0 ebpf: support for long paths
Added support to report absolute path to a binary up to 4096 characters,
defined here:

https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/limits.h#L13
2022-06-27 14:42:54 +02:00
Gustavo Iñiguez Goia
4ce8b0e57c ebpf: improved process detection/new events module
Improved process detections by monitoring new processes execution.
It allow us to know the path of a process before a socket is opened.

Closes #617

Other improvements:
 - If we fail to retrieve the path of a process, then we'll use the comm
   name of the connection/process.
 - Better kernel connections detection.
 - If debugfs is not loaded, we'll try to mount it, to allow to use
   eBPF monitor method.

Future work (help wanted):
 - Extract command line arguments from the kernel (sys_execve, or mm
   struct).
 - Monitor other functions (execveat, clone*, fork, etc).
 - Send these events to the server (GUI), and display all the commands
   an application has executed.
2022-06-24 01:09:45 +02:00
Gustavo Iñiguez Goia
32243c2cfd some ebpf,dns improvements
When using the DNS ebpf module there were some timeouts handling
connections, as well as some (nearly) imperceptible delays resolving
domains.
2022-06-10 17:01:18 +02:00
Jeremy Mahieu
69ca95b796 fixes attachment of dns uprobes when libc is stripped of symbol names (.dynsym instead of .symtab) 2022-06-07 00:04:08 +02:00
Gustavo Iñiguez Goia
12b1adfe03 loggers: improved remote_syslog logging
Under heavy network traffic load, writing to a remote syslog fails with
a timeout. Under this situation the connection didn't recover from that
state, blocking other connections.

To ensure that we continue working normally, as well as keep sending
events to syslog:

- Set a max timeout when writing to a remote syslog.
- Restart the connection with the server, if there're more than 10
  errors.

With these fixes along with few other changes, writing to remote syslog
is more reliable, it works as expected.

We need to find the root cause of this behavior, and further test it
(#638).
2022-05-25 17:46:27 +02:00
Gustavo Iñiguez Goia
558f3a78c3 prevent mem leak on Subscribe() 2022-05-24 17:41:03 +02:00
Gustavo Iñiguez Goia
37caf49ca3 removed unused channel
It caused sometimes panics on exit.
2022-05-23 14:52:51 +02:00
Gustavo Iñiguez Goia
0ba5fc44c9 run tests on every change, fixed fw options
- Run unit tests on every push/pr.
- Silence gcc warnings, it doesn't seem to work and causes unit tests to
  fail:
  https://github.com/golang/go/issues/6883#issuecomment-383800123
- Improved firewall configuration contraints, to meet with this table:
  https://wiki.nftables.org/wiki-nftables/index.php/Netfilter_hooks#Hooks_by_family_and_chain_type
2022-05-18 17:47:39 +02:00
Gustavo Iñiguez Goia
5453a49692 tests: updated rules tests
- Updated rules tests to use the new description field.
- Removed debugging traces from the loggers module.
2022-05-18 15:27:53 +02:00
Gustavo Iñiguez Goia
7b610c0176 added way to send events to syslog
Now you can send events to syslog, local or remote.
This feature was requested here #638

This feature allows you to integrate opensnitch with your SIEM. Take a
look at the above discussion to see examples with
syslog-ng+promtail+loki+grafana.

There's only one logger implemented (syslog), but it should be easily
expandable to add more type of loggers (elastic, etc).

The event format can be CSV or RFC5424. It sould also be easy to add
more formats.

- Allow to configure stats workers. They were hardcoded to 4.
2022-05-17 16:28:59 +02:00
Gustavo Iñiguez Goia
3c524c1942 ui, rules: added description field
- Added ability to add a description to the rules.
- Display the description field on the Rules view, and remove the internal
  fields (operator, operator_data, etc).
- Added DB migrations.
- Improved rules' executable path field tooltip (#661).

Closes #652 #466
2022-05-12 13:38:23 +02:00
Gustavo Iñiguez Goia
db4646dec8 rpm pkgs: deploy dns ebpf module, add grpcio as dep
- Deploy DNS eBPF module when installing the daemon.
- Include python3-grpcio as dependency. For older systems we'll use the
  old .spec file.
2022-05-05 01:16:38 +02:00
Gustavo Iñiguez Goia
b626e3fea2 bump nftables dependency version, packaging changes
- Bump nftable version to depend on latest version with fixes.
- Include opensnitch-dns.o eBPF object when creating the deb package.
- Replaced Suggests by Recommends, to install addtional but not
  essential packages (like python3-pyasnc, and others).
- Added python3-grpcio, python3-protobuf and python3-slugify as
  dependencies.
  For systems without these packages, we'll use the old debian/ dir.
2022-05-04 18:36:50 +02:00
Gustavo Iñiguez Goia
cb74058b96 Bump versions to 1.6.0rc1 2022-05-04 14:47:45 +02:00
Gustavo Iñiguez Goia
d9e0c59158
Allow to configure firewall rules from the GUI (#660)
* Allow to configure firewall rules from the GUI (WIP)

New features:
- Configure and list system firewall rules from the GUI (nftables).
- Configure chains' policies.
- Add simple rules to allow incoming ports.
- Add simple rules to exclude apps (ports) from being intercepted.

This feature is only available for nftables. iptables is still supported,
you can add rules to the configuration file and they'll be loaded, but
you can't configure them from the GUI.

More information: #592
2022-05-03 22:05:12 +02:00
Gustavo Iñiguez Goia
93f61d09e8 ebpf cache improvements
The eBPF cache is meant mainly for certain applications that
establish 2-4 new connections in under 1-2 seconds. Thus, a cache of 1
minute per item was too much, 10-20 seconds is enough.

Also, check old items every minute to keep the number of items low.
2022-02-22 20:33:29 +01:00
Gustavo Iñiguez Goia
4babc52524 exclude ::1 from dns cache
It caused some problems. See #629
2022-02-21 17:51:29 +01:00
cinerea0
a550252f79 daemon: allow building on musl 2022-02-18 20:36:56 -05:00
Gustavo Iñiguez Goia
026f05d9cc dns, ebpf: do not crash on exit when in DEBUG
If the daemon crashes on exit, fw rules are not deleted.
2022-02-18 00:42:54 +01:00
Gustavo Iñiguez Goia
1f79b3a8fd fw, nftables: better rules deletion on exit
We were not deleting our rules correctly on exit if another fw tool had
added rules to the nftables tables. This problem caused to detect that
our rules were not added, so we added them again.
2022-02-17 23:54:55 +01:00
Gustavo Iñiguez Goia
88b30e98d1 go.mod: updated nftables version
google/nftables removed koneu/natend lib, so we don't need it anymore.

Reported here: #623
2022-02-17 16:16:44 +01:00
calesanz
a4b7f57806
Add ebpf based dns lookup hooks (#582)
When using DoT or DoH opensnitch cannot intercept the dns packets.
Therefore the UI always shows IP addresses instead of hostnames. To fix
this issue an ebpf (uprobe) filter was created to hook getaddrinfo and
gethostbyname calls.

In order to be independent of libbcc an additional module was added to
ebpf_prog. Without libbcc the libc function offsets must be resolved
manually. In order to find the loaded glibc version some cgo code was
added.
2022-02-15 21:25:35 +01:00
Yaroslav Chvanov
64dc70aa7a
Improve systemd service unit name
It was a full sentence that looked out of place. Official documentation
of systemd recommends to make it a short capitalized label, preferably a
noun.
See man page `systemd.unit`.[1]

[1] https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Description=
2022-02-02 14:24:13 +03:00
Gustavo Iñiguez Goia
e633588139 fw: fixed formatting directives 2022-01-29 19:42:32 +01:00
Gustavo Iñiguez Goia
d9e8699702 Bump versions to v1.5.0 2022-01-28 23:29:31 +01:00
Gustavo Iñiguez Goia
fcf03405e1 tests, conman: added new tests 2022-01-28 23:16:51 +01:00
Gustavo Iñiguez Goia
49841d4f73 tests, netlink: added tests for netlink functions 2022-01-28 23:02:25 +01:00
Gustavo Iñiguez Goia
70486d8cd2 misc: fixed directive formatting 2022-01-28 14:07:48 +01:00
Gustavo Iñiguez Goia
5d6121bb77 fixed connecting to the GUI via TCP on localhost
There are two issues when connecting to the GUI via TCP on localhost:

- Sometimes when the daemon is launched with the GUI already running, the
  notifications channel is not established.

  * Give 10 seconds to connect, if it timeouts, disconnect everything
    and try to reconnect again.

- After some time the notifications channel is closed from the server
  side (i.e., the GUI), and it is not restablished.

  * Forcefully disconnect everything, and let it reconnect again.

Both issues should be investigated further to find the root problem.
2022-01-28 01:47:29 +01:00