-
Notifications
You must be signed in to change notification settings - Fork 8.1k
WIP: Windows: Alternate Data Steams on directories are now accessible. #13795
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
Conversation
|
All issues raised by CodeFactor are in code that I didn't touch. @anmenaga Please review when you get a moment? |
|
I tested it, it works. One thing though before the compatibility is set in stone, does it make sense that PsIsContainer is $True? It's a member of a container, but I don't think streams that are parts of folders can have any children in NTFS.... |
You are correct, data streams cannot contain children. That's a handy mnemonic to understand why files always have default (unnamed) data streams, and why directories can never have default data streams. Unfortunately, I can't figure out the path by which the property is set, so I can't figure out if I have enough information available anywhere to communicate to that location that even though the filesystem entry is a directory it's actually a stream on a directory. If you have any suggestions to figuring out how it works, I am attentive. I'm just a filesystem guy, not a PowerShell internal structure guy, and I've been trying to push this so I can get back to work on what I'm actually supposed to be working on (a Windows filesystem filter driver that uses alternate data streams to store persistent data). :/ |
I did some exploring tonight, and thought I might have figured it out, but alas it didn't work the way I wanted to. You apparently can't use I can't figure out where "Stream" is added as a dynamic parameter, so I can't really do anything there either. Ideally, if PSChildName contains a |
|
I found it! Now, I need to write tests for it to make sure it's correct. Will set the title here to WIP. |
|
I apparently suck at git, and I've gotten my local repository into a state where I can't push it. Will try again on Yet Another Branch[tm]. |
|
Superseded by #13941, because apparently some pull I made is trying to update workflow but my OAUTH token doesn't have the "workflow" scope. That PR has all tests written and all commits squashed for review, and addresses @n3rdopolis's concern about $PSIsContainer on the alternate data streams. |
PR Summary
This PR allows
Get-Item -Stream,Get-Content -Stream,Clear-Content -Stream,Set-Content -Stream,Add-Content -Stream, andRemove-Item -Streamto see and address alternate data streams on directories, not merely on files.Fixes #10570. Fixes #13656.
Supersedes #13650 (squashes all intermediary commits).
PR Context
Issue #10570 has been open for a year. NTFS supports what are called "Alternate Data Streams" on both files and directories (multiple named discrete blobs of data which are associated with a single directory entry). PowerShell currently supports enumeration of these Alternate Data Streams on files, using the '-Stream' parameter to 'Get-Item'. It also supports manipulation of these alternate data streams on files, using the '-Stream' parameter to Set-Content, Add-Content, Clear-Content, and Remove-Item.
Unfortunately, the initial implementation of PowerShell only supported alternate data streams on files, not on directories. This makes an entire facility of the OS's file system invisible, and if an administration team is relying on PowerShell it makes an attractive place for a red team to store data to exfiltrate. (This is not an invitation to destroy the capability to store alternate data streams on directories, as they are useful for many purposes. It is merely a rationale for making their existence visible through PowerShell.)
To create and see an alternate data stream on a directory, use cmd.exe to run the following commands:
The output is something like:
To see the failure of PowerShell being able to see the stream on the file, but not the directory:
Writing the tests revealed that Set-Content internally calls Clear-Content, which is hardcoded to not check for streams on directories. This was raised as an issue in Issue #13656, but I decided to put that into this PR as well.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.