Skip to content

Commit

Permalink
win: improve security of soft file/app delete $260
Browse files Browse the repository at this point in the history
This commit improves soft file delete logic:

- Unify logic for soft deleting single files and system apps.
- Rename `RenameSystemFile` templating function to `SoftDeleteFiles` so
  new name gives clarity to:
   - It's not necessarily single file being renamed but can be multiple
     files.
   - It's not necessarily system files being renamed, but can also work
     without granting extra permissions.
- Grant permissions for only files that will be backed up, skipping
  unnecessarily granting permissions to folders/other files. Both
  `SeRestorePrivilege` and `SeTakeownershipPrivileges` are claimed and
  revoked as necessary.
- Make granting permissions optional through `grantPermissions`
  parameter. Do not take permissions if not needed.
- Restore permissions to system default after file is renamed. Before
  both deletion of system apps and renaming system files did not restore
  their original permissions. This might leave user computers
  vulnerable, which is fixed in this commit. It ensures that the
  system's original security posture is preserved.
- Deleting system apps do not depend on `Get-AppxPackage`, making it
  more robust for being able to clean-up residual files once $260 (hard
  deleting of system apps) is implemented.
- Introduce common way to share glob iteration logic of how the
  directories are being cleaned up. It reuses most of the logic from
  former `DeleteGlob` with some improvements:
  - Simplify call to `Get-ChildItem` but not building a `-Filter`
    parameter.
  - Improve reliability of getting parent directory in `DeleteGlob`
    sanity check to use .NET's `[System.IO.Path]` methods.

TODO: Remove this
  - Fix `parentDirectory.EndsWith('/')` using wrong path separator,
    change it to `parentDirectory.EndsWith('\')`.
  - Fix a matching issue when wildcards are present in the parent
    directory by ensuring base directory and filter are correctly
    identified using .NET's `[System.IO.Path]` methods.
    An example of the issue:
      Iterating `C:\User\OneDrive*\` finds any folder or file that
      starts with `OneDrive` recursively inside `C:\User` and one of its
      subfolders.
    Current fixed behavior:
      Iterating `C:\User\OneDrive*` finds any folder or file starting
      with `OneDrive` in `C:\User\` directory only
  • Loading branch information
undergroundwires committed Oct 26, 2023
1 parent 80821fc commit 11c132c
Showing 1 changed file with 390 additions and 224 deletions.
Loading

0 comments on commit 11c132c

Please sign in to comment.