r/programming • • Nov 27 '18

event-stream vulnerability explained

https://schneid.io/blog/event-stream-vulnerability-explained/
147 Upvotes

21 comments sorted by

28

u/aal0 Nov 28 '18 edited Nov 28 '18

They were only caught because they used one deprecated method (`createDecipher` instead of `createDecipheriv`), which raised concerns on other projects first. The rest was all covered up so well, minimising output, cpu cycles and network activity. This would have continued for months(/years?) before anyone would have noticed anything.

They also only stole wallets which contained more than 100 bitcoins. This was a very specific attack to a very small number of people, just to reduce any awareness, but still raking in those bitcoins.....

A deprecation warning prevented this.

11

u/smmalis37 Nov 28 '18

Really makes you wonder how many other attacks just like this one are ongoing at this very moment, and just haven't been noticed yet.

9

u/aal0 Nov 28 '18

Seeing how sophisticated this attack was, I think there are quite a few already.

I mean the cutoff was so immensely high (100btc ~400k$), this would have made it super future proof. This code was intended to run for years. Only affecting a few users, Coday would have had a lot of trouble correlating the data and probably for these few affected users shrugged it off as too local/incidental*. They would never have reviewed their code for these few cases.

*Note: the amount won't matter, quantity will. If all users were affected they had no other choice than to do an investigation.

15

u/Vakz Nov 28 '18

Really is a very creative attack. Still, my understanding is that at the very core, it's still a case of social engineering. The attacker couldn't have done this if he hadn't been given full access to the git repo. I've seen a lot of people blaming NPM for this, but surely this attack would've been possible in any environment which uses package management, be it NPM, Nuget, Maven, pip or any other. The only exception I can see here is that it's harder to detect here, due to the custom of minifying, as my understanding from this summary is that the malicious code was only present in the minified version.

27

u/michalg82 Nov 28 '18 edited Nov 28 '18

Also, it's easier in JS community, because of this fragmentation of nano packages. For example you can trust Facebook and use React package. But React uses probably dozen of other packages. Every this package uses dozen of another. Ultimately you are now using 200 packages from over 100 developers. Many of those packages are not maintained anymore. Many of those packages are vulnerable to hacking. Hacker only have to hack one small forgotten package on bottom of this dependency chain.

JS community should stop with this nano packages obsession. Every package developer / maintainer should aim for as low dependencies as possible. Currently it works in the opposite direction - many prefers to add new dependency instead of writing 10 lines of code.

NPM website says "What can you make with 700,000 building blocks? The npm registry hosts the world’s largest collection of free, reusable code.". In my opinion it's nothing to be proud of. It only shows that developers prefer to create new packages instead of working together. I don't need 20 packages for reversing string. I only need one good package containing string functions (among many other functions). Such, which is developed and maintained by more than single developer.

Some time ago i compared how many packages were installed by installing one popular dev tool package. Here are results (probably now will be different):

  • webpack - 244

  • gulp - 197

  • babel - 164

  • typescript - 0

3

u/Vakz Nov 28 '18

Yes, and I definitely agree that overuse of dependencies is a major factor in this, but I still don't see how that's an issue with NPM itself. The userbase is doing unsafe things, but it's not an inherent issue with NPM. There's nothing actually stopping people from creating packages for Nuget or Maven which has 200 dependencies, it's just not how things are generally done there. The issue is still with the users of NPM blindly using dependencies for every little thing, to the point that nobody can keep track of them. I fail to see how a package manager could possibly solve that.

13

u/blackn1ght Nov 28 '18

The language itself is a major part of the problem. .NET/Nuget doesn't have the same issue because .NET contains an extensive set of APIs, and so you don't need to install a package to do basic things. Instead, you're more likely to install libraries like AutoMapper. But with JS, there's no decent standard lib, so developers fill the gaps when they need with small packages that fill that need.

I do think the more popular packages like webpack, Angular, React etc should look to using far less dependencies and write their own implementations.

6

u/[deleted] Nov 28 '18

The language itself is a major part of the problem.

And even a bigger part than people might think.

It's a very clear example of how powerful linguistic relativism is. This reckless sloppy mentality is induced by the language itself. Anyone using JavaScript is unavoidably falling prey to the JavaScript mentality, and the npm shitshow is a direct consequence of this influence of the language semantics on human minds.

Fascinating and scary.

4

u/double-you Nov 28 '18

Yes, the main thing was getting permissions to change an established module. NPM's implementation helped hide it. I don't know how much extra processing power it would need from NPM, but the packages should really be minified from the public source by them and not the maintainer, or separate minification matching checks should be performed.

3

u/blargh10 Nov 28 '18

I was surprised to find they weren't already doing this.

The so called benefit of open-source is that "it's secure" because you have a lot of eyes looking at it is lost entirely.

If you publish a minified version you didn't process from source yourself will increase the risk factor exponentially.

2

u/BurkusCat Nov 30 '18

To me, the social engineering part is a minimal part of the attack. The original owner of the repo could have just performed the same attack if they wanted. How can you trust the original owner of the repo?

0

u/[deleted] Nov 28 '18

[deleted]

1

u/Vakz Nov 28 '18

NPM will automatically update you to the latest compatible version of all of your dependencies every time you build

But it doesn't, though. You can specify the exact version you want to use. NPM does produce lock files.

5

u/joesb Nov 28 '18

Except npm installwill happily install new patch version and silently override your lock file.

Really, look it up.

You have to use npm ci if you want npm to really follow the lock file.

10

u/mrbonner Nov 27 '18

Save me tons of time reading through the GH issue logs. Thanks

9

u/Plastix Nov 27 '18

This is really great! Thanks for taking the time to explain this.

3

u/caspervonb Nov 28 '18 edited Nov 28 '18

It's what I've been yapping on about for years, yet every time it happens everyone brushes it off as a one time thing, until the next one time thing.

4

u/Dgc2002 Nov 28 '18

everyone brushes it off as a one time thing

Do you even read the comment section of articles and posts related to these? Tons of people are very aware of the core issue. Pretty much everything in your blog post has been rehashed in those comment sections since these issues started arising.

1

u/ariasaurus Nov 28 '18

but it keeps happening, so obviously they brushed off as a one time thing, and moved on.

3

u/jonjonbee Nov 28 '18

The people who are aware it's a problem either completely avoid the shitshow that is NPMJS, or very carefully pick and choose and audit the dependencies they require.

The other 99% either don't understand or care or know about it.

1

u/CyberTechnologyInc Nov 28 '18

Very interesting!

Although I think that it would be nice if there was some sort of tool, either embedded into IDEs, and/or in source control UI... Showing warnings when code is clearly obfuscated.

Randomly named methods (search through a dictionary, if words aren't found in there it could possibly be obfuscated).

Same goes for variables.

I've not looked into this at all, but it could help in the very least.

Also just comparing hashes of each file in source control, then matching them up in the IDE to ensure they're the same files.

Maybe an extreme, but it could be quite useful as sly attacks like this happen.

-13

u/ggtsu_00 Nov 28 '18

Stealing bitcoin wallets from JavaScript code monkeys? That's actually quite genius. That's quite a clever spear fishing attack.