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

[html-pages] Path Traversal in html-pages module allows to read any file from the server with curl

The html-pages module fails to validate directory traversal sequences in requested paths, allowing an attacker to read arbitrary files on the server. Using curl with encoded dot and slash characters, an attacker can bypass the browser's restrictions and access files outside the intended root directory.

bl4de Follow

Originally disclosed on HackerOne

Critical 9.5 View original
  • Triaged in under an hour
  • Fixed in 4 months
  • Disclosed after 4 months

Hi,

This report is about Directory Traversal vulnerability I found in html-pages module.

Module:

html-pages is a module which allows to browse directories and serve static files in the browser. The vulnerability exists in the latest available version (2.0.7)

Link to npm page: https://www.npmjs.com/package/html-pages

Summary:

When html-pages server is run, browser does not allow toread files from arbitrary locations. However, I've noticed that using simple bypasses with %2e (.) or %2f (/) I can easily go up in the directory tree. But it's not possible to open any file in the browser, due to characters used in the path, only directory listing is available:

1.png
1.png From the original on HackerOne

However, with simple curl call we can read any file on the remote server where html-pages runs:

$ curl -v --path-as-is http://localhost:8000/../../../../../Users/bl4de/.vimrc

Here is the part of the code, which read directory content, but does not validate against Directory Traversal in any way, which literally makes root config setting useless:

https://github.com/danielcardoso/html-pages/blob/master/lib/server.js#L122

This vulnerability can be exploited regardless of some html-pages configuration settings, like root. All files on the server can be read by malicious user.

Steps To Reproduce:

  • install html-pages
$ npm install html-pages
  • create simple application which uses html-pages for serving static files from local server:
JavaScript
const pages = require('html-pages')

const pagesServer = pages(__dirname, {
    port: 8000,
    'directory-index': '',
    'root': './',
    'no-clipboard': true,
    ignore: ['.git', 'node_modules']
})
  • run application:
$ node app.js
  • open the browser and go to 127.0.0.1:8000 You should see all directories and files in the directory, where app.js was run. Now, try to modify url into something like 127.0.0.1:8000/.%2e/.%2e/ - now content of directory two levels up in the file tree should be displayed. Try to open any directory or file (if available) by clicking on its name.

You should notice that application actually hangs on.

  • from the terminal, execute following command (please adjust numbers of ../ to your system):
$ curl -v --path-as-is http://127.0.0.1:8000/../../../../../etc/passwd

You should see the content of /etc/passwd file:

3.png
3.png From the original on HackerOne

Supporting Material/References:

Configuration I've used to find this vulnerability:

  • macOS HighSierra 10.13.2
  • node 8.9.3
  • npm 5.5.1
  • curl 7.54.0

Wrap up

I hope this report will help to keep Node ecosystem more safe. If you have any questions about any details of this finding, please let me know in comment.

Thank you

Regards,

Rafal 'bl4de' Janicki

Impact

Impact:

This vulnerability allows malisious user to read content of any file on machine where similar to presented app is running. This might expose vectors to attack system with Remote Code Execution, reveals files with usernames and passwords and many other possibilites.

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 code that reads directory content does not validate against directory traversal sequences, making the 'root' configuration setting ineffective.

Impact

Allows reading any file on the machine, potentially exposing sensitive information and possibly enabling further attacks such as remote code execution.

What the attacker needed

Html-pages module installed and running; network access to the server

How it was found

  1. Install html-pages via npm.
  2. Create a simple application that uses html-pages to serve static files.
  3. Run the application with node.
  4. Open the browser and navigate to the server; observe directory listing.
  5. Modify the URL to include encoded '../' sequences to traverse directories.
  6. Use curl with --path-as-is to request a file outside the root, such as /etc/passwd.

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.

The html-pages module serves files from a folder, but it does not check if someone tries to access files outside that folder using '../' sequences. An attacker can use a tool like curl to send a request with encoded '../' and read any file on the server, such as system password files.

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.