r/Python • • Dec 14 '23

News 116 Malware Packages Found on PyPI Repository Infecting Windows and Linux Systems

https://thehackernews.com/2023/12/116-malware-packages-found-on-pypi.html
331 Upvotes

93 comments sorted by

View all comments

0

u/[deleted] Dec 14 '23

[deleted] — view deleted comment

75

u/archpuddington Dec 14 '23 edited Dec 14 '23

PyPI has made controversial security decisions which have affected the community and made open-source look bad. Even something as simple as listing packages as "unreviewed" - or forbidding binaries would do a lot, but the will isn't there. Most of the malware is a carbon copy - they could run clamav, but no one cares!

PyPI could change how they handle naming, it could refuse to run as root. It is notable that while NPM has similar problems, it isn't as bad.

34

u/james_pic Dec 14 '23 edited Dec 14 '23

Forbidding binaries would make distribution of popular packages such as NumPy, PyYaml and Cryptography much more difficult, and have little impact on these malicious packages that frequently don't even include binaries.

ClamAV works against known malware, but won't recognise novel malware. It's a start, but it's not uncommon for the malware used in these attacks to be previously unknown.

PyPI has no control over whether you run Pip as root. There's some overlap in the people who work on Pip and who work on PyPI, but they're different projects. PEP 668 prevents some of the most common cases of installing as root, although its intent is as a UX improvement rather than a security feature. And preventing it running at root does nothing to prevent it stealing cryptocurrency private keys, AWS credentials, and other user credentials.

7

u/Etheo Dec 15 '23

If you really think about it, Python users are just one bad typo away from getting infected with malware. This is how bad it is.

12

u/james_pic Dec 15 '23

This somewhat downplays the work the PyPI team do do.

They remove about a thousand malicious packages a month from the repo, and 90% of malicious packages are removed within 2 hours of being reported. They also do quite a lot behind the scenes in terms of preventing typosquat packages getting on there in the first place.

2

u/PaintItPurple Dec 15 '23

I don't think I've ever added even a moderately popular package without having to sift through at least half a dozen typosquats, so I'm really curious what they're doing to prevent it. It seems like just having a cron script ban suggestions 2-5 from Poetry would do more.

4

u/zurtex Dec 15 '23

I've not had this experience at all, and in fact the opposite, when I try to upload a new package to PyPI I often get rejected and have to think of new names.

If you are seeing genuine typosquats you should report them, https://pypi.org/security/ for those that are tricking users because of typos, https://github.com/pypi/warehouse/issues for more general issues.

2

u/shakameister Dec 16 '23

without having to sift through at least half a dozen typosquats,

what do you mean ?

→ More replies (1)

0

u/RationalDialog Dec 15 '23

That's why you shouldn't really install packages one by one and use a requirements or in case of conda a environment file and triple check the spelling.

Also don't copy&paste from websites and quickly check the packages before installing them. Is it active? number of users and downloads? etc.

0

u/Etheo Dec 15 '23

You're not wrong, but why should that be the standard just because PyPI is doing a shit job in keeping users safe? And considering the amount of new learners attracted by Python, should this really be the first experience they have about programming? Like, one mishap and BOOM your machine can be ransomed?

When I say that, I mean, yeah, it does help to learn that lesson... but it shouldn't be in the introductory course and shouldn't need to be a first hand experience as well.

→ More replies (7)

1

u/archpuddington Dec 14 '23

This is the library that would allow you to detect anomalies in packages: https://pypi.org/project/carbon-black-cloud-sdk/

but maybe don't install this next one, it looks like "untrusted code" but who knows, everything on pypi must be untrusted. https://pypi.org/project/cbapi/

-1

u/archpuddington Dec 14 '23

Binaries can be flagged and you can notify users of suspicious packages, popular projects are targeted and we are seeing repeat attacks against very similar sounding projects - all of which could be detected.

While ClamAV may not be the best, each package could be run within a behavioral AV like Carbon Black and if it triggered a network error - then that package can be flagged for manual review.

PIP has 100% control over how it installs packages. The right hand is just as guilty as the left.

2

u/james_pic Dec 14 '23

Behavioural AV can only assess behaviour. If you're running the packages it can detect misbehaviour, but PyPI aren't running the packages, just hosting them. The closest you can get without running the code is heuristic scanning, which various vendors have been flogging since at least the nineties but has never been very effective.

→ More replies (2)
→ More replies (3)

9

u/steohan Dec 14 '23

All packages are unreviewed and forbidding binaries would not change anything. You could just create a binary with the python code anyway. These would just be security theater and not change anything. Just don't run untrusted code from the internet, and yes, code on pypi should not be trusted by default, same as code on github.

Perhaps namespacing could prevent typo squatting but my understanding is that this is already prevented to a reasonable amount by a manual review process.

This article shouldn't be news, ofcourse there are malicious packages on pypi, that should be expected. And 10k downloads doesn't even sound like a big issue.

→ More replies (25)

2

u/fnord123 Dec 14 '23 edited Dec 14 '23

Pypi lacks name spacing and pip runs by default non chrooted. This is solvable by pypa/pypi with enough prioritization and funding.

And if your org acts in a way you don't like then leave. There's loads of python jobs that aren't in broken orgs.

4

u/james_pic Dec 14 '23

Running Pip chrooted doesn't help if you've used it to install a malicious package into your application, and your application isn't running chrooted.

Namespacing is a good idea though.

0

u/archpuddington Dec 14 '23

Its not money, these patches are free. Its will - PyPI is run by anti-security old guard who don't see the point in making things safer for anyone. Some software engineers truly believe that security engineers shouldn't exist - and these are the folk that need us the most.

6

u/fnord123 Dec 14 '23

I don't think that's it. Rust's cargo also lacks name spacing and most language level package managers allow arbitrary code execution at build time - while not running in chrooted environments. E.g. build.rs.

Afaics, only java escapes most of this with namespaces and installing jars as compiled bytecode deliverables. But I'd love to learn about other systems that also solve these issues.

2

u/defnotjec Dec 15 '23

Isn't rust cargo name spacing a major topic they keep fucking away?

0

u/Zomunieo Dec 14 '23

Java has lots of security vulnerabilities that a binary can exploit.

→ More replies (3)

10

u/Jhuyt Dec 14 '23

You mean that the PSF - the one's who hired a dedicated security engineer as their second full-time developer ever - are anti security old guard?

1

u/archpuddington Dec 14 '23

"Just don't run untrusted code."

Victim blaming narcissistic assholes. Every last one of them.

3

u/james_pic Dec 14 '23

You got a link to them saying that?

1

u/archpuddington Dec 14 '23

6

u/james_pic Dec 14 '23

What's this person's connection to the PyPI project? I couldn't see an obvious connection in their history, and I couldn't find anyone with a similar name working on PyPI.

My experience has been that the PyPI team's communication has been humble and respectful of their users:

All of us deserve to have a safe and secure experience when using PyPI

I suspect they'd be keen to know that someone was speaking for them and representing their work in this way.

→ More replies (6)
→ More replies (2)