Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Handle directories uploaded into zip file. #3327

Merged
merged 3 commits into from
Mar 7, 2024
Merged

Conversation

scudette
Copy link
Contributor

@scudette scudette commented Mar 7, 2024

A Zip archive only contains files and has no concept of directories. If the upload() VQL function is accidentally called on a directory, Velociraptor will try to read the directory and store it in the zip file. This leads to a 0 length file placed in the middle of a directory path:

/Foo/Bar <- zero length file
/Foo/Bar/Baz <- a real file.

This makes the real file impossible to extract and third party zip programs will be unable to write it once they created a file at the directory level above. This also confuses Velociraptor's zip accessor which emulates directories based on path prefixes and see /Foo/Bar as a file not a directory (so it does not recurse into it).

This PR ensures that when a directory is passed to upload() it will have a trailing / appended. This seems to be a convention with zip programs to denote a directory in a zip file. Additionally we consider a zero length file in the zip archive to be a directory regardless if it has a trailing / in order to be able to recover older collections which were written without the trailing /.

scudette added 3 commits March 7, 2024 03:17
A Zip archive only contains files and has no concept of
directories. If the upload() VQL function is accidentally called on a
directory, Velociraptor will try to read the directory and store it in
the zip file. This leads to a 0 length file placed in the middle of a
directory path:

/Foo/Bar <- zero length file
/Foo/Bar/Baz <- a real file.

This makes the real file impossible to extract and third party zip
programs will be unable to write it once they created a file at the
directory level above. This also confuses Velociraptor's zip accessor
which emulates directories based on path prefixes and see /Foo/Bar as
a file not a directory (so it does not recurse into it).

This PR ensures that when a directory is passed to upload() it will
have a trailing / appended. This seems to be a convention with zip
programs to denote a directory in a zip file. Additionally we consider
a zero length file in the zip archive to be a directory regardless if
it has a trailing / in order to be able to recover older collections
which were written without the trailing /.
@scudette scudette merged commit a334c37 into master Mar 7, 2024
3 checks passed
@scudette scudette deleted the zip_directories branch March 7, 2024 04:45
scudette added a commit that referenced this pull request Mar 10, 2024
A Zip archive only contains files and has no concept of directories. If
the upload() VQL function is accidentally called on a directory,
Velociraptor will try to read the directory and store it in the zip
file. This leads to a 0 length file placed in the middle of a directory
path:

/Foo/Bar <- zero length file
/Foo/Bar/Baz <- a real file.

This makes the real file impossible to extract and third party zip
programs will be unable to write it once they created a file at the
directory level above. This also confuses Velociraptor's zip accessor
which emulates directories based on path prefixes and see /Foo/Bar as a
file not a directory (so it does not recurse into it).

This PR ensures that when a directory is passed to upload() it will have
a trailing / appended. This seems to be a convention with zip programs
to denote a directory in a zip file. Additionally we consider a zero
length file in the zip archive to be a directory regardless if it has a
trailing / in order to be able to recover older collections which were
written without the trailing /.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant