-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A question about unrecognized connections #84
Comments
No that I can remember of. Those connections could be of a forwarded connection traversing the box, but we wouldn't intercept it anyway, because we only intercept NEW and RELATED connections. Also broadcast/multicast connections are a bit special (differ a bit as seen by iptables and netlink). There're at least two situations though where this can happen, and is when you come back from suspend the system or when you dis/connect to a wifi network. Usually the opened connections are in an invalid state, and the processes start closing/reestablishing them. Adding the state RELATED helped to identify some of these connections.
If the PID of the process who created the connection is not found on the first iteration, it could mean that the PID is in reality a TID, i.e.: the connection was opened by a thread of the process. As we don't parse Another case is when the process is a forked child, for example those launched by systemd. As far as I can remember, in this case the reported PID was of the systemd. |
Regarding the last case, for example fwupdmgr launched by systemd (fwupd-refresh systemd service) is not detected (using proc method):
netlink dumps correctly the inode of the connection but the PID is not found. Using audit is more likely to have success. If you launch it manually then yes I'm wondering if will have anything to do with the systemd sandboxing options. |
Thanks for the insights. Clarified a lot. DBG new connection tcp => 45017: -> :27359 uid: %!(EXTRA uint32=4294967295) Have you seen this before? What do you think the cause may be? |
Yeah, with transmission is fairly common to see those messages. I have no idea really, but it could be failed connection attempts:
maybe it happens so fast that when we query for it the kernel has already deleted the entry. I wrote some words regarding these issues here #10 (comment) and here #10 (comment) |
Some more examples for future reference:
So in this case, we should be able to find the PID. More than not finding the PID, in this case what intrigues me is why auditd does not detect it, or well, it's probably detecting it but for some reason we're not parsing the event correctly. I should probably analyze auditd logs as well. |
Just want to report that I ran an endless loop of dumping all TCP connections via netlink with NLM_F_DUMP and all TCP stated (mask 0xfff) while adding a new torrent to transmission. Only for ~ 1/5 unknown connections I would find the source port of the unknown connection in my netlink dump. Unfortunately netlink doesn't provide a way to subscribe to new events for inet sockets, we can only poll it periodically. |
The key here would be to use eBPF if it's available: https://github.com/iovisor/bcc/blob/master/tools/tcplife.py There's a fork who integrated it in opensnitch, maybe we can reuse it. On the other hand, ideally we should have to use XDP to block connections. But it's a faily new feature and it's not available in many systems. |
Correct, in particular non-blocking failed connection attempts. Sometimes the connection will be discarded because it's not found via netlink, and other times will pass all the checks until it fails to retrieve the PID of the process. With this example you can reproduce the issue (port and ip captured sniffing Transmission traffic):
|
Nice, thank you. |
Regarding this problem, I've modified the The benefits of doing this is that we only cache and intercept PIDs that have created network activity, instead of cache every single execution of a process in the system. If we wanted to monitor whenever a new process is launched, we should do it via netlink (PROC_EVENT_EXEC, PROC_EVENT_FORK, PROC_EVENT_EXIT), to not rely on On the other hand, new outgoing connection: inet_sock_set_state: It's not bulletproof. Sometimes the source port is 0 (probably when connection fails to establish), so the new outgoing connection doesn't match. But still, it seems to work way better than the current method. |
@gustavo-iniguez-goya, I remember reading in other github issues that you've done a lot of research into this area of trying to pin down where the unrecognized connections come from.
Have you seen connections which the first time around are not found via netlink nor via tcp netstat, but if you loop again they will be found via netlink or netstat?
Sort of like a delay in the kernel to update its netlink tables or something?
Or has it always been the case that if the connection is not found on the first netlink/netstat iteration, it means that's the end of it?
Just throwing some ideas around. Maybe you already know these things, so it's quicker to ask you than to test whether it is the case.
The text was updated successfully, but these errors were encountered: