-
Notifications
You must be signed in to change notification settings - Fork 14k
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
Fix #cd for Powershell Sessions #18021
Conversation
# @param [Boolean] spaces Whether or not to escape spaces. If the string is being passed to echo, set this to false | ||
# otherwise if it's an argument, set it to true. | ||
# @return [String] The escaped string. | ||
def self.escape_cmd_literal(string, spaces:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces
is optional here because sometimes they need to be escaped, and other times they do not.
This snippet demonstrates the issue. A small Python stub is used to print the arguments then one" "argument
is passed to it showing that the space is kept but when passed to echo, the double quotes are kept.
Microsoft Windows [Version 10.0.17763.4377](c) 2018 Microsoft Corporation. All rights reserved.
msflab\smcintyre@DC C:\Users\smcintyre>type args.py
import sys; print(repr(sys.argv))
msflab\smcintyre@DC C:\Users\smcintyre>python args.py one" "argument
['args.py', 'one argument']
msflab\smcintyre@DC C:\Users\smcintyre>echo one" "argument
one" "argument
msflab\smcintyre@DC C:\Users\smcintyre>
Allowing the user to specify means the escaped value can be used in both contexts. Psexec should not escape spaces because the command is passed to echo.
Before
After
Did some investigating but ultimately wasn't sure what was causing system info of target
|
Release NotesThe Powershell Post API methods use a mix of Powershell and .NET methods which have different ways of keeping track of the current working directory. This changes fixes the ambiguity by synchronizing the current working directory referenced by each set of methods. |
Per PowerShell/PowerShell#10278 the .NET working directory is different from the Powershell one. Our Powershell Post API methods use a mix of Powershell and .NET methods. This means that after changing directory, methods that use .NET will fail when given relative paths because the current working directory is different. The proposed solution is to set the .NET working directory at the same time so they stay synchronized. With this in place, 3 tests will start to pass from the
post/test/file
module, leaving just one failure.Also added is a method to escape Windows command literals that's more robust that what was added here which ended up breaking the
cmd/windows/powershell_reverse_tcp
payload when delivered via psexec.Verification
msfconsole
use exploit/windows/smb/psexec
cmd/windows/powershell_reverse_tcp
loadpath test/modules
post/test/file
module with the new session.should delete a symbolic link target
will fail but the rest will passshould create directories
passes 🟢should list the directory we just made
passes 🟢should not recurse into symbolic link directories
passes 🟢New Output
Old Output