Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

被污染的 npm 包:event-stream #4851

Merged
merged 6 commits into from
Dec 20, 2018
Merged

被污染的 npm 包:event-stream #4851

merged 6 commits into from
Dec 20, 2018

Conversation

CoderMing
Copy link
Contributor

译文翻译完成,resolve #4798

@CoderMing
Copy link
Contributor Author

注:原markdown文件的换行存在一定格式问题,我翻译的时候已经改过来了。这看起来会让删除的行比新增的行多。

@CoderMing CoderMing changed the title translate compromised-npm-package-event-stream.md 被污染的 npm 包:event-stream Dec 14, 2018
@KarthusLorin
Copy link
Contributor

@leviding 校对认领

@fanyijihua
Copy link
Collaborator

@KarthusLorin 好的呢 🍺

@caoyi0905
Copy link
Contributor

校对认领

@fanyijihua
Copy link
Collaborator

@caoyi0905 妥妥哒 🍻

Copy link
Contributor

@caoyi0905 caoyi0905 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

校对完成

> * 校对者:
# 被污染的 npm 包:event-stream
![](https://cdn-images-1.medium.com/max/800/1*OB_BwZtUSGuM15X6xFsrWw.png)
一个著名的 npm 包 [`event-stream`](https://github.com/dominictarr/event-stream) 的作者,将其转让给了一个恶意用户 [right9ctrl](https://github.com/right9ctrl)。这个包每个月有超过 [150万](https://www.npmjs.com/package/event-stream) 次下载,同时其被 1,600 个其它的 npm 包依赖。恶意用户通过持续地向这个包贡献代码来收获了其原作者的信任。这个 npm 包由恶意用户发布的第一个版本时间是 2018 年 9 月 4 日。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

收获了其原作者的信任 => 获得了其原作者的信任

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 npm 包由恶意用户发布的第一个版本是 2018 年 9 月 4 日。 => 恶意用户在 2018 年 9 月 4 日 发布了这个 npm 包的第一个版本。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 npm 包很早以前就存在了哈~是在 2018 年 9 月 4 日由恶意用户发布了经过修改的带恶意代码的第一个版本~

# 被污染的 npm 包:event-stream
![](https://cdn-images-1.medium.com/max/800/1*OB_BwZtUSGuM15X6xFsrWw.png)
一个著名的 npm 包 [`event-stream`](https://github.com/dominictarr/event-stream) 的作者,将其转让给了一个恶意用户 [right9ctrl](https://github.com/right9ctrl)。这个包每个月有超过 [150万](https://www.npmjs.com/package/event-stream) 次下载,同时其被 1,600 个其它的 npm 包依赖。恶意用户通过持续地向这个包贡献代码来收获了其原作者的信任。这个 npm 包由恶意用户发布的第一个版本时间是 2018 年 9 月 4 日。
恶意用户修改了 `event-stream` 让其依赖了一个恶意 npm 包 [`flatmap-stream`](https://github.com/hugeglass/flatmap-stream)。这个 npm 包是专门针对这次攻击所制作的。它包括了一个相当简单的 `index.js` 文件,同时也有一个压缩版的 `index.min.js` 文件。在 GitHub 上,这两个文件看起来完全没问题。然而,在 npm 上发行的代码并没有被要求与 git 仓库中所存储的代码相同。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“让其依赖了一个恶意 npm 包” 前可以加一个逗号


# Compromised npm Package: event-stream
### 恶意 npm 包做了什么?
恶意 npm 为目标高度精确的攻击。它最终会对一个开源 APP [bitpay/copay](https://github.com/bitpay/copay) 发起攻击。该 APP 的 README 中讲到:_Copay 是一个支持桌面端和移动端的安全的比特币钱包平台_。我们知道恶意 npm 包只针对这个应用是因为其会读取项目 `package.json` 文件中的 `description` 字段,并用其去解码一个 **AES256** 加密的代码段。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APP => App


![](https://cdn-images-1.medium.com/max/800/1*OB_BwZtUSGuM15X6xFsrWw.png)
对于其他项目, `description` 字段不能够用于给加密代码段解密,之后 hack 操作将会悄悄终止。 而 [bitpay/copay的 description 字段](https://github.com/bitpay/copay/blob/90336ef9fb4cc3a90a026827be27a32348d3615c/package.json#L3),也就是 `A Secure Bitcoin Wallet`,是解密这些数据(加密代码段)的key。
`flatmap-stream` 这个包巧妙地将数据隐藏在了 `test` 文件夹中。这个文件夹在 GitHub 不可见但却出现在了实际的 [`flatmap-stream-0.1.1.tgz`](https://registry.npmjs.org/flatmap-stream/-/flatmap-stream-0.1.1.tgz) 包中。这些加密的数据以一个数组的形式存储,数据的每一部分都被压缩及混淆过,同时也以不同的参数进行了加密。一部分加密的数据包括了一些会被静态数据统计工具警告为恶意行为的方法名,例如 `_compile` 这个在 `require` 中意味着创建一个新 Module 的字符串。在下面两段示例代码中,我尽我所能去清理了这些文件让其阅读更加友好。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

让其阅读更加友好 => 让代码更易读

Copy link
Contributor

@KarthusLorin KarthusLorin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

校对完成,请多多指教~

![](https://cdn-images-1.medium.com/max/800/1*OB_BwZtUSGuM15X6xFsrWw.png)
一个著名的 npm 包 [`event-stream`](https://github.com/dominictarr/event-stream) 的作者,将其转让给了一个恶意用户 [right9ctrl](https://github.com/right9ctrl)。这个包每个月有超过 [150万](https://www.npmjs.com/package/event-stream) 次下载,同时其被 1,600 个其它的 npm 包依赖。恶意用户通过持续地向这个包贡献代码来收获了其原作者的信任。这个 npm 包由恶意用户发布的第一个版本时间是 2018 年 9 月 4 日。
恶意用户修改了 `event-stream` 让其依赖了一个恶意 npm 包 [`flatmap-stream`](https://github.com/hugeglass/flatmap-stream)。这个 npm 包是专门针对这次攻击所制作的。它包括了一个相当简单的 `index.js` 文件,同时也有一个压缩版的 `index.min.js` 文件。在 GitHub 上,这两个文件看起来完全没问题。然而,在 npm 上发行的代码并没有被要求与 git 仓库中所存储的代码相同。
这个被插入到 `event-stream` 中的恶意 npm 包在 10 月 20 日被其他用户发现并在 [dominictarr/event-stream#116](https://github.com/dominictarr/event-stream/issues/116#issuecomment-441759047) 中曝光。这个 issue 在恶意 npm 包发布两个月后才被创建。开源软件的一大好处是能够集众多开发者之力。但这并不是毫无坏处的。例如 OpenSSL,这个开源项目有着几乎最严格的代码审查,但是其仍然有许多不足之处,例如 Heartbleed 漏洞(译者注:可参考 http://heartbleed.com/)。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

开源软件的一大好处是能够集众多开发者之力。但这并不是毫无坏处的 => 建议把句号改为逗号


# Compromised npm Package: event-stream
### 恶意 npm 包做了什么?
恶意 npm 为目标高度精确的攻击。它最终会对一个开源 APP [bitpay/copay](https://github.com/bitpay/copay) 发起攻击。该 APP 的 README 中讲到:_Copay 是一个支持桌面端和移动端的安全的比特币钱包平台_。我们知道恶意 npm 包只针对这个应用是因为其会读取项目 `package.json` 文件中的 `description` 字段,并用其去解码一个 **AES256** 加密的代码段。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

恶意 npm 为目标高度精确的攻击 => 该恶意 npm 包是一种针对性很强的攻击


# Compromised npm Package: event-stream
### 恶意 npm 包做了什么?
恶意 npm 为目标高度精确的攻击。它最终会对一个开源 APP [bitpay/copay](https://github.com/bitpay/copay) 发起攻击。该 APP 的 README 中讲到:_Copay 是一个支持桌面端和移动端的安全的比特币钱包平台_。我们知道恶意 npm 包只针对这个应用是因为其会读取项目 `package.json` 文件中的 `description` 字段,并用其去解码一个 **AES256** 加密的代码段。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

讲到 => 提到


# Compromised npm Package: event-stream
### 恶意 npm 包做了什么?
恶意 npm 为目标高度精确的攻击。它最终会对一个开源 APP [bitpay/copay](https://github.com/bitpay/copay) 发起攻击。该 APP 的 README 中讲到:_Copay 是一个支持桌面端和移动端的安全的比特币钱包平台_。我们知道恶意 npm 包只针对这个应用是因为其会读取项目 `package.json` 文件中的 `description` 字段,并用其去解码一个 **AES256** 加密的代码段。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copay 是一个支持桌面端和移动端的安全的比特币钱包平台 => Copay 是一个支持桌面端和移动端的安全比特币钱包平台

### 如何防御这次攻击?
通过使用静态分析工具来扫描 npm 包可能是个很棒的想法。但此次攻击对恶意的源代码进行了加密以避免被检测到。为了防止这种攻击,我们必须采取其他的的方法...
这次特定攻击看起来可以同时在传统 web 页面和通过 Cordova(一个将 web APP 打包成移动端 APP 的工具)构建的 APP 中运行。我们已经发现了这次攻击可以通过使用 [CSP (Content Security Policy)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) 来阻止。这是用来指定页面可以与哪些 url 通信并将这些设定通过 web 服务器响应头来指定的标准。Cordova 甚至有其自身的方法 [mechanism](https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/index.html#navigation-whitelist) 来指定哪些第三方服务可以使用。然而,[Copay APP 似乎禁用了这个特性](https://github.com/bitpay/copay/blob/72a9e176c12c77b5dfc4590c88de73f28fa301b7/app-template/config-template.xml#L121)。
CSP 可以有效地保证前端页面的安全。然而,这个特性没有被内置在 Node.js 中。[Intrinsic](https://intrinsic.com/) 这个 Node.js 包提供了让你可以设定你 APP 通信 URL 白名单的功能——这很像 CSP——而且其可以干更多事情。Intrinsic 可以被用来设置文件系统白名单、子进程白名单、`process` 的细分节点、TCP 和 UDP 连接甚至是细粒度的数据库访问。这些白名单是建立在每条请求路由的,这使得其比防火墙更加强大。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSP—— => CSP ——

@KarthusLorin
Copy link
Contributor

@leviding @CoderMing 校对完成

@leviding
Copy link
Member

@CoderMing 可以修改啦

@leviding leviding added the enhancement 等待译者修改 label Dec 16, 2018
@CoderMing
Copy link
Contributor Author

@leviding 校对完成

@leviding leviding added 标注 待管理员 Review and removed enhancement 等待译者修改 labels Dec 16, 2018
@leviding
Copy link
Member

@CoderMing 本文为什么这么乱,是不是哪里出错了

@leviding leviding added the WIP label Dec 18, 2018
@leviding
Copy link
Member

@CoderMing 记得修改一下

@CoderMing
Copy link
Contributor Author

@leviding 刚看了下原因,vscode 代码自动 lint 了。。内容没缺的,就是空格和换行符有出入,抱歉。格式我尽量做了修改。

@leviding leviding added WIP and removed WIP labels Dec 19, 2018
@leviding leviding removed the WIP label Dec 20, 2018
Copy link
Member

@leviding leviding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!

@leviding leviding merged commit 208ab11 into xitu:master Dec 20, 2018
@leviding
Copy link
Member

@CoderMing 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。

掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件
专栏地址:https://zhuanlan.zhihu.com/juejinfanyi

@leviding leviding added 翻译完成 and removed 标注 待管理员 Review 正在校对 labels Dec 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

被污染的 npm 包:event-stream
5 participants