Skip to content
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

Does the program understand processes hierarchy ? #406

Open
Danny3 opened this issue May 4, 2021 · 8 comments
Open

Does the program understand processes hierarchy ? #406

Danny3 opened this issue May 4, 2021 · 8 comments

Comments

@Danny3
Copy link

Danny3 commented May 4, 2021

Hello everyone !

I have seen the the program's pop-ups sometimes show generic tools want to connect to the internet, like http, curl, etc.
So it got me wondering...
What if we have two programs:
Program 1
Program 2
And both take advantage by a third party tool like CURL (or wget)

It looks to me that if I want to allow Program 1, but deny Program 2, it would seem to me that I need to also allow CURL for Program 1 to work.
But doing it so, I don't see what's stopping Program 2 to use the allowed CURL too to send and receive data it wants even though Program 2 is denied ?

Can OpenSnitch look at who (which program) called CURL and allow or deny its connection based on allowed / denied permission of the caller, making the permission for CURL dynamic ?

From what I know systemd should have a hierarchy with which programs started which programs, but I don't know if it can track who called who

Does OpenSnitch has such capability or could it be implemented in the future with the help of systemd or other tool ?

@gustavo-iniguez-goya
Copy link
Collaborator

gustavo-iniguez-goya commented May 4, 2021

Hi @Danny3 !

Right now we don't track the Parent PID of a process that's trying to open a new connection. So if you allow Program1 or Program2, you don't explicity allow all the children initiated by these processes (curl, wget, nc, telnet, etc).

For example Spotify. If you allow Spotify, you'll still be prompted to allow wget. But if you allow wget only by name (wget) or by path (/usr/bin/wget), then Edge (just an example) would be able to use wget freely.

For now what you can do is to deny/allow wget/curl/etc not only by path, but also by path + arguments + dest IP + dest port.
That way, you can allow/deny connections made by Program1 using curl/wget, but restricting to where it can connect to.
If Program2 launches a wget/curl to open a new connection, you'll be prompted to allow/deny it.

What's not possible right now is to block or deny connections initiated by children of another process.

We could study it for future releases.

@Danny3
Copy link
Author

Danny3 commented May 5, 2021

Thank you very much @gustavo-iniguez-goya for the reply !
"deny/allow wget/curl/etc not only by path, but also by path + arguments + dest IP + dest port."
Could I do that from the GUI ?
Because I see drop-downs only for one option at a time, I don't know how can I add multiple ones and I think it will be better for me to just wait for something more user friendly (easier to understand how to do it).

My desktop environment is KDE Plasma that has the possibility to optionally use systemd for startup, which I have activated.
https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/47
I can see now in KSysGuard ( its sytem monitor), in tree view, that the processes are displayed in the right hierarchy like:
systemd
| ----------plasmashell
| ------------------------- Firefox
| ---------- Child 1 of Firefox
| ----------- Child 2 of Firefox and so on
..............................................................
I assume is taking advantage of Cgroups as explained here:
https://blog.davidedmundson.co.uk/blog/plasma-and-the-systemd-startup/
And here (by clicking on the " cgroups for applications" in the above article):
https://blog.davidedmundson.co.uk/blog/modern-process-management-on-the-desktop/

Could all this work done by the KDE developers to start programs in their own CGroups (if I got that right) help in any way in the future OpenSnitch to track and maybe control together programs and their children ?
Or could CGroups be used anyway, so it works on all desktop environments, non only in the fortunate cases like KDE Plasma ?

@gustavo-iniguez-goya
Copy link
Collaborator

Could I do that from the GUI ?

Yes, you can either do it from the pop-ups by clicking on the [+] button:
image

Or you can allow it and edit it later from the Rules Tab -> Permanent or Temporary, by double clicking on the rule, or right click on the rule -> Edit.

As you can see there're plenty of options to configure it. If you have installed OpenSnitch recently get used to it, it's not complicated (well, a firewall is something complicated anyway, but we try our best to ease its usage).

Could all this work done by the KDE developers to start programs in their own CGroups (if I got that right) help in any way in the future OpenSnitch to track and maybe control together programs and their children ?

No, I don't think it's related. We could track Parent PIDs regardless of how they display the processes' hierarchy or how they group (containerize) processes. This is already happening if you use firejail, systemd (yes, many system services are already containerized) or docker/podman/k8s, etc.

But that'd be a new feature, something like: [x] Allow connections from childs of this process , or [x] Allow connections from these childs of Program1: [x] wget [x] curl

@BetweenTheKeyboardAndChair

I have a different use case where the ParentID would be useful.

I would like to be able to set the duration to "this instance of the app", where the instance includes any child processes.

Use case: When I open an app, e.g. a browser I would like it to have access until I close the browser. (I close my browser many times a day.) Whenever I am using a less trusted app (e.g. tax software), I ensure the browser is closed. This way I can catch any attempts to piggyback out through the browser. e.g. A button that when clicked, tries to use the default browser to their URL.

I find this also makes configuring apps a bit easier. An app update often starts many processes, so the "once" isn't a great solution. I can guess at the time the updates will take. I find it easier to do the updates and then restart the process to reset the firewall permissions. Now I know if the app tries anything after the update and before the timer expires.

@gustavo-iniguez-goya
Copy link
Collaborator

Interesting use case @BetweenTheKeyboardAndChair , thank you for sharing.

Filtering by "this instance of an app" is an old (ooold) request. I want to finish some things first, but it's definitely a feature that would be great to have.

@gustavo-iniguez-goya
Copy link
Collaborator

It turns out that today while being away from the computer I had an alert of a not answered output connection:

image

what is interesting here is the domain that gvfsd-http has tried to connect to: i.scdn.co, which is a domain of Spotify. If we'd have logged the PPid, probably it'd have been of the spotify.

@deliciouslytyped
Copy link

I'm currently looking for solutions for whitelisting connections / firewall the network of containers / firejail / bubblewrap / etc, I would very much need / like this.

Do you know any alternative solutions? My google searches have yielded very little information.

@gustavo-iniguez-goya
Copy link
Collaborator

Hi @deliciouslytyped !

OpenSnitch should be able to intercept connections from applications launched from firejail/bubblewrap. I'm using chromium/firefox sandboxed with firejail and connections are intercepted just fine.

For containers (like docker) we need to add a fw rule: https://github.com/evilsocket/opensnitch/wiki/System-rules-legacy#intercepting-connections-from-containers

gustavo-iniguez-goya added a commit that referenced this issue Sep 30, 2023
 - 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
gustavo-iniguez-goya added a commit that referenced this issue Feb 13, 2025
Some use cases:

 - Reject connections initiated by certain paths:

   Deny all connections initiated by cron*:
        /usr/sbin/cron
            /usr/bin/curl

     "action": "reject",
     "operator: {
        "type": "list",
        "operand": "list",
        "data": "",
        "list": [
     	   {
                "type": "regexp",
                "operand": "process.parent.path",

                // /usr/bin/crond , /usr/bin/crontab, ...
                "data": "^/usr/(s|)bin/cron"
           }
        ]
     }

 - Reject or Allow connections of binaries launched by another app:

       "action": "allow",
       "operator": {
       	"type": "list",
       	"operand": "list",
       	"data": "",
       	"list": [
       	    {
                "type": "simple",
       	        "operand": "process.parent.path",
       	        "data": "/opt/spotify/bin/spotify"
       	    },
       	    {
       	        "type": "simple",
       	        "operand": "process.path",
       	        "data": "/usr/bin/wget"
       	    }
       	  ]
       }

You can also combine multiple parent paths, to allow a command launched
from a specific chain of processes:

    /usr/lib/systemd/systemd
        /usr/sbin/cron
             /bin/sh
                 /usr/bin/curl

The order is checked from the newest process to the oldest (curl -> sh
-> cron -> systemd)

The operand can be used with any of the existing types (simple, regexp,
etc).

Related: #406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants