Live data from Hacker News

Two malicious Python libraries caught stealing SSH and GPG keys

zdnet.com

241–250 of 323 posts

Re: Two malicious Python libraries caught stealing SSH and GPG keys

#241
post #239

Earlier quoted context omitted.

macOS has this already.

Does it? On OpenBSD, Chrome cannot read my ~/.ssh directory, can the same guarantee be made on Mac?

Yes, you can write custom sandbox profiles and apply themselves to yourself using sandbox_init(3).

Re: Two malicious Python libraries caught stealing SSH and GPG keys

#242
post #114
post #56

Earlier quoted context omitted.

"Solid SELinux policy" is really the hard part there. When I pip install paramiko, I do, in fact, want it to have access to my SSH keys. When I pip install ansible, I want ansible to be able to shell out to OpenSSH to use my keys. If I write custom Python code that calls gpg, I want that custom code to be able to load libraries that I've pip installed without the gpg subprocess being blocked from loading my keys. If…

The value-add for SELinux is that the security boundary is no longer the user. Prior to SELinux a process running as `bob` is allowed to access anything that Bob himself can access. It at least pushes the boundary to I want to allow X program to access Y instead of I want to allow X user to access Y. Using a user account per-app only really works elegantly on single user systems where there are a small number of apps…

> bob-firefox, bob-vim, alice-evolution, alice-calculator,... would be a nightmare to maintain compared to being able to apply policy to the program itself.

This is how Android works, btw. Each app has its own UID.

And the standard SELinux policies don't solve this problem, anyway - when there are a small number of apps, you can give them each a context, but maintaining one for hundreds or thousands of apps is a nightmare. For web serving itself, quoting from https://linux.die.net/man/8/httpd_selinux :

    The following process types are defined for httpd:*

    httpd_cvs_script_t, httpd_rotatelogs_t, httpd_bugzilla_script_t, httpd_smokeping_cgi_script_t, httpd_nagios_script_t, httpd_dirsrvadmin_script_t, httpd_suexec_t, httpd_php_t, httpd_w3c_validator_script_t, httpd_user_script_t, httpd_awstats_script_t, httpd_apcupsd_cgi_script_t, httpd_nutups_cgi_script_t, httpd_munin_script_t, httpd_openshift_script_t, httpd_sys_script_t, httpd_dspam_script_t, httpd_prewikka_script_t, httpd_git_script_t, httpd_unconfined_script_t, httpd_t, httpd_helper_t, httpd_squid_script_t, httpd_cobbler_script_t, httpd_mediawiki_script_t*
SELinux works elegantly on a very lightly configured system where there are a small number of apps and you got them all from the distro.

Re: Two malicious Python libraries caught stealing SSH and GPG keys

#243

I don't know what the solution is but it feels like this is a much bigger issue and we need some rethinking of how OSes work by default. Apple has taken some steps it seems the last 2 MacOS updates where they block access to certain folders for lots of executables until the user specifically gives that permission. Unfortunately for things like python the permission is granted to the Terminal app so once given, all pr…

Yep, and Apple, Google and Microsoft aren't helping. Particularly bad these days is the idea of granting apps permissions; for example, if I want to deploy a new Google Drive application for some whiz-bang thing, I almost certainly need to "Grant read and write for all documents." Well, I don't want to do that, so I don't use any Google Drive add-ons ever. Is there a way to restrict privileges by folder? Nope! Same is true for Microsoft Office 365. Apple is trying, but still a long way to go.

Re: Two malicious Python libraries caught stealing SSH and GPG keys

#244
post #112

Earlier quoted context omitted.

> SELinux has been able to solve the problem of "if a policy says X can't get to Y, prevent X from getting to Y" for years. Regular UNIX permissions have been doing the same for decades. (Yes, SELinux and regular UNIX permissions take a different approach / let you write the policy differently, but that's the problem they're fundamentally solving; given a clear description of who to deny access to, deny this access.)…

Is it possible the OS should be designed so only the OS can read the actual private key so then at least at some level some apps don't ever need to see the key, they just need permission to authenticate.

As described in a sibling thread, while that contains the damage, that doesn't actually solve the problem - you're still giving malicious code permission to authenticate.

Re: Two malicious Python libraries caught stealing SSH and GPG keys

#245
post #184
post #162

Earlier quoted context omitted.

On the contrary, this wouldn't even need to be hidden if it was closed source. It was caught because it's open source.

Possibly, but some of the solutions proposed, e.g., monitoring of network activity, would work either way. It concerns me that one of these sat out there for a year.

But it's not like malicious activities could only involve the network. Also, it's possible to obfuscate network activity and hide such things among legitimate traffic.

> It concerns me that one of these sat out there for a year.

Certainly it being open source doesn't guarantee that someone will notice such things, but it raises the probabilities. It could have been like that longer if it were closed source.

Re: Two malicious Python libraries caught stealing SSH and GPG keys

#246
post #239

Earlier quoted context omitted.

Does it? On OpenBSD, Chrome cannot read my ~/.ssh directory, can the same guarantee be made on Mac?

Yes, you can write custom sandbox profiles and apply themselves to yourself using sandbox_init(3).

Good to know, but I don't need to write anything on OpenBSD. The protection is just enabled by default. That is more comforting to me as a user.

Re: Two malicious Python libraries caught stealing SSH and GPG keys

#247
post #246

Earlier quoted context omitted.

Yes, you can write custom sandbox profiles and apply themselves to yourself using sandbox_init(3).

Good to know, but I don't need to write anything on OpenBSD. The protection is just enabled by default. That is more comforting to me as a user.

Certain programs have default protections applied to them, such as most App Store apps.

Re: Two malicious Python libraries caught stealing SSH and GPG keys

#248
post #243

I don't know what the solution is but it feels like this is a much bigger issue and we need some rethinking of how OSes work by default. Apple has taken some steps it seems the last 2 MacOS updates where they block access to certain folders for lots of executables until the user specifically gives that permission. Unfortunately for things like python the permission is granted to the Terminal app so once given, all pr…

Yep, and Apple, Google and Microsoft aren't helping. Particularly bad these days is the idea of granting apps permissions; for example, if I want to deploy a new Google Drive application for some whiz-bang thing, I almost certainly need to "Grant read and write for all documents." Well, I don't want to do that, so I don't use any Google Drive add-ons ever . Is there a way to restrict privileges by folder? Nope! Same…

> Is there a way to restrict privileges by folder? Nope!

Playing devil's advocate... I'm sure most folks here appreciate that providing granular level of permissions/restrictions can often lead to a less secure environment!

Users (of pretty much every skill level) quickly become overwhelmed and give up.

I recall advocating that a large client group manage their own permissions in Sharepoint. It was a painful and futile exercise! Though really not much different than IT admins trying to managing security of a large organization using active directory.

Re: Two malicious Python libraries caught stealing SSH and GPG keys

#249
post #11
post #2

Alarming given that pypi is treated as trusted by many I think (even if it shouldn't)

What is trusted then, the Anaconda base repo?

I don't know the answer frankly.

The serious devs in actual dev shops I've asked answered with something like:

>We do code reviews on the libraries we use. Basically if someone wants a library they're responsible for checking it

Me: Isn't that a shtload of work with new versions etc

>Yeah so we tend to lag behind official versions quite a bit

It sounded like they host local mirrors of some sort with just the vetted code. Though I think vetted here is a quick glance over for shady sht rather than true security vetting

Re: Two malicious Python libraries caught stealing SSH and GPG keys

#250
post #192
post #56

Earlier quoted context omitted.

"Solid SELinux policy" is really the hard part there. When I pip install paramiko, I do, in fact, want it to have access to my SSH keys. When I pip install ansible, I want ansible to be able to shell out to OpenSSH to use my keys. If I write custom Python code that calls gpg, I want that custom code to be able to load libraries that I've pip installed without the gpg subprocess being blocked from loading my keys. If…

If you are installing paramiko or ansible you know what you are doing. It should be end user conscious choice to give them access. You should not be prevented to give that access but also that access should not be granted without end user knowing it. You don't want to instal "some library, from somewhere" to have automatically access to everything on your machine. I also agree with all people that comment that it is…

That approach has two problems. First is that access isn't fine-grained enough - you often have to grant access to far more than you intend. Second is that there's no way to know why an app is asking for access, or to be certain what it's going to do with that access.
Post reply on HN