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

Zip loader for Velociraptor packages #355

Merged
merged 24 commits into from
Aug 28, 2023

Conversation

OlafHaalstra
Copy link
Contributor

@OlafHaalstra OlafHaalstra commented Aug 13, 2023

Implemented a zip loader for Velociraptor packages.

Currently works on Velociraptor packages that have been created with release >=0.6.7

Still looking for advise on:

  • How to implement Linux / OSX filesystems
  • Combining both Velociraptor parsers. I have chosen to create a new loader to support the zips since parsing zips might punish performance. Can probably also be implemented in such a way that it supports both ZIPs and regular folders

@OlafHaalstra
Copy link
Contributor Author

@Zawadidone it would be nice if you could quickly review this as well given your history with parsing Velociraptor

@Zawadidone
Copy link
Contributor

I have tested the Velociraptor features of version https://github.com/Velocidex/velociraptor/releases/tag/v0.7.0.

Velociraptor Artifact Options Result Fix
Windows.KapeFiles.Targets UseAutoAccessor:Y,_SANS_Triage:Y,VSSAnalysisAge:365 The ntfs_vss which adds drives to uploads/ntfs_vss/, e.g. uploads/ntfs_vss/%5C%5C.%5CC%3A/ Map/mount the drivers/folders in uploads/ntfs_vss/
Windows.KapeFiles.Targets UseAutoAccessor:N,_SANS_Triage:Y,VSSAnalysisAge:365 The ntfs_vss which adds drives to uploads/ntfs_vss/, e.g. uploads/ntfs_vss/%5C%5C.%5CC%3A/, but in case Map/mount the drivers/folders in uploads/ntfs_vss/
Windows.KapeFiles.Targets UseAutoAccessor:N,_SANS_Triage:Y,VSSAnalysisAge:0 Depending on the path the accessors lazy_ntfs or ntfs is used Map/mount drives in uploads/<accessor>/
Windows.KapeFiles.Targets UseAutoAccessor:Y,_SANS_Triage:Y,VSSAnalysisAge:0 Depending on the path the accessors lazy_ntfs or ntfs is used Map/mount drives in uploads/<accessor>/

For Linux, MacOS, etc see the table below.

Velociraptor Artifact Options Result Fix
Generic.Collectors.File root:/, accessor:file The root directory starts at uploads/file/ Map/mount the root directory uploads/file/
Generic.Collectors.File root:/, accessor:file The root directory starts at uploads/auto/ Map/mount the root directory uploads/auto/

I have created a PR (#358) to fix this in the VelociraptorLoader but there is something wrong with the acquired files related to the NTFS filesystem (#358 (comment)).

@Schamper
Copy link
Member

Schamper commented Aug 15, 2023

Combining both Velociraptor parsers. I have chosen to create a new loader to support the zips since parsing zips might punish performance. Can probably also be implemented in such a way that it supports both ZIPs and regular folders

The zipfile module partially implements the pathlib API through the zipfile.Path object (which I see you're already using). Perhaps the logic in the original Velociraptor loader could be tweaked to be generic on a pathlib.Path-like object, so that it works on both zip files and directories.

How to implement Linux / OSX filesystems

Combining the loaders probably solves this problem too?

@Zawadidone
Copy link
Contributor

Zawadidone commented Aug 18, 2023

@OlafHaalstra is it possible to add the ZIP Loader to the updated VelociraptorLoader (#358) that supports version Velociraptor version 0.7.0?

target-query -q -f hostname,os -t *
<Target VSSAnalysisAge-N> MSEDGEWIN10 windows
<Target VSSAnalysisAge-Y> MSEDGEWIN10 windows
<Target autoaccessor-N.exe> MSEDGEWIN10 windows
<Target autoaccessor-Y> MSEDGEWIN10 windows
<Target linux-auto> dummy unix
<Target linux-file> dummy unix

@OlafHaalstra
Copy link
Contributor Author

@OlafHaalstra is it possible to add the ZIP Loader to the updated VelociraptorLoader (#358) that supports version Velociraptor version 0.7.0?

target-query -q -f hostname,os -t *
<Target VSSAnalysisAge-N> MSEDGEWIN10 windows
<Target VSSAnalysisAge-Y> MSEDGEWIN10 windows
<Target autoaccessor-N.exe> MSEDGEWIN10 windows
<Target autoaccessor-Y> MSEDGEWIN10 windows
<Target linux-auto> dummy unix
<Target linux-file> dummy unix

@Zawadidone could you test the original zipfiles with the current PR?

@OlafHaalstra
Copy link
Contributor Author

With the new commit I tried to combine both loaders into a single file, due to the fact that map_dirs is not able to correctly parse the correct Windows drives I reimplemented it partially inside the Velociraptor loader to support the %5C%5C.%5CD%3A and C%3A style of writing drives. Potentially we can also move this functionality to expand map_dirs in dir.py.

Ideally you would combine more code for zips and non zips but I wasn't fully able to do so. The zip folder parsing follows the way tar is also parsed. Folders are parsed the same way as they were with the exception of determining the correct drive.

@Schamper
Copy link
Member

@OlafHaalstra I've made some changes to re-use more existing code. The unit tests pass, can you test if this works on real Velociraptor ZIPs too?

I looked briefly into making DirFilesystem compatible with zipfile.Path but unfortunately it's missing too much functionality for that.

@codecov
Copy link

codecov bot commented Aug 21, 2023

Codecov Report

Merging #355 (08027be) into main (3bf722f) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #355      +/-   ##
==========================================
+ Coverage   71.93%   71.95%   +0.02%     
==========================================
  Files         236      236              
  Lines       18740    18755      +15     
==========================================
+ Hits        13481    13496      +15     
  Misses       5259     5259              
Flag Coverage Δ
unittests 71.95% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
dissect/target/loaders/dir.py 98.68% <100.00%> (+0.07%) ⬆️
dissect/target/loaders/velociraptor.py 95.91% <100.00%> (+1.18%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Zawadidone
Copy link
Contributor

@OlafHaalstra it works thanks for the feature!

@OlafHaalstra
Copy link
Contributor Author

@Schamper your improvements work on the real zip from Velociraptor! Thanks 😄

@DissectBot
Copy link

@OlafHaalstra thank you for your contribution! As this is your first code contribution, please read the following Contributor License Agreement (CLA). If you agree with the CLA, please reply with the following information:

@DissectBot agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
Contributor License Agreement

Contribution License Agreement

This Contribution License Agreement ("Agreement") governs your Contribution(s) (as defined below) and conveys certain license rights to Fox-IT B.V. ("Fox-IT") for your Contribution(s) to Fox-IT"s open source Dissect project. This Agreement covers any and all Contributions that you ("You" or "Your"), now or in the future, Submit (as defined below) to this project. This Agreement is between Fox-IT B.V. and You and takes effect when you click an “I Accept” button, check box presented with these terms, otherwise accept these terms or, if earlier, when You Submit a Contribution.

  1. Definitions.
    "Contribution" means any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to Fox-IT for inclusion in, or documentation of, any of the software products owned or managed by, or on behalf of, Fox-IT as part of the Project (the "Work").
    "Project" means any of the projects owned or managed by Fox-IT and offered under a license approved by the Open Source Initiative (www.opensource.org).
    "Submit" means any form of electronic, verbal, or written communication sent to Fox-IT or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, Fox-IT for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."

  2. Grant of Copyright License. Subject to the terms and conditions of this Agreement, You hereby grant to Fox-IT and to recipients of software distributed by Fox-IT a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.

  3. Grant of Patent License. Subject to the terms and conditions of this Agreement, You hereby grant to Fox-IT and to recipients of software distributed by Fox-IT a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, maintain, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed.

  4. Representations. You represent that:

    • You are legally entitled to grant the above license.
    • each of Your Contributions is Your original creation (see section 8 for submissions on behalf of others).
    • Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
  5. Employer. If Your Contribution is made in the course of Your work for an employer or Your employer has intellectual property rights in Your Submission by contract or applicable law, You must secure permission from Your employer to make the Contribution before signing this Agreement. In that case, the term "You" in this Agreement will refer to You and the employer collectively. If You change employers in the future and desire to Submit additional Contribution for the new employer, then You agree to sign a new Agreement and secure permission from the new employer before Submitting those Contributions.

  6. Support. You are not expected to provide support for Your Contribution, unless You choose to do so. Any such support provided to the Project is provided free of charge.

  7. Warranty. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.

  8. Third party material. Should You wish to submit work that is not Your original creation, You may only submit it to Fox-IT separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which You are personally aware, and conspicuously marking the work as "Submitted on behalf of a third-party: [named here]".

  9. Notify. You agree to notify Fox-IT of any facts or circumstances of which You become aware that would make the above representations inaccurate in any respect.

  10. Governing law / competent court. This Agreement is governed by the laws of the Netherlands. Any disputes that may arise are resolved by arbitration in accordance with the Arbitration Regulations of the Foundation for the Settlement of Automation Disputes (Stichting Geschillenoplossing Automatisering – SGOA – (www.sgoa.eu), this without prejudice to either party"s right to request preliminary relief in preliminary relief proceedings or arbitral preliminary relief proceedings. Arbitration proceedings take place in Amsterdam, or in any other place designated in the Arbitration Regulations. Arbitration shall take place in English.

@OlafHaalstra
Copy link
Contributor Author

@DissectBot agree

@Schamper Schamper requested review from Miauwkeru and Poeloe and removed request for Miauwkeru August 22, 2023 14:01
tests/test_loaders_velociraptor.py Outdated Show resolved Hide resolved
@Schamper Schamper requested a review from Poeloe August 27, 2023 19:58
tests/test_loaders_velociraptor.py Outdated Show resolved Hide resolved
tests/test_loaders_velociraptor.py Outdated Show resolved Hide resolved
Schamper and others added 2 commits August 28, 2023 16:24
Co-authored-by: Paul M <22234727+Poeloe@users.noreply.github.com>
Copy link
Contributor

@Poeloe Poeloe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Schamper Schamper merged commit 9e14c54 into fox-it:main Aug 28, 2023
10 checks passed
Zawadidone pushed a commit to Zawadidone/dissect.target that referenced this pull request Apr 5, 2024
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.

5 participants