Commit graph

23 commits

Author SHA1 Message Date
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
785500cd08
clean dns ebpf hooks on exit
We were not reacting to common exit signals, only to kill/interrupt
signals, so the DNS uprobes were never properly removed. Each uprobe
has the PID of the daemon in the identifier, so in theory, there
shouldn't be conflicts, but better clean our probes on exit.

previous to this commit with the daemon running
(and lot of starts/stops):

~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
367

after stopping the daemon:
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
364

~ # > /sys/kernel/debug/tracing/uprobe_events
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
0

~ # cp opensnitchd-new /usr/bin/opensnitchd ; service opensnitchd start
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
3
~ # service opensnitchd stop
~ # cat /sys/kernel/debug/tracing/uprobe_events |wc -l
0
2024-01-28 01:10:00 +01:00
Gustavo Iñiguez Goia
55678b4d3b
added more debug info to the dns ebpf hook
Added the path to the libc as well as the calculated offset for the
uprobe.
Don't return on the first error found loading a uprobe, instead try all
the uprobes and return if the loaded uprobes are 0.
2024-01-26 14:48:44 +01:00
Gustavo Iñiguez Goia
379d010ab8
minor improvement/refactoring
Move queues setup to its own func.
Don't declare some dns vars inside for loops.
2024-01-18 11:37:07 +01:00
Gustavo Iñiguez Goia
e5787aef65
structs fields reorganized
Structs' fields reorganized based on fieldalignment tool output
2024-01-14 20:44:49 +01:00
Gustavo Iñiguez Goia
ffb76683aa
allow to configure ebpf modules path
Now it's possible to configure eBPF modules path from the
default-config.json file:
 "Ebpf": {
   "ModulesPath": "..."
 }

If the option is not provided, or if it's empty, we'll keep loading from
the default directories:

 - /usr/local/lib/opensnitchd/ebpf
 - /usr/lib/opensnitchd/ebpf
 - /etc/opensnitchd/ebpf (deprecated, will be removed in the future).

Closes #928
2023-12-22 23:27:18 +01:00
Gustavo Iñiguez Goia
816496ae72
dns monitor: ignore some dns answers
Ignore those DNS answers that we don't need or use.
2023-03-12 21:37:11 +01:00
Gustavo Iñiguez Goia
e58ade4365
dns/logs minor improvements
- Fixed adding CNAME domains to cache.
- Better connection logging in DEBUG.
- Exclude from dns cache local IPs, equal IPs/domains.
2023-03-10 21:30:28 +01:00
Gustavo Iñiguez Goia
b560ad6967
Added systemd-resolved DNS monitor
Up until now we intercepted query and DNS answers using these methods:
 - Intercepting DNS queries to port 53.
 - Intercepting DNS answers from port 53
 - Intercepting glibc DNS functions.

Unfortunately there are scenarios where these methods are not enough:
 - When using DNSSEC, DoT, DoH, etc.
 - When resolvers return DNS answers from cache
 - When resolvers don't use glibc functions to resolve domains.
 - When applications use D-BUS to query for domain names instead of
   using UDP/TCP (VPNs, flatpaks, electron based apps, etc.).

With this new DNS monitor now we're able to intercept DNS answers when
systemd-resolved is used to resolve domains.
This includes queries from flatpaks and others containerized
applications, as well as cyphered DNS queries.

Closes #874
2023-03-10 15:04:42 +01:00
Gustavo Iñiguez Goia
314ee820ce
centralized ebpf modules loading 2022-11-18 20:38:52 +01: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
4babc52524 exclude ::1 from dns cache
It caused some problems. See #629
2022-02-21 17:51:29 +01: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
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
Gustavo Iñiguez Goia
e13015ce67 updated import paths 2020-12-09 18:18:42 +01:00
Gustavo Iñiguez Goia
528ce81c04 exclude localhost resolved dns from being cached
it led to resolve some domains to 127.0.0.1 and show the user a
dialog with that misleading domain.
2020-04-04 10:53:30 +02:00
Gustavo Iñiguez Goia
99b024e0de dns sources formatted and documented 2020-03-07 10:23:53 +01:00
Gustavo Iñiguez Goia
93592b6b00 Allow to see which domain a process is trying to resolve
Ideally this information should go in a different Connection field, but
for now lets use DstHost.
2019-11-08 01:38:26 +01:00
Gustavo Iñiguez Goia
a7e9b5072f project import paths changed 2019-10-20 21:51:35 +02:00
Armen Boursalian
a8a52f8650 RWMutex may help performance in DNS tracking 2018-08-28 08:21:26 -07:00
Armen Boursalian
b95c63f0c0 #176: IP -> CNAME -> orig. domain display 2018-08-28 08:20:42 -07:00
evilsocket
534ec8cd73
misc: small fix or general refactoring i did not bother commenting 2018-04-02 05:25:32 +02:00