text stringlengths 0 1.99k |
|---|
-- 2.6.2 - --safe-links Bypass |
The --safe-links CLI flag makes the client validate any symbolic links it |
receives from the server. The desired behavior is that the symbolic links |
target can only be 1) relative to the destination directory and 2) never |
point outside of the destination directory. |
The unsafe_symlink() function is responsible for validating these symbolic |
links. The function calculates the traversal depth of a symbolic link |
target, relative to its position within the destination directory. |
As an example, the following symbolic link is considered unsafe: |
{DESTINATION}/foo -> ../../ |
As it points outside the destination directory. On the other hand, the |
following symbolic link is considered safe as it still points within the |
destination directory: |
{DESTINATION}/foo -> a/b/c/d/e/f/../../ |
This function can be bypassed as it does not consider if the destination |
of a symbolic link contains other symbolic links in the path. For example, |
take the following two symbolic links: |
{DESTINATION}/a -> . |
{DESTINATION}/foo -> a/a/a/a/a/a/../../ |
In this case, foo would actually point outside the destination directory. |
However, the unsafe_symlink() function assumes that a/ is a directory and |
that the symbolic link is safe. |
-- 2.6.3 - Arbitrary File Read |
When the server sends instructions for receiving a file to the receiver, |
it provides the client with an index into the file list(s). The |
corresponding entry is then created. Additionally, it will send a few |
flags that alter the behaviour of the file download. |
We mentioned previously that the server receives a list of checksums, each |
checksum related to a chunk of the file which is currently synchronized. |
We established that in simplified terms, the server sends the client |
instructions on which chunks to keep and which to update. The flags the |
server sends tell the client how to update the file. The client needs to |
know if it should overwrite the file in place or first create a copy and |
then replace the old version, for example. |
The server can set the flags ITEM_BASIS_TYPE_FOLLOWS and |
ITEM_XNAME_FOLLOWS, which tells the client to read matching chunks from an |
existing file and which file to read from. |
By default, there are no checks done on the xname that the server sends. |
The flag sanitize_paths, which causes sanitize_path() to sanitize xname, |
is off for clients: |
if (iflags & ITEM_XNAME_FOLLOWS) { |
if ((len = read_vstring(f_in, buf, MAXPATHLEN)) < 0) |
exit_cleanup(RERR_PROTOCOL); |
if (sanitize_paths) { |
sanitize_path(buf, buf, "", 0, SP_DEFAULT); |
len = strlen(buf); |
} |
} |
When the server sets the comparison type to FNAMECMP_FUZZY and provides an |
xname, the attacker can fully control the fnamecmp variable: |
case FNAMECMP_FUZZY: |
if (file->dirname) { |
pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, |
file->dirname, xname); |
fnamecmp = fnamecmpbuf; |
} else |
fnamecmp = xname; |
break; |
Control over this variable allows us to open any file as the compare file: |
fd1 = do_open(fnamecmp, O_RDONLY, 0); |
The compare file is used in the call to receive_data(), which handles the |
aforementioned instructions, or as they are called in the function tokens, |
received by the server. |
Tokens are then read from the server with a negative value, indicating |
thatthe client should read the data from the compare file. |
while ((i = recv_token(f_in, &data)) != 0) { |
..snip.. |
if (i > 0) { |
..snip.. |
} |
..snip.. |
if (fd != -1 && map && |
write_file(fd, 0, offset, map, len) != (int)len) |
Once recv_token() returns 0, which indicates the end of the |
synchronization, the client calculates a final checksum. This checksum is |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.