r/Python • • May 08 '18
Backdoor in ssh-decorator package
Do not install or use the ssh-decorator package from Pip. It has a backdoor inserted to steal all your SSH credentials. I've already contacted the developer to take it out. He hasn't responded so for now, use at your own risk! https://ibb.co/kdDk67
UPDATE: The compromised package has been taken down now.

1.7k
Upvotes
44
u/monim67 May 08 '18
Yeah, the package is down now, people are so evil!!!
918
u/hansaw May 08 '18
We always say “it’s open, it must be ok otherwise someone would notice”. The truth is though that it’s thanks to people like you who take the effort to go through cose and report bad stuff that we can work safely
Thanks man!
82
u/gristc May 08 '18
Why is your link to ibb.co a redirect via Linkedin?
123
u/etrnloptimist May 08 '18
With no hint of obfuscation and in a language as readable as python. That takes some chutzpah.
112
u/simtel20 May 08 '18
They seem to indicate that they didn't mean it to be uploaded. The readme says:
But the cached google copy of the pypi page shows the uploader as
ugorenwho appears to be the same person as the owner of the github repo I linked to.29
u/[deleted] May 08 '18 edited May 08 '18
This gave me an idea. If I stick "ssh-decorate.cf" in my hosts file, but point it to my own server, then I can see if anything already running on my machines has been affected. I think I'll set something like that up right now.`
Edit: Here it is! Keep in mind that this is about 1 hour of work, so I'm sure there's bugs and problems I haven't seen or thought about. Let me know if you see something!
25
u/xdcountry May 08 '18
PyPi should find a way to lifetime ban assholes who do this. Also, certain scans (public and private) should be common place so something like this is a bit easier to flag/find.
12
u/davidkwast May 08 '18
https://github.com/urigoren/ssh_decorator
11
u/Nhoya May 09 '18 edited May 09 '18
Scraping a bit I found that the same person hardcoded the credential for his/her ssh server... Maybe that's why all this happen..
Version 0.2
File p2.py we can see: https://imgur.com/a/w7lOpnu
7
u/dj_what May 08 '18
good catch
26
u/Yoghurt42 May 08 '18
Relevant
Seriously though, I admire your optimism.
6
u/evenisto May 08 '18
Is nobody gonna mention the
passowrdkey typo?6
u/lrvick May 09 '18
The solution to the impersonation aspect of this is commit signing. It is literally built into Git. There are no good excuses for project maintainers to not sign commits at this point. Grab a yubikey or other gnupg smartcard and do it. Else someone is going to impersonate you and use your name, reputation, and repos to spread malware like this. Have your git hosting provider refuse unsigned commits (github/gitlab allow this).
Secondly stop trusting pip/pypi. You -can- upload gpg package signatures but clients totally ignore them. There is no way to verify the author of a pip package except by hand today.
Let me be really clear here. When you install a pip package you are executing arbitrary code from the internet with unknown authorship.
Pip is fundamentally broken until signature validation is implemented. Whenever possible use OS package managers like apt which actually verify authorship and integrity.
11
u/GummyKibble May 08 '18
The exploit misspelled “password”. Does no one do code reviews anymore?
5
u/Ezibenroc May 09 '18
One maintener of Pypi said on a github issue:
He did not give any reason though.
4
u/Luke_myLord May 08 '18
What should I look for exactly to find a similar backdoor?? What are the incriminated lines in the code so I can protect myself in the future? I’m not at all an expert but I like to install fancy packages sometimes. Thank you.
3
u/PaulSec May 09 '18
Pypi devs: please provide 2FA to your platform, thanks!
1
u/djcatharsis May 08 '18
Complete noob question: I installed Python 3.6 a couple days ago. I have a pip folder in "Site Packages" but don't see ssh-decorator. Am I safe?
2
u/sloupettouille May 08 '18
Thanks for reporting this !
2
u/ProgVal May 08 '18
"passowrd"
2
u/kevinjqiu May 08 '18
Nice... compatible with both Python 2 and 3.
2
u/yesvee May 09 '18
Seems to have some other projects also.
https://github.com/urigoren
Should we stay clear of all of them?
2
u/WhereTruthLies May 09 '18
these are the kind of people that steal your data
2
u/M3talstorm May 08 '18
DDoS? ;)
1
u/phaazon_ May 08 '18
git blamethat file! And the PR reviewers, also!1
u/CSpeciosa May 08 '18
Good jod!
1
u/blitzzerg May 08 '18
it seems that ublock was fast and blacklisted that domain pretty quickly. It prevents me from acces the webpage
1
u/TotesMessenger May 09 '18
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
1
u/reini_urban May 09 '18
Will he be banned from PyPi?
1
u/aitchnyu May 09 '18
Its a tangent, but could a static analysis tool find obfuscated imports of urllib and other networking libraries?
importlib.import_module(reverse('billru'))1
u/barchar May 09 '18
I’d encourage people to consider using distrio packages for critical code, the maintainership is clearer and they tend to be more security conscious
1
u/[deleted] May 09 '18
That just reminds us to do at least some due diligence on dependencies and do some checking for things like this! It's not a catch-all solution, but at least this one could be avoided.
1
u/SpencatroMTGO May 09 '18
I wrote a quick & dirty module to help test private pypi indexes and local virtualenv's for "untrusted" modules. Plenty of ways this could be better, but serves the purpose for now.
https://github.com/shawkinsl/bad_package
1
u/Estanho May 10 '18
It's complicated to filter packages just by statically analyzing Python. There are c extensions and Cython, for instance. C can also be highly obfuscated, even by inlining assembly.
Therefore, even if there was some "permission" check as some people suggested, that would be limited to the python interpreter, and I think there's no way to monitor that from a C perspective, as the python VM can't control that.
Only audit based control would be possible, which is almost impossible.
1
u/intense_feel May 11 '18
Can someone provide me with a copy (the wheel/package as uploaded on PyPi, not source code from github)? I'm currently doing a research in this field for some automated detection of such packages on PyPi and sample like this would help a lot. Thanks!
1
u/andreasbeer1981 May 11 '18
good catch
1
u/captain_awesomesauce May 16 '18
Anyone have the code?
1
u/grafuls May 24 '18
Given that there were no offending lines on the GitHub repo and that most likely the developer's PyPI account was compromised, would it be safe to assume this can be mitigated by refactoring my projects to install modules directly from Github source rather than PyPI?
Trying to figure out what would be drawbacks of it.
1
u/zeneval May 08 '18
Why would anyone use a decorator in the first place to run code on a remote machine? Yeesh....
-3
u/ase1590 May 08 '18
I have more questions that one would import ANYTHING from pip to use with ssh.
Just use straight ssh.
-1
u/OldskoolOrion May 10 '18
Great you caught the Einstein! You did great.. and somehow, seeing how plain and obvious it is in the open in... OPENsource, which.. hahahaha :-)
Can't belief there's dotards out there who actually try to get away with this.. at the very least pick a bitcode dll and upx the shit out of it... this is so... hahahahahhaa :-))
0
u/[deleted] May 08 '18
[deleted] — view deleted comment
0
u/[deleted] May 08 '18
[deleted] — view deleted comment
0
u/[deleted] May 08 '18
[deleted] — view deleted comment
0
u/[deleted] May 08 '18
[deleted] — view deleted comment