Fix PowerShell command injection via unescaped single quotes in file paths - #6
Open
msarg44 wants to merge 2 commits into
Open
Fix PowerShell command injection via unescaped single quotes in file paths#6msarg44 wants to merge 2 commits into
msarg44 wants to merge 2 commits into
Conversation
All five Set-/Get-ProcessMitigation file-path call sites embed a user-chosen (or user-influenced) path inside a single-quoted PowerShell string without escaping. A path containing an apostrophe (common on Windows, e.g. a folder named "User's Documents") breaks the command, and a crafted '; <cmd>; ' segment is a PowerShell command-injection primitive. Wrap every interpolated path in ps_quote(), which doubles literal single quotes -- the PowerShell escape for single-quoted strings -- so install, import, and backup paths are safe regardless of their contents.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
All five
Set-/Get-ProcessMitigationfile-path call sites inExploitProtection.PYembed a user-chosen or user-influenced path directly inside a single-quoted PowerShell string without any escaping:update_online_xml()(validation + import)backup_current_settings()import_local_xml()Why it matters
In PowerShell, a literal single quote inside a single-quoted string must be escaped by doubling it (
''). Without this:C:\Users\User's Documents\...) terminates the string early and breaks the command, so install/import/backup silently fails.C:\tmp'; Set-Item ...'lets an attacker who influences the path (e.g. via the XML import dialog, the online-XML download location, or a file name) break out of the quoted argument and inject arbitrary PowerShell. This is a PowerShell command-injection primitive.Fix
Added a small
ps_quote()helper that doubles literal single quotes (the PowerShell escape sequence for single-quoted strings) and wrapped every interpolated path in it, so install, import, and backup paths are safe regardless of their contents.No behavior change for normal paths — only paths containing an apostrophe are affected.