Cryptocurrency-Stealing Code Distributed via Popular Library
The popular EventStream Node.js library was recently modified to fetch malicious code designed to steal crypto-currencies.
The code library was designed by a Dominic Tarr, who says he hasn’t been using it for years. However, he apparently agreed to transfer the module to another user in September 2018, who modified the library’s dependencies, which eventually resulted in malicious code being delivered to users.
On September 9, the repository’s new maintainer, right9ctrl, added the flatmap-stream library as a dependency of event-stream, but then removed it on September 16, when they also pushed a new version of event-stream, Chris Northwood explains on Medium.
On October 5, NPM user hugeglass pushed flatmap-stream 0.1.1, which had an obfuscated snippet of nefarious code appended to it. The encrypted payload is decrypted if a specific value of description in package.json is present, and was found last week to target a crypto-currency wallet to steal keys.
Specifically, the malicious code in flatmap-stream 0.1.1 was designed to steal coins from Dash Copay Bitcoin, an open-source, multiplatform, multi-signature, secure Bitcoin wallet. The malicious code would only become active when the wallet app is used.
“Currently we have only confirmed that the malicious code was deployed on versions 5.0.2 through 5.1.0 of our Copay and BitPay apps. However, the BitPay app was not vulnerable to the malicious code. We are still investigating whether this code vulnerability was ever exploited against Copay users,” the BitPay Team says in a blog post.
The root cause of the issue is that the original maintainer of event-stream handed over the repository/package to another individual, likely without performing rigorous checks, which eventually resulted in malicious code being added to the library.
“The main takeaway with this attack is that in the world of modern software, it’s turtles all the way down… Just because the code you write is secure, doesn’t mean that the code other developers write for you is. The only way to get ahead of this is to practice deep and continuous abuse-case (i.e., security) testing,” Casey Ellis, CTO at Bugcrowd, told SecurityWeek.
This is not the first time popular repositories, especially those that are no longer maintained, end up being abused for malicious purposes. Such was the case with ESLint earlier this year, as well as with numerous WordPress plugins last year.