Skip to content
Misconfiguration Write-up Intermediate

Atom.io Misconfiguration Allowed Code Execution on Untrusted Networks

The atom.io download service redirected requests for node-gyp headers and checksums to an S3 bucket over plain HTTP, so an attacker on the same network could intercept and replace those files. By tampering with the tarball and checksum file, an attacker could execute arbitrary commands during a native module build.

Adam Baldwin Follow

Published on evilpacket.net

Developers have increasingly become a more valuable target to compromise in recent years. The DevOps movement means they have more access to production, not to mention the plethora of source code and keys that you are likely to find.

Adam Baldwin (@adam_baldwin), on evilpacket.net

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

Atom is a text editor, and its package manager, apm, uses npm to resolve dependencies. When a package contains native modules, those modules have to be compiled, and that compilation is done with node-gyp.

As part of the compilation step for native modules, node-gyp downloads a tarball of headers from a configured dist-url, together with a list of SHASUMS used for integrity verification. The URLs are configured with a flag, something like this:

Text
node-gyp rebuild --dist-url=https://atom.io/download/atom-shell

The target here is the atom.io domain, which serves those downloads. The researcher's point is that developers are a valuable target: the DevOps movement gives them more access to production, and their machines hold source code and keys.

Setup

The work required a position between a developer and atom.io, so the researcher performed a machine-in-the-middle attack. For that task he used Bettercap, described in the post as an extensible MITM framework with many already built plugins. Because the job was a bit custom, he wrote a custom plugin to replace more than one file on the fly. The post links to the custom plugin on GitHub.

No account, role or specific version of Atom, apm or node-gyp is given in the report.

Finding it

The subtle bug is easy to miss during an audit. Someone looking at the --dist-url flag sees HTTPS, confirms it, and moves on. They might go a step further and curl the URL to verify that it really uses HTTPS, and they would be correct that it does.

However, the dist-url and SHASUM URLs that are derived by node-gyp are forwarded to an S3 bucket over HTTP by the atom.io web service. For example, when this URL is requested:

Text
hxxps://atom.io/download/atom-shell/v0.30.6/node-v0.30.6.tar.gz

a 302 is returned with a redirect location of:

Text
hxxp://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist/v0.30.6/node-v0.30.6.tar.gz

The same goes for the SHASUM URL. A request to:

Text
hxxps://atom.io/download/atom-shell/v0.30.6/SHASUMS256.txt

redirects to:

Text
hxxp://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist/v0.30.6/SHASUMS256.txt

The consequence is that anyone who can get between the developer and atom.io can control the content returned for the dist tarball and for the SHASUM file. Because the attacker can control the content returned for both the tarball and the SHASUM file, the integrity check can be bypassed.

Exploitation

Step 1: find a way to execute code during installation

Before going after the network, the researcher had to work out how to backdoor the dist tarball so that it would produce code execution. He notes that he knew nothing about how node-gyp works and found it to be a rats nest of gibberish, so this took a while. He also notes that there are likely other ways, such as causing a backdoor to be compiled into the final library, but he went with what he felt was the simpler route, as attackers tend to do.

What he found is that node-gyp loads a file named common.gypi. That file provides ways to specify defaults and configuration for gyp. The proof of concept includes a default target with an action that executes the say command, though it could be any command the attacker wants to run:

JavaScript
'target_name': 'sdf',
'sources': ['src/asdf.h'],
'actions': [{
  'action_name': 'hax',
  'inputs': ['src/asdf.h'],
  'outputs': ['<(PRODUCT_DIR)/asdf.out'],
  'action': ['/usr/bin/say', 'ha ha ha ha ha ha powned'],
}],

Step 2: intercept the download and swap the files

With reliable code execution during a node-gyp installation in hand, the next step was the MITM attack to swap out the tarball and the SHASUMS file. Bettercap handled the interception, and the custom plugin replaced more than one file on the fly.

Or watch on YouTube
YouTube Video From the original on evilpacket.net

Root cause

The mistake is in the atom.io web service: it accepts HTTPS requests and then redirects the client to an S3 bucket over plain HTTP. The redirect target is derived from the dist-url and SHASUM URLs that node-gyp builds, so the downgrade applies to both the tarball and the integrity file.

Because the SHASUMS file is fetched over the same plaintext channel as the tarball, an attacker in the middle can replace both files.

Impact

An attacker positioned between a developer and atom.io can control the content returned for the dist tarball and the SHASUM file, and through the common.gypi action obtain code execution on the developer's machine during a node-gyp installation. The command run is whatever the attacker chooses; the proof of concept uses /usr/bin/say.

Two mitigating factors limit the exposure. Not all modules trigger the condition, because plenty of modules are not native modules. And node-gyp caches the dist content, so if it is already on disk it will not be downloaded again.

Fix

The issue is now fixed, and the report thanks the GitHub Security team. The report does not describe the change that was made. The timeline records that the fix was verified in place on 11.05.2016 and that GitHub Security resolved the issue and issued a bounty on 11.07.2016.

Timeline as given:

Date Event
10.28.2016 Vulnerability found
10.29.2016 Confirmed exploitability
10.30.2016 Notified atom.io via email
10.31.2016 Notified AtomEditor via twitter
11.03.2016 Submitted to GitHub bounty via hackerone.com
11.03.2016 Received bug confirmation
11.05.2016 Verified fix was in place
11.07.2016 GitHub Security resolved the issue and issued a bounty

Variants to test

  • Follow download endpoints that return a 302 and check the scheme of the Location header. A positive result is an HTTPS request answered with a redirect to an http:// URL, especially when the redirect target is a storage bucket.
  • Check whether an integrity file (SHASUMS or similar) is fetched over the same channel as the artefact it verifies. A positive result is both files arriving over plaintext HTTP, so that replacing one allows replacing the other.
  • Look at build tooling that loads configuration files from a downloaded distribution, such as common.gypi for gyp. A positive result is a configuration file inside the tarball that can define actions or commands executed during installation.
  • Test whether the tool caches downloaded distribution content. A positive result is that a second install does not fetch the files again, which narrows the window in which an interception works.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

Atom is a text editor for programmers. Like many modern tools, it can be extended with add-ons called packages. A package manager called apm fetches and installs those packages for you, and underneath it uses another tool called npm to work out what a package needs in order to run.

Some packages contain pieces written in a lower-level language (often C or C++) rather than in JavaScript. Those pieces are called native modules, and before they can be used they have to be turned into a form the computer can run. That translation step is called compiling, and Atom's toolchain does it with a helper program called node-gyp.

To compile a native module, node-gyp needs a set of ready-made files called headers. It downloads them as a single compressed archive, a tarball, from a web address you configure. Alongside the tarball it downloads a small text file listing checksums (SHASUMS), which are short fingerprints of the files. The idea is simple: after downloading, the tool computes the fingerprint of what it received and compares it with the list. If they match, the files are the ones the project published; if not, something is wrong.

A useful everyday comparison: a checksum is like the tamper-evident seal on a medicine bottle. If the seal is intact, you trust the contents. But if the person who hands you the bottle also prints the seal, the seal proves nothing.

That is roughly what went wrong here. The researcher found that the atom.io website, which serves these downloads, accepted a secure HTTPS request and then quietly redirected the client to a storage service (an S3 bucket) over plain HTTP. The tarball and the checksum file both travelled over that plain channel. Anyone sitting on the network between the developer and atom.io could therefore replace both files, and the checksum check would happily approve the swapped-in content.

The researcher then showed that a swapped tarball can carry a configuration file that makes the build run a command. In other words, a developer installing a package while an attacker is positioned between them and atom.io could end up running an attacker's command on their own machine. The issue was reported to GitHub, fixed, and a bounty was issued.

Why care about developers at all? Because developers are valuable targets. The DevOps movement means they often have direct access to production systems, and their laptops hold source code and keys. A single command run on a developer's machine can be worth far more than one run on an ordinary user's.

Background: what the pieces are

Before the details, a few terms from the report, explained from zero.

  • HTTPS and HTTP. HTTP is the language browsers and servers use to exchange pages and files. HTTPS is the same language wrapped in encryption, so nobody between you and the server can read or change the traffic. The padlock in your browser's address bar means HTTPS. HTTP, without the S, is plain: anyone on the same network can look at it and alter it.
  • A redirect (302). When you ask a web server for something, it can answer "not here, go to this other address instead". That answer has a status code, and 302 is the common one for a temporary redirect. Your browser then automatically requests the new address. This is normal and useful, but it means the security of the final address matters as much as the first one.
  • A tarball. A single file that bundles many files together, like a zip archive. Here it contains the headers node-gyp needs.
  • A checksum (hash). A short string computed from a file's contents. Change one byte of the file and the checksum changes completely. Comparing checksums is how software checks that a download arrived intact and unmodified.
  • A flag. An option you add to a command to change its behaviour, usually starting with two dashes.
  • A machine-in-the-middle (MITM) attack. The attacker places themselves on the network path between two parties, so traffic passes through them. On an open Wi-Fi network this can be done by impersonating the access point. The attacker can then read, and in the plain HTTP case modify, what passes through.
  • S3 bucket. Amazon's cloud storage service. Files stored there have web addresses, and those addresses can be HTTP or HTTPS.

Now the setup. The URLs node-gyp uses are configured with a flag, something like this:

Text
node-gyp rebuild --dist-url=https://atom.io/download/atom-shell

Line by line: node-gyp is the program being run. rebuild tells it to compile the native module from scratch. --dist-url= is the flag that sets where the headers come from, and the value after the equals sign is the address: https://atom.io/download/atom-shell. Notice the https, which looks reassuring.

This is exactly why the bug is easy to miss. A reviewer auditing the source sees the flag, sees HTTPS, confirms it, and moves on. They might go a step further and fetch the URL themselves with a command-line tool called curl to check that it really is HTTPS, and they would be right: it is. The problem is not the first address. It is where that address sends you next.

Finding it

The atom.io web service takes the download request and forwards it to an S3 bucket, but over HTTP rather than HTTPS. For example, when this address is requested:

Text
hxxps://atom.io/download/atom-shell/v0.30.6/node-v0.30.6.tar.gz

a 302 is returned, pointing at this address:

Text
hxxp://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist/v0.30.6/node-v0.30.6.tar.gz

Line by line: the first line is the address the developer's tool asks for. The hxxps spelling is a convention in security writing: the address is written with xx instead of tt so that it is not a clickable live link, but it means the same as https. The path /download/atom-shell/v0.30.6/node-v0.30.6.tar.gz names the project, a version, and the tarball file.

The second line is where the server tells the client to go instead. Here the scheme is hxxp, meaning plain HTTP, and the host is an Amazon S3 bucket. So the secure first hop ends in a plain second hop.

The same happens for the checksum file. A request to:

Text
hxxps://atom.io/download/atom-shell/v0.30.6/SHASUMS256.txt

redirects to:

Text
hxxp://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist/v0.30.6/SHASUMS256.txt

Line by line: this is the same pattern with a different file name. SHASUMS256.txt is the text file holding the checksums, and it too is fetched over plain HTTP.

So what? The consequence is that anyone who can get between the developer and atom.io can control the content returned for the tarball and for the checksum file. And because the checksum file travels over the same unprotected channel as the tarball, the integrity check gives no protection at all: the attacker replaces the tarball and replaces the list of fingerprints to match. The seal and the bottle both come from the attacker.

The exploit

Step 1: make the downloaded content run a command

Before touching the network, the researcher had to work out how to modify the tarball so that installing it would run code. He says he knew nothing about how node-gyp works and found it to be a rats nest of gibberish, so this took a while. He also notes there are probably other routes, such as getting a backdoor compiled into the final library, but he chose what felt like the simpler one, as attackers tend to do.

What he found is that node-gyp loads a file named common.gypi. This file is a configuration file: it lets the build system set defaults and describe what should happen during a build. The proof of concept below defines a default target with an action that runs the say command, though it could be any command the attacker wants:

JavaScript
'target_name': 'sdf',
'sources': ['src/asdf.h'],
'actions': [{
  'action_name': 'hax',
  'inputs': ['src/asdf.h'],
  'outputs': ['<(PRODUCT_DIR)/asdf.out'],
  'action': ['/usr/bin/say', 'ha ha ha ha ha ha powned'],
}],

Line by line, in plain words:

  • 'target_name': 'sdf', gives this build target a name. A target is just a labelled unit of work in the build.
  • 'sources': ['src/asdf.h'], lists the source files the target is built from. Here it is a single header file.
  • 'actions': [{ opens a list of extra actions to perform during the build. An action is a command the build system will run.
  • 'action_name': 'hax', names the action.
  • 'inputs': ['src/asdf.h'], says which files the action depends on.
  • 'outputs': ['<(PRODUCT_DIR)/asdf.out'], says which file the action produces. <(PRODUCT_DIR) is a placeholder that the build system replaces with the directory where build output goes.
  • 'action': ['/usr/bin/say', 'ha ha ha ha ha ha powned'], is the actual command: run the program at /usr/bin/say (a macOS utility that speaks text out loud) with the words that follow as its argument. On a real attack this could be any command the attacker wants.
  • The closing }], ends the action and the list.

Why this matters: the build system treats this file as instructions, and instructions include commands to run. Put the file inside the tarball, and the build runs your command.

Step 2: intercept the download and swap the files

With reliable code execution during a node-gyp installation in hand, the next step was the network attack: get between the developer and the download, and swap out the tarball and the checksum file.

For this task the researcher used Bettercap, which the post describes as an extensible MITM framework with many already built plugins. "Extensible" means you can add your own modules to it. Because the job was a bit custom, he wrote a custom plugin to replace more than one file on the fly. The post links to the custom plugin on GitHub.

Or watch on YouTube
YouTube Video From the original on evilpacket.net

Mitigating factors

Two things limit how often this works in practice.

  1. Not all modules trigger the condition, because plenty of modules are not native modules. If a package is pure JavaScript, there is no compilation step and no header download to intercept.
  2. node-gyp caches the downloaded content. If the files are already on disk from an earlier install, they are not downloaded again, so there is nothing to intercept.

Timeline

The dates are given in the report as follows.

Date Event
10.28.2016 Vulnerability found
10.29.2016 Confirmed exploitability
10.30.2016 Notified atom.io via email
10.31.2016 Notified AtomEditor via twitter
11.03.2016 Submitted to GitHub bounty via hackerone.com
11.03.2016 Received bug confirmation
11.05.2016 Verified fix was in place
11.07.2016 GitHub Security resolved the issue and issued a bounty

A bounty, in this context, is a reward a company pays someone who reports a security problem responsibly. The report thanks the GitHub Security team for their quick response and good communication.

Glossary

  • 302: an HTTP status code meaning "the thing you asked for is at another address, go there instead".
  • apm: Atom's package manager, the tool that installs add-ons for the Atom editor.
  • Bettercap: a tool for intercepting and manipulating network traffic, described in the report as an extensible MITM framework.
  • Bounty: a reward paid by a company for a responsibly reported security bug.
  • Checksum (hash): a short fingerprint computed from a file's contents, used to detect changes.
  • Compiling: turning human-written source code into a form the computer can run.
  • Configuration file: a file that tells a program how to behave, including, in this case, which commands to run during a build.
  • curl: a command-line tool for fetching web addresses.
  • DevOps: a way of working where developers are closely involved in running and deploying production systems, giving them more access.
  • dist-url: the flag that sets where node-gyp downloads its headers from.
  • Flag: an option added to a command to change its behaviour, usually starting with two dashes.
  • gyp: the build configuration system that node-gyp uses, which reads files such as common.gypi.
  • Headers: ready-made files a compiler needs in order to build a native module.
  • HTTP: the plain, unencrypted language of the web.
  • HTTPS: HTTP wrapped in encryption, so traffic cannot be read or changed in transit.
  • Machine-in-the-middle (MITM): an attack where someone places themselves on the network path between two parties to read or alter traffic.
  • Native module: a piece of a package written in a lower-level language that must be compiled before use.
  • node-gyp: the tool that compiles native modules for Node.js and Atom packages.
  • npm: the package manager that apm uses underneath to resolve dependencies.
  • Package: an add-on that extends the Atom editor.
  • Redirect: a server response that sends the client to a different address.
  • S3 bucket: storage space on Amazon's cloud service, reachable by web address.
  • SHASUMS: a text file listing checksums used to verify downloaded files.
  • Tarball: a single archive file bundling many files together.
  • Target: a labelled unit of work in a build configuration.

More from GitHub

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.