Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an alternative for the slash in a path?

Tags:

I have an application which correctly escapes slashes ("/) in file names to avoid path traversal attacks.

The secret file has this path: /tmp/secret.txt

I want to access this file by uploading a file with a special crafted file name (something like \/tmp\/secret.txt)

Is there any alternative syntax without the slashes which I can use so that Linux will read this file?

(I'm aware of URL encoding but as the escaping is done in the backend this has no use for me.)

like image 921
Yeti Avatar asked Apr 20 '18 14:04

Yeti


People also ask

Should directory paths end with slash?

Steps for serving only one URL version If your site has a directory structure, it's more conventional to use a trailing slash with your directory URLs (for example, example.com/directory/ rather than example.com/directory ), but you can choose whichever you like. Be consistent with the preferred version.

What do slashes mean in a path?

Microsoft uses the backwards slash, or backslash (\), to indicate folder names and paths. For example, the path C:\Windows\System indicates the System folder inside the Windows folder on the C: drive.

Why is there a double slash in path?

Double Backslashes (\\) Two backslashes are used as a prefix to a server name (hostname). For example, \\a5\c\expenses is the path to the EXPENSES folder on the C: drive on server A5.


1 Answers

No. The / is not allowed in a filename, no matter if it's escaped as \/ or not.

It is one out of only two characters that are not allowed in filenames, the other being \0.

This means that you obviously could use _tmp_secret.txt or -tmp-secret.txt, or replace the / in the path with any other character that you wish, to create a filename with a path "encoded into it". But in doing so, you can not encode pathnames that includes the chosen delimiter character in one or several of its path components and expect to decode it into the original pathname.

This is, by the way, how OpenBSD's ports system encodes filenames for patches to software. In (for example) /usr/ports/shells/fish/patches we find files with names like

patch-share_tools_create_manpage_completions_py

which comes from the pathname of a particular file in the fish shell source distribution (probably share/tools/create_manpage_completions.py). These pathnames are however never parsed, and the encoding is only there to create unique and somewhat intelligible filenames for the patches themselves. The real paths are included in the patch files.

like image 99
Kusalananda Avatar answered Oct 05 '22 13:10

Kusalananda