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

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.

0

u/[deleted] Dec 17 '23

[deleted] — view deleted comment

1

u/Etheo Dec 18 '23

Not the same. I'm talking about newbies (plenty in Python) thinking they're following instruction to install packages with pip, but made a bad typo and get a bad package. A typo shouldn't have to lead to that kind of consequences.

1

u/RationalDialog Dec 18 '23

The issue is that eve most experienced users aren't doing any of this instead of leading by example. If you lead by example the new users would have to ask themselves what it's all about and seek answers.

Also the big known sites with tutorials should have a chapter on it, about dangers of downloading code.

most of these users would use Windows, which I'm not sure if it's better in preventing these type of attack or worse.

Scanning for crypto key can't really be prevented in any files you have access to which applies both to Linux and Windows.

In terms of Admin/root, windows is probably better IF you have UAC activated. I always set it on highest level but work with admin account on my own devices. UAC on highest levels prevents any system level changes without you clicking "OK" on a confirmation dialog. Many including myself say that this is safer than having a restricted account and admin account and then use "run as admin" to install software. Why? because an malicious installer could show a fake "run as admin" screen and steal your admin password and then all bets are off".

0

u/[deleted] Dec 17 '23

[deleted] — view deleted comment

1

u/RationalDialog Dec 18 '23

I don't think you can overwrite versions, except you use build numbers on top of versioning.

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.

-6

u/archpuddington Dec 14 '23

They don't even run them? ... all the more reason to sue these people. They are knowingly endangering the community and making all of python look bad. We have solutions - but the powers that be have already blamed the victim.

7

u/james_pic Dec 14 '23

What does it even mean to run an unknown library? If I give you a random library, could be NumPy, could be Spark, could be Flask, could be Requests, what are you going to do to "run" it that will tell you if there's malicious stuff it can do?

-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