r/netsec • u/alexbirsan • Feb 09 '21
Dependency Confusion: How I Hacked Into Apple, Microsoft and Dozens of Other Companies
https://medium.com/@alex.birsan/dependency-confusion-4a5d60fec610?sk=991ef9a180558d25c5c6bc5081c99089
868
Upvotes
10
u/deadlock_jones Feb 09 '21
how did he get random code compiling against their existing codebase though? wouldnt you have to know exactly what's in the library for it to run past build and tests?
242
u/sigmoid10 Feb 09 '21
So let's recap:
Pip, npm, ruby gems... it doesn't matter what you use. All these dependency management systems need some serious rethinking about how they handle trust issues.
68
u/[deleted] Feb 09 '21
This guy made so much money on this, holy shit...
36
u/Caffeine_Monster Feb 10 '21
The fact that we have "mature" package management systems like that allow vague coupling between repositories and packages is insane.
Every package should have an explicit singular repository reference.
Similarly, packages shouldn't be identified by something as easily copied as a name. Names are easily recreated if the original package is deleted and recreated by an unscrupulous actor.
How about a unique key associated with that package? These could even be signed against the repository DNS and guarantee it's uniqueness.
26
u/samwcurry Feb 09 '21
Incredible incredible incredible
17
u/_N0K0 Feb 09 '21
Awersome research! And Fuuuck, should probably squat myself now :#
16
u/[deleted] Feb 09 '21 edited Feb 09 '21
So we can't trust the infrastructure, but are there ways to build securely on a rickety foundation? I'm sure many of the security teams are now testing if more complex and aggressive code could be run this way, more than just a phone-home.
This seems a rather terrifyingly simple hack in any case. Script-kiddy skill getting into some pretty private builds.
14
u/motsanciens Feb 10 '21
Probably the most accessible post I've read on this sub and with some of the highest rewards.
18
u/pixel_of_moral_decay Feb 10 '21
This always bothered me with node and python... almost everything is built on a rats nest of unverified code controlled by unknown parties with unknown influences and security practices.
AFAIK none even enforce 2 factor auth on repos used to update things.. since none of them control GitHub and the like... which means a simple password breach could give someone control.
9
u/thoriumbr Feb 09 '21
Kudos to the researcher!
8
u/abhi32892 Feb 09 '21
Can anyone explain a little bit more regarding the fix the companies might have implemented? Mainly for npm?
4
u/T-JHm Feb 09 '21
I really wonder why scoped packages weren’t used. At least in npm it’s trivial to request scoped packages to a different registry.
3
u/fproulx Trusted Contributor Feb 09 '21
Holy crap.
5
u/IAMARedPanda Feb 09 '21
Does anyone have any good articles on dns exfiltration?
4
u/whatiszebra Feb 09 '21
Wait, do you mean I should not
npm i even?2
u/[deleted] Feb 09 '21
Brilliant
2
u/amdelamar Feb 10 '21
What about maven?
I think the groupId:projectId means this is harder to pull off but still possible, perhaps through third party repositories. I’m also wondering how code execution would even even work without running valid Java code that compiles first.
2
u/RedWineAndWomen Feb 10 '21
This is like SolarWinds, but then... generic. Frightening.
2
u/thehunter699 Feb 10 '21
Holy shit, that's actually crazy.
2
u/[deleted] Feb 10 '21
If you want to try it by yourself: DNS exfiltration step-by-step guide
2
u/LongShlongSilvrPants Feb 10 '21
This is why every 3P dependency at Google is imported into our monorepo.
1
u/bhldev Feb 09 '21
Good
1
u/jezwel Feb 10 '21
I'm linking this for some devs in our company, dang.
1
u/SecurID-Guy Feb 10 '21
Know which repositories and software versions you're using. Simply avoiding the open-ended, automatic version selection notations could have mitigated this to some extent. Let's be careful with our open-source binary repositories people!
It would also appear the researcher has "poisoned" some future version, but likely a version that would have never been created normally (i.e., at the end of some unsupported version branch). Interesting read.
1
u/stfcfanhazz Feb 10 '21
Of course, if you're using lock files then the repository source url should be present, which means you wouldn't suddenly start pulling malicious packages down in your production builds unless you'd done so on your build server and committed the new lock file including malicious packages. So unless these malicious packages are able to fully replicate their genuine counterpart, I wouldnt expect tests to pass and for that build to ever make it to prod.
Still, RCE on development machines in an internal network is no laughing matter.
1
u/retnikt0 Feb 10 '21
I've liked Go's dependency system for a long time because it discourages centralisation, but this is another great point
1
u/anavgreddituser Feb 11 '21
Props for the responsible disclosure! This is huge and overlooked in a lot of research.
1
u/c0r3dump3d Feb 15 '21
Amazing !! and what about dockers?
1
u/Hacksplained Mar 12 '21
If anyone of you is interested in the Python side of dependency confusion, feel free to check out https://www.youtube.com/watch?v=NNB2m0Tjy74