Commit graph

54 commits

Author SHA1 Message Date
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
19d376abf0
getparents code reorganization
Deoptimizing GetParents() until we figure out how to do it without
leaking mem.
2023-10-04 00:58:17 +02:00
Gustavo Iñiguez Goia
0556dc1c81
obtain process's parent hierarchy, checksums improvements
- Obtain the process's parent hierarchy.
 - Display the hierarchy on the pop-ups and the process dialog.
 - [pop-ups] Added a Detailed view with all the metadata of the
   process.
 - [cache-events] Improved the cache of processes.
 - [ruleseditor] Fixed enabling md5 checksum widget.

Related: #413, #406
2023-09-30 18:31:19 +02:00
Gustavo Iñiguez Goia
7a9bb17829
allow to filter connections by process checksum
Now you can create rules to filter processes by checksum. Only md5 is
available at the moment.

There's a global configuration option that you can use to enable or
disable this feature, from the config file or from the Preferences
dialog.

As part of this feature there have been more changes:

   - New proc monitor method (PROCESS CONNECTOR) that listens for
     exec/exit events from the kernel.
     This feature depends on CONFIG_PROC_EVENTS kernel option.

   - Only one cache of active processes for ebpf and proc monitor
     methods.

More info and details: #413.
2023-09-22 00:36:26 +02:00
Gustavo Iñiguez Goia
19890062ff
added more logs for better issues debugging
- Log packet mark, which may help debugging VPN connections for example.
- Log the nfqueue number when we fail to setup the queue.
  * Suggest to restart the computer on one particular case (#912).
2023-04-21 23:28:13 +02:00
Gustavo Iñiguez Goia
5f532e5011
logging: better connections logging
- in DEBUG level log dst_host(dst_ip), instead of only dst_host.
2023-03-10 22:02:02 +01:00
Gustavo Iñiguez Goia
e44e1468b8
improved connections parsing, minor refactoring
When using proc monitor method + interceptUnknown, allow to ask the user
about connections not associated with a process. Usually they're safe to
discard, but on some special cases it helps not disrupt some services.

Block of code to find connections via netstat moved to procmon/
2023-02-04 16:43:24 +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
50217afc9f
added initial support for ICMP and SCTP
Closes: 714
2022-12-18 00:41:06 +01: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
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
fcf03405e1 tests, conman: added new tests 2022-01-28 23:16:51 +01:00
Gustavo Iñiguez Goia
479b8ded59 improved connections parsing
Under certain conditions, when we dumped inodes via netlink, we were
linking network connections to wrong applications.

- To improve this situation:

1) Use netfilter's UID by default:
   Sometimes the UID reported via netlink was different than the one
   reported by libnetfilter. libnetfilter UID is always correct.
   If you had a rule that filtered by UID, this problem could cause to
   prompt you again to allow the connection.

2) Use the netlink entry that matches exactly the properties of an
   outgoing connection:
   There're some in-kernel sockets that doesn't match 1:1 outgoing
   connections (daemon/netlink/socket.go#L22).
   In order to identify the applications that initiate these network
   connections we use a workaround. But under certain conditions
   (source port reuse), we were associating connections to wrong
   applications.
   So in order to avoid this problem, if there's a 1:1 match use that
   netlink entry. If not, fallback to the workaround.

- misc: added more logs to better debug these issues.
2021-11-15 13:26:52 +01:00
Gustavo Iñiguez Goia
465d531496 find PID: use legacy methods if the PID is not found.
Some times, processes that establish connections to localhost are only
found in /proc/net/* files. So if we fail to get the PID of a
connection, fallback to legacy method to find it.
2021-06-08 14:11:19 +02:00
themighty1
9497cf8394
Use ebpf program to find PID of new connections. (#397)
* Use ebpf program to find PID of new connections.

    before running the branch you have to compile ebpf_prog/opensnitch.c
    opensnitch.c is an eBPF program. Compilation requires getting kernel source.

    cd opensnitch
    wget https://github.com/torvalds/linux/archive/v5.8.tar.gz
    tar -xf v5.8.tar.gz
    patch linux-5.8/tools/lib/bpf/bpf_helpers.h < ebpf_prog/file.patch
    cp ebpf_prog/opensnitch.c ebpf_prog/Makefile linux-5.8/samples/bpf
    cd linux-5.8 && yes "" | make oldconfig && make prepare && make headers_install # (1 min)
    cd samples/bpf && make
    objdump -h opensnitch.o #you should see many section, number 1 should be called kprobe/tcp_v4_connect
    llvm-strip -g opensnitch.o #remove debug info
    sudo cp opensnitch.o /etc/opensnitchd
    cd ../../../daemon

    --opensnitchd expects to find opensnitch.o in /etc/opensnitchd/
    --start opensnitchd with:

    opensnitchd -rules-path /etc/opensnitchd/rules -process-monitor-method ebpf

Co-authored-by: themighty1 <you@example.com>
Co-authored-by: Gustavo Iñiguez Goia <gooffy1@gmail.com>
2021-04-05 11:28:16 +02:00
Gustavo Iñiguez Goia
a325876641 improved connection parsing
Sometimes when querying the kernel for a given connection, the inode of
the connection is 0, i.e.: invalid (or not yet valid).

In these cases we search for the connection in /proc/net/. It turns out
that some connections are found in netstat but the inode is still 0, and
we were accepting them erronously.

As a result, when looking for the inode under /proc we didn't find it,
so an "Unknown process" dialog was shown to the user.

Discarding this type of connections avoids unknown process dialogs when
using Epiphany in particular. It retries to establish the connection
several times, and finally we're able to find the PID of the process.
2021-02-20 23:53:22 +01:00
themighty1
41172b65e5 minor fixes to prevent go vet from complaining 2021-02-13 19:18:38 +03:00
luz paz
d15d3465a9 Fix random typos
Found via `codespell v2.1.dev0`  
`codespell -q 3 -L ans`
2020-12-23 13:24:59 -05:00
Gustavo Iñiguez Goia
e13015ce67 updated import paths 2020-12-09 18:18:42 +01:00
Gustavo Iñiguez Goia
df952d974e fixed errors when IPv6 is not enabled in the system
If IPv6 was not enabled we failed to add IPv6 rules.

closes #96
2020-11-26 16:25:48 +01:00
Gustavo Iñiguez Goia
e8683e77be improved packets parsing
We were checking several times if a packet was IPv6.

Additionally we were itereating over all the layers of the packet, when
in reality we're only interested in network layer and transport layer.

This change brings down packets parsing from ~200µs to ~2µs.
2020-11-24 01:35:36 +01:00
Gustavo Iñiguez Goia
1e6d03e332 do not assign an IP to the DstHost field
In case we're connecting to an IP directly, or if an IP is not resolved,
leave the DstHost field empty and format it appropiately on the UIs.

Otherwise we can't know (easily) if the field DstHost of a connection is
an IP or a domain.
2020-10-19 01:29:00 +02:00
Gustavo Iñiguez Goia
d6cf18ef27 show domain name when establishing a new connection
When a new connection is about to be established and the system performs
a dns resolution, we displayed it like this: 9.9.9.9 (www.opensnitch.io)

It added visibility of what was going on, but if you created a rule to
filter by destination host, you were prompted twice to allow firstly the
DNS query, and secondly the TCP connection, which was a bit annoying.

Some users (#5) also asked to display just the domain, so now we only
display the domain name.
2020-10-19 01:02:05 +02:00
Gustavo Iñiguez Goia
a1bba4da3f send on new connection CWD and envrionment vars of the process
CWD allow us to know from where was a process executed.
The environment variables allows to know more about a process execution.
2020-06-04 01:14:25 +02:00
Gustavo Iñiguez Goia
6ee80b1640 Allow to change settings from the UI
(1/2)
We start receiving notifications from the UI, which allow us to change
configurations and perform actions on the daemon.

The concept of Node has also been introduced, which identifies every
daemon (client) connected to the UI (server).

These options has been added:
- Enable/Disable firewall interception (for all nodes)
- Change daemons (clients) configuration. globally or per node.
- Change prompt dialog options.

We have fixed some bugs along the way:
- Close audit client connection gracefully.
- Exclude our own connections from being intercepted.
- Better handling of client connection status with the UI.

We probably has also introduced some other bugs (not listed here).
2020-04-19 20:13:31 +02:00
Gustavo Iñiguez Goia
99ad5e531f fixed getting process uid under certain situations 2020-04-12 01:38:39 +02:00
Gustavo Iñiguez Goia
b9af7c2837 fixed compiling for arm and i386 2020-04-11 00:23:27 +02:00
Gustavo Iñiguez Goia
24ede1c92b netlink: get active connections by source port + protocol
- Dump connections from kernel querying by source port + protocol.
- Prioritize responses which match the outgoing connection.
- If we don't get any response, apply the default action configured in
/etc/opensnitchd/default-config.json

--

A connection can be considered unique if:
protocol + source port + source ip + destination ip + destination port

We can be quite sure that only one process has created the connection.

However, many times, querying the kernel for the connection details by
all these parameters results in no response.

A regular query and normal response would be:
query: TCP:47344:192.168.1.106 -> 151.101.65.140:443
response: 47344:192.168.1.106 -> 151.101.65.140:443, inode: 1234567, ...

But in another cases, the details of the outgoing connection differs
from the kernel response, or it even doesn't exist.

However, if we query by protocol+source port, we can get more entries, and
somewhat guess what program opened the outgoing connection.

Some examples of querying by outgoing connection and response from
kernel:

query: 8612:192.168.1.5 -> 192.168.1.255:8612
response: 8612:192.168.1.105 -> 0.0.0.0:0

query: 123:192.168.1.5  -> 217.144.138.234:123
response: 123:0.0.0.0 -> 0.0.0.0:0

query: 45015:127.0.0.1 -> 239.255.255.250:1900
response: 45015:127.0.0.1 -> 0.0.0.0:0

query: 50416:fe80::9fc2:ddcf:df22:aa50 -> fe80::1:53
response: 50416:254.128.0.0 -> 254.128.0.0:53

query: 51413:192.168.1.106 -> 103.224.182.250:1337
response: 51413:0.0.0.0 -> 0.0.0.0:0
2020-04-05 19:14:51 +02:00
Gustavo Iñiguez Goia
9e6860fe63 formatted connman/ 2020-03-06 21:44:47 +01:00
Gustavo Iñiguez Goia
6646ee469a Accept response from netlink just if inode is valid
Sometimes we get wrong values for Uid field, so just check if the inode
field is valid to accept the response from netlink.
2020-02-15 00:22:37 +01:00
Gustavo Iñiguez Goia
d8ad8de6ef Lookup inode and uid via netlink
It has some advantages over parsing /proc, like performance and
reliability.
2019-12-01 20:10:49 +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
7eec749498 allow to configure unknown conns interception
/etc/opensnitchd/default-config.json can now contain
"intercept_unknown": true|false
2019-11-01 01:00:10 +01:00
Gustavo Iñiguez Goia
845e6a704f Intercept and parse UDPLite connections
/proc/net/udplite[6]
2019-10-29 20:01:45 +01:00
Gustavo Iñiguez Goia
a0eacfb8b8 Allow to intercept localhost and multicast connections 2019-10-29 19:53:07 +01:00
Gustavo Iñiguez Goia
65c3790106 Prompt the user to allow/deny all outgoing connections
With the current implementation, it's not possible to know what
process/pid has created an outgoing connection, but there's still
valuable information that the user may want to know, so:

- display outgoing connections even if the process name/path is unknown.
 (src ip, dst ip, dst port, uid)
- get outgoing connection uid if kernel > 3.6.
2019-10-25 00:55:32 +02:00
Gustavo Iñiguez Goia
9cc3da6446 experimental cache of inodes and pids
Just an experimental cache of inodes and pids, which lowers the CPU
usage and improves user's experience.
2019-10-24 01:01:20 +02:00
Gustavo Iñiguez Goia
a7e9b5072f project import paths changed 2019-10-20 21:51:35 +02:00
Christina Lena Korosec
08c3e17c37
Fixes #228: Parse IP and port to uint 2018-12-13 12:08:44 +01:00
Jerzy Kozera
22c4aca5d0 IPv6 support 2018-11-21 22:57:43 +01:00
Armen Boursalian
b95c63f0c0 #176: IP -> CNAME -> orig. domain display 2018-08-28 08:20:42 -07:00
evilsocket
96cc94180e
misc: small fix or general refactoring i did not bother commenting 2018-04-16 19:28:28 +02:00
evilsocket
d4cca89329
optimization 2018-04-16 19:12:46 +02:00
evilsocket
fc97f5b431
misc: small fix or general refactoring i did not bother commenting 2018-04-10 13:06:02 +02:00
evilsocket
7e474a0514
refactored netfilter code, implemented SetVerdictAndMark method 2018-04-08 20:13:35 +02:00
evilsocket
8009743d60
when the thc kicks in and you find a better logic, better naming, better design and new ideas 2018-04-08 15:32:20 +02:00
evilsocket
34ec05a5d2
misc: small fix or general refactoring i did not bother commenting 2018-04-07 03:28:44 +02:00
evilsocket
5cef91e534
better protocol file manag. 2018-04-06 15:58:19 +02:00
evilsocket
726d0302d0
misc: small fix or general refactoring i did not bother commenting 2018-04-05 17:00:47 +02:00