Skip to content

Commit 6861b1f

Browse files
authored
Merge pull request rapid7#19729 from sempervictus/bug/shell_command_overlap
Fix overlap of shell built-in commands with host's
2 parents 7112fb2 + df6bd84 commit 6861b1f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/msf/base/sessions/command_shell.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ def cmd_help(*args)
202202
tbl << [key, value]
203203
end
204204

205+
tbl << ['.<command>', "Prefix any built-in command on this list with a '.' to execute in the underlying shell (ex: .help)"]
206+
205207
print(tbl.to_s)
206208
print("For more info on a specific command, use %grn<command> -h%clr or %grnhelp <command>%clr.\n\n")
207209
end
@@ -607,8 +609,13 @@ def run_single(cmd)
607609
end
608610

609611
# Built-in command
610-
if commands.key?(method)
611-
return run_builtin_cmd(method, arguments)
612+
if commands.key?(method) or ( not method.nil? and method[0] == '.' and commands.key?(method[1..-1]))
613+
# Handle overlapping built-ins with actual shell commands by prepending '.'
614+
if method[0] == '.' and commands.key?(method[1..-1])
615+
return shell_write(cmd[1..-1] + command_termination)
616+
else
617+
return run_builtin_cmd(method, arguments)
618+
end
612619
end
613620

614621
# User input is not a built-in command, write to socket directly

0 commit comments

Comments
 (0)