-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Land #18021, Fix #cd for Powershell Sessions
- Loading branch information
Showing
3 changed files
with
16 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
# -*- coding: binary -*- | ||
|
||
module Msf::Post::Windows | ||
# Escape a string literal value to be included as an argument to cmd.exe. The escaped value *should not* be placed | ||
# within double quotes as this will alter now it is evaluated (e.g. `echo "^"((^&test) Foo^""` is different than | ||
# `echo ^"((^&test) Foo^"`. | ||
# | ||
# @param [String] string The string to escape for use with cmd.exe. | ||
# @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:) | ||
string = string.dup | ||
%w[ ^ & < > | " ].each { |char| string.gsub!(char, "^#{char}") } | ||
string.gsub!(' ', '" "') if spaces | ||
string | ||
end | ||
end |