Commit graph

14 commits

Author SHA1 Message Date
Gustavo Iñiguez Goia
e5b54f0a6b eBPF: ignore netlink errors if there're no connections
When enabling the eBPF monitor method we dump the active connections,
but in some cases there're no active connections, and because of this
we're failing enabling this monitor method.

If there're no connections established, netlink returns 0 entries. It's
not clear if it's an indication of error in some cases or the expected
result.

Either way:
- fail only if we're unable to load the eBPF module.
- dump TCP IPv6 connections only if IPv6 is enabled in the syste,-
2021-05-29 00:16:18 +02:00
Gustavo Iñiguez Goia
e13015ce67 updated import paths 2020-12-09 18:18:42 +01:00
Gustavo Iñiguez Goia
c1e8bc3156 netlink: de/serialize ipv6, dump socket list
- De/Serialize IPv6 connections.
- Added SocketsDump() to list all sockets currently in the kernel.
- [proc details] Resolve all the sockets an application has opened
  and translate them to network data, e.g:
  ```
  ls -l /proc/1234/fd/
    0  ... 25 -> socket[12345678]
  ```
  to
  ```
    0 .... 25 -> socket[12345678] - 54321:10.0.2.2 -> github.com:443,
  state: established
  ```
2020-11-20 00:53:29 +01:00
Gustavo Iñiguez Goia
d6af47813e netlink: exclude connections with invalid inode 2020-04-12 12:33:59 +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
7cbcc4d736 reformatted netlink/ sources, fixed typo 2020-03-06 21:02:34 +01:00
Gustavo Iñiguez Goia
848f72de68 Fixed netlink socket querying
man sock_diag:
"If the nlmsg_flags field of the struct nlmsghdr header has the
NLM_F_DUMP flag set, it means that a list of sockets is being
requested; otherwise it is a query about an individual socket."
2020-02-20 01:45:02 +01:00
Gustavo Iñiguez Goia
a13f42d98b netlink: fixed connections querying
also code simplified.
2020-02-18 02:05:15 +01:00
Gustavo Iñiguez Goia
a4a5637a22 Fixed errors
Typos were made.
2020-02-13 23:19:15 +01:00
Gustavo Iñiguez Goia
d5b7c597ae Fixed typo in netlink parameter
Thanks to @Ph0rk0z for pointing it out.
2020-02-13 10:01:22 +01:00
Gustavo Iñiguez Goia
54bb5dcca5 Fixed and improved netlink communications
Fixed invalid uid.
Fixed/improved netlink sockets querying.
2020-02-12 22:52:24 +01:00
Gustavo Iñiguez Goia
a978f405fc Fixed missing returned value 2020-02-05 00:26:32 +01:00
Gustavo Iñiguez Goia
996e9ad888 Added netlink IPv6 uid/inode lookup support 2019-12-02 23:53:41 +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