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

[buttle] Path traversal in mid-buttle module allows to read any file in the server.

The buttle static file server used a regular expression to detect markdown files that did not anchor the match to the end of the URL, and it did not block path traversal sequences. An attacker could request a URL containing '.markdown' followed by '../' sequences to read arbitrary files on the server.

n0n4me Follow

Originally disclosed on HackerOne

Critical 10.0 View original
  • Triaged in 20 days
  • Fixed in 31 days
  • Disclosed after 31 days

Hello Node.js third-party modules

I would like to report path traversal in buttle module It allows me to read any file in the server if i know the path.

Module

module name: buttle version: 0.2.0 npm page: https://www.npmjs.com/package/buttle

Module Description

Simple static file (+ markdown) server.

Module Stats

[21] downloads in the last week

Vulnerability

Vulnerability Description

module mid-buttle.js uses regex to check the url containing the string ".markdown". I think, the right check of the author wants, is string ".markdown" located the end of the url. But he forgot the $ in the regex. That is the first vulnerability. The second is he does not check for path traversal (../).

 var url = req.url;
    if(/\.md$/i.test(url) || /\.markdown/i.test(url)) {
      fs.exists(j(dir, url), function(exists) {
        if(exists) {
          fs.readFile(j(dir, url), {encoding: 'utf8'}, function(err, data) {
            if(err) { return res.end(err.message); }
            res.end(wrapInHtml(md(data)));
          });
        } else {
          next();
        }
      });
    } else {
      next();
}

Link in github: https://github.com/jtrussell/buttle/blob/master/lib/mid-buttle.js#L16

Steps To Reproduce:

install buttle

$ npm install -g buttle

start buttle

$ buttle ./

start the burpsuite. Enter the url contain string ".markdown" and ../ to traverse to the file you want.

1.__Buttle__PoC-Path_traversal.png
1.__Buttle__PoC-Path_traversal.png From the original on HackerOne

Patch

I recommend that:

  1. Should filter ".." in url before using that for reading file. (check path traversal)
  2. correct the specific string in the url for your check. (check logic bug)

Supporting Material/References:

  • Kali linux 4.15.0
  • v8.11.2
  • 6.1.0
  • Burpsuite community

Wrap up

  • I contacted the maintainer to let them know: N
  • I opened an issue in the related repository: N

Impact

The malicious user can use this vulnerability to read some file containing credential, ssh key files, source code ...

The original report as published on HackerOne, by n0n4me. 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

Likely the markdown file check used an unanchored regular expression and the file path was built from the raw URL without rejecting '..' sequences, allowing directory traversal.

Impact

A malicious user could read files containing credentials, SSH keys, or source code.

What the attacker needed

Buttle server running; attacker can send HTTP requests; attacker knows the target file path

The fix

The URL should be filtered to reject '..' before being used to read a file, and the markdown check should be corrected to match only the end of the URL.

How it was found

  1. Install the buttle module globally.
  2. Start buttle serving the current directory.
  3. Use a proxy tool to send a request whose URL contains '.markdown' and '../' sequences to traverse to the target 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 give out files from the folder it is meant to share. Here, the server checked whether the web address contained the text '.markdown' but did not make sure that text was at the very end, and it also allowed '..' in the address. The '..' means 'go up one folder', so an attacker could walk out of the shared 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 n0n4me

View all

1 more disclosed report, 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.