Skip to content

Commit

Permalink
Fix overlap of shell built-in commands with host's
Browse files Browse the repository at this point in the history
When a shell session is established against a system which offers
limited shells, its very common to run into something like "help"
being a native command in the target. MSF now intercepts those as
built-ins and presents the MSF shell help instead of letting the
user see the relevant output from the target.

Implement a fix by allowing the user to prepend built-ins with '.'
to pass-through execution of the intended command (such as '.help'
being executed as 'help') to the target.

Testing:
  Local testing with racadm SSH shell - works as intended
  • Loading branch information
RageLtMan committed Dec 15, 2024
1 parent cb68297 commit 54bec33
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/msf/base/sessions/command_shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,13 @@ def run_single(cmd)
end

# Built-in command
if commands.key?(method)
return run_builtin_cmd(method, arguments)
if commands.key?(method) or ( not method.nil? and method[0] == '.' and commands.key?(method[1..-1]))
# Handle overlapping built-ins with actual shell commands by prepending '.'
if method[0] == '.' and commands.key?(method[1..-1])
return shell_write(cmd[1..-1] + command_termination)
else
return run_builtin_cmd(method, arguments)
end
end

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

0 comments on commit 54bec33

Please sign in to comment.