Can use null characters to escape filesystem
See original GitHub issueI haven’t totally figured out how this works but one of our users managed to escape the restraints of a subfilesystem to be able to write anywhere on the physical filesystem.
The basic theory is this…
using System.IO;
using Zio;
using Zio.FileSystems;
var physical = new PhysicalFileSystem();
// create a sandboxed subsystem
var subsystem = new Zio.FileSystems.SubFileSystem(physical, "/mnt/c/temp/sandboxed", false);
// cool! this is allowed!
subsystem.WriteAllText("/hello.txt", "hello");
// agh!
UPath path = "/\0\0/mnt/windows/system32/evil.txt";
subsystem.WriteAllText(path, "we escaped!");
This seems to want to write to a T: drive (which I don’t have).
But obviously there’s some deeper funny business going on here.
I’m not sure whether you even meant for the subfilesystems to work in the sandboxed fashion we’re using them, but since this seems like unpredictable/unwanted behaviour I thought I would report it.
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
bash - Using/reading/writing the null and escape characters
I know that a filename in Linux has no restriction whatsoever except for two characters '/' and '\0' . I know that '/'...
Read more >in linux, is it normal that there is no null character at the end ...
There is usually no null character at the end of files on Unix. An empty text file has zero bytes. One empty line...
Read more >Null character
In source code, the null character is often represented as the escape sequence \0 in string literals (for example, "abc\0def" ) or in...
Read more >Which common characters are illegal in Unix and Windows ...
Most filesystems are fairly permissive: for example, all NTFS, extN, btrfs, XFS and ReiserFS allow everything except 1) the null byte and 2) ......
Read more >What characters are safe in cross-platform file names for ...
Linux, OS-X: anything except null or /. On all platforms it is best to avoid non-printable characters such as the ASCII control-characters.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have pushed a commit 930974d that should fix this issue. The code was using
StarsWith
without ordinal comparison, so it could make the actual checks to be completely bypassed.Thanks @ninjasploit! Yeah, indeed, we probably need to always check the expanded path to make sure it is within boundaries.