Skip to content

Commit 05279ef

Browse files
author
Brent Cook
committed
consistently use double-quoted paths
allow for variable expansion if needed
1 parent 0b0ac14 commit 05279ef

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/msf/core/post/file.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def cd(path)
1212
if session.type == "meterpreter"
1313
session.fs.dir.chdir(e_path)
1414
else
15-
session.shell_command_token("cd '#{e_path}'")
15+
session.shell_command_token("cd \"#{e_path}\"")
1616
end
1717
end
1818

@@ -67,7 +67,7 @@ def directory?(path)
6767
if session.platform =~ /win/
6868
f = cmd_exec("cmd.exe /C IF exist \"#{path}\\*\" ( echo true )")
6969
else
70-
f = session.shell_command_token("test -d '#{path}' && echo true")
70+
f = session.shell_command_token("test -d \"#{path}\" && echo true")
7171
end
7272

7373
return false if f.nil? or f.empty?
@@ -104,7 +104,7 @@ def file?(path)
104104
f = cmd_exec("cmd.exe /C IF exist \"#{path}\\\\\" ( echo false ) ELSE ( echo true )")
105105
end
106106
else
107-
f = session.shell_command_token("test -f '#{path}' && echo true")
107+
f = session.shell_command_token("test -f \"#{path}\" && echo true")
108108
end
109109

110110
return false if f.nil? or f.empty?
@@ -127,7 +127,7 @@ def exist?(path)
127127
if session.platform =~ /win/
128128
f = cmd_exec("cmd.exe /C IF exist \"#{path}\" ( echo true )")
129129
else
130-
f = cmd_exec("test -e '#{path}' && echo true")
130+
f = cmd_exec("test -e \"#{path}\" && echo true")
131131
end
132132

133133
return false if f.nil? or f.empty?
@@ -261,7 +261,7 @@ def read_file(file_name)
261261
if session.platform =~ /win/
262262
data = session.shell_command_token("type \"#{file_name}\"")
263263
else
264-
data = session.shell_command_token("cat \'#{file_name}\'")
264+
data = session.shell_command_token("cat \"#{file_name}\"")
265265
end
266266

267267
end
@@ -340,7 +340,7 @@ def rm_f(*remote_files)
340340
if session.platform =~ /win/
341341
cmd_exec("del /q /f \"#{remote}\"")
342342
else
343-
cmd_exec("rm -f '#{remote}'")
343+
cmd_exec("rm -f \"#{remote}\"")
344344
end
345345
end
346346
end
@@ -522,7 +522,7 @@ def _write_file_unix_shell(file_name, data, append=false)
522522
# The first command needs to use the provided redirection for either
523523
# appending or truncating.
524524
cmd = command.sub("CONTENTS") { chunks.shift }
525-
session.shell_command_token("#{cmd} #{redirect} '#{file_name}'")
525+
session.shell_command_token("#{cmd} #{redirect} \"#{file_name}\"")
526526

527527
# After creating/truncating or appending with the first command, we
528528
# need to append from here on out.

0 commit comments

Comments
 (0)