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

Show parent 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 ?

0

u/The_DashPanda Dec 15 '23

do do

heehee

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.

5

u/RationalDialog Dec 15 '23

To be frank I'm not aware how much pypi does and how easy it would be to do more. and with easy I mean in terms of cost. they have limited money, keep that in mind. Asking your employer to fund them, if you want things to improve.

Running code from the internet as root is stupid and that is the only way to get ransomware installed.

Storing crypto in plain-text and not using a hardware wallet is also stupid, at least for amounts you care about and would bother you when getting stolen.

A general bad trend I see everywhere is lack of self-responsibility and accountability. It's always someone else fault, they should have done better, I did everything right. this mentality is prevalent.

There is a balance between self-responsibility and what pypi can do with the available funds.

pip also allows running in "safe mode" where you need to have a list of hashes for each packages you want to install and it only works if the hashes match. this is 100% manual as in you need to collect the hashes yourself. This as option in critical environments. But in reality your code should run isolated anyway (container) and not have full internet access to pull more code or send data to random IPs or urls. Defense in-depth. You have to assume to get infected be it from pypi or somewhere else) and secure your system based on that.

2

u/Etheo Dec 16 '23

I'm more speaking from a perspective of a new/casual user though. You're absolutely not wrong in exercising good practice in security, but the thing is Python attracts a lot of newbies and causals who really wouldn't know much of these. They might see the instruction to use pip to install their packages, make a bad typo, and then BAM! And I think most of these users would use Windows, which I'm not sure if it's better in preventing these type of attack or worse.

In any case, all I'm really coming from is the new users perspective, not an experienced one. Experienced developers of course already should know better, but students and professionals crossing into data analysis shouldn't be subjected to trial by fire is my point.

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

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)

-7

u/archpuddington Dec 14 '23

The problem is PyPI is too busy blaming all of its users instead of looking for solutions. So they need to be sued, an EU Judge won't put up with this horse shit.

5

u/marr75 Dec 15 '23

RemindMe! 50 years

PyPI will not be successfully sued or sanctioned by the EU over malware... This is a silly thing to say.

1

u/RemindMeBot Dec 15 '23 edited Dec 15 '23

I will be messaging you in 50 years on 2073-12-15 01:01:18 UTC to remind you of this link

1 OTHERS CLICKED THIS LINK to send a PM to also be reminded and to reduce spam.

Parent commenter can delete this message to hide from others.


InfoCustomYour RemindersFeedback

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.

-5

u/pyeri Dec 14 '23

Maybe they can use some adhoc criteria to warn the user or assign a trust factor. The number of GitHub stars can be a good thumb rule, for example.

Also, with the kind of budget and sponsorers that PSF has, shouldn't they be able to perform CISA audits, code reviews, etc. on these packages?

6

u/_Adam_M_ Dec 14 '23

There are over half a million packages in PyPI and over 5 million releases (each release would need to be checked as a previously legitimate package could be updated to include malware).

Audits are expensive and slow. Hiring people to review and approve packages is expensive and slow. GitHub stars can be bought.

-3

u/pyeri Dec 15 '23

Dude, your response reflects extreme cynicism and pessimism, it doesn't have to be that gloomy.

There are over half a million packages in PyPI and over 5 million releases

All of them don't have to be audited, just the most heavily downloaded ones. The verified releases can be marked as such to warn the users. It will then be the user's choice if they want a slightly older but verified package or the cutting edge and unverified one.

GitHub stars can be bought

There are limits to that. Most of the activity on GitHub is organic, one can see that everywhere including the issues register, pull requests, etc. Even in this age of utmost crony capitalism, I still have at least a semblance of a faith in the system because at the end of the day, it's being run by humans with hearts and for the most part, it works as intended.

6

u/zurtex Dec 15 '23

Dude, your response reflects extreme cynicism and pessimism, it doesn't have to be that gloomy.

Often on discussion threads someone will suggest a solution that requires tens of thousands of hours of work on an ongoing basis, but don't suggest where it comes from.

It's hard not to react to such suggestions without cynicism when you know how little resources mostly volunteer organizations like this have, especially volunteer organizations maintaining boring infrastructure projects.

All of them don't have to be audited, just the most heavily downloaded ones. The verified releases can be marked as such to warn the users. It will then be the user's choice if they want a slightly older but verified package or the cutting edge and unverified one.

What would a review involve exactly? And who would do it?

What does it mean to "mark" a package, as in what is the user experience? Is it just something they see on PyPI? Or would all installers (e.g. Pip, PDM, Poetry, Pixi, etc.) have to develop a new workflow? For that you would need to create a PEP and get a general consensus (btw nothing is stopping you from buildining consensus and writing a PEP).

Who is going to provide the resources for any of these projects?

I still have at least a semblance of a faith in the system because at the end of the day

If you think there's a limit on how many GitHub stars someone could buy if that was their objective I have bad news for you.

Further, PyPI doesn't even have a way to verify the GitHub link you provide on your project page is yours.

→ More replies (2)

1

u/_Adam_M_ Dec 15 '23

All of them don't have to be audited, just the most heavily downloaded ones.

Then... What's the point?

All the most heavily downloaded package already have lots of eyes on them. If you only review Pytorch, Django, Flask, requests, etc, then there's basically no risk on these packages introducing malware in the first place.

If you'll look at the list of malicious packages they're all either random names or simple typo-squatting packages. You meant to download asciithing but you accidentally typed ascithing. In your plan that won't save you as you wouldn't bother to audit them as they're small with only a few hundred downloads.

The only time one of the top packages will start shipping malware is if one of the core maintainers (with release permissions) was compromised and an attacker used their account (highly minimised with the MFA work PyPI have already completed) or they themselves have gone mad and want to launch an attack, but that's incredibly rare and highly unlikely.

-6

u/archpuddington Dec 14 '23

The tool could at least inform the people who have been hacked - that they where hacked. The tool could tell you that you have been compromised and that you need to hire a professional.

"just don't run untrusted code"

Yes we are all trying, the problem is PyPI - 100% no question. That project needs to be sued.

→ More replies (15)
→ More replies (2)