Skip to content

Quote a list for cmd.exe under a drive-relative path too - #113

Merged
HalRiveria merged 1 commit into
mainfrom
fix/drive-relative-cmd-quoting
Dec 3, 2026
Merged

HalRiveria merged 1 commit into
mainfrom
fix/drive-relative-cmd-quoting

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

What was wrong: given a list in -Arguments, the kit picks the quoting cmd.exe needs (a quote written "") when the program is cmd.exe or a .bat/.cmd. It recognized cmd.exe with a pattern that needed a slash or the start of the path before cmd, so a drive-relative path (C:cmd.exe, C:cmd) got the ordinary quoting, where a quote is written \". cmd.exe doesn't honor \", so an element like a" & echo INJECTED & " made it run a second command. The program run is cmd.exe either way: the start resolves the drive-relative path.

What changed: the pattern in Resolve-PkArgumentList also accepts a colon before cmd ((^|[\\/:])cmd(\.exe)?$). A .bat or .cmd was already recognized by its extension under any path.

How it was tested: harness section AE runs an injection payload through C:cmd.exe, C:cmd and C:CMD.EXE. with System32 as that drive's current folder, and checks that no second command ran and each run exited 0.

  • Before the fix (Windows PowerShell 5.1 and PowerShell 7): [FAIL] nor under a drive-relative path to cmd.exe (3 of 3 did, 0 failed to run, 0 ran)
  • After: [PASS] nor under a drive-relative path to cmd.exe (0 of 3 did, 0 failed to run, 3 ran)

Full harness: all 749 assertions pass on Windows PowerShell 5.1 and on PowerShell 7.

Batch-file quoting was picked by a pattern that needed a slash or the start of the path before 'cmd', so C:cmd.exe and C:cmd got the ordinary quoting, where a quote is written \" and cmd.exe doesn't honor it: an element like 'a" & echo X & "' ran a second command. The pattern now accepts a colon there too. Harness section AE runs the injection payload through C:cmd.exe, C:cmd and C:CMD.EXE. from System32.
@HalRiveria
HalRiveria added this pull request to stack #118 December 3, 2026 00:28
@HalRiveria
HalRiveria merged commit 9c25617 into main Dec 3, 2026
3 checks passed
@HalRiveria
HalRiveria deleted the fix/drive-relative-cmd-quoting branch December 3, 2026 00:29
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.

2 participants