Skip to content
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 error downloading a file from generic shell #18372

Merged
merged 1 commit into from
Oct 5, 2023

Conversation

gcarmix
Copy link
Contributor

@gcarmix gcarmix commented Sep 15, 2023

This PR solves the issue #18371 Error downloading a file from generic shell.

I found that it was an issue of scoping of the variable 'session_type' in file lib/msf/base/sessions/command_shell.rb at line 800

  def _file_transfer
    raise NotImplementedError.new('Session does not support file transfers.') if @session_type.ends_with?(':winpty')

    FileTransfer.new(self)
  end

The '@' should be removed

Verification

  • Start msfconsole
  • use auxiliary/scanner/ssh/ssh_login
  • Connect to a target and create a shell session
  • Download a file from the session
  • The file is downloaded correctly

@@ -797,7 +797,7 @@ def vprint_status(s)
end

def _file_transfer
raise NotImplementedError.new('Session does not support file transfers.') if @session_type.ends_with?(':winpty')
raise NotImplementedError.new('Session does not support file transfers.') if session_type.ends_with?(':winpty')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the tester, we should verify if we need to add in something slightly different here, potentially akin to:

    raise NotImplementedError.new('Session does not support file transfers.') if @session.session_type.ends_with?(':winpty')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the tester, we should verify if we need to add in something slightly different here, potentially akin to:

    raise NotImplementedError.new('Session does not support file transfers.') if @session.session_type.ends_with?(':winpty')

I've tried with your suggested code but it doesn't work, it comes back to the previous error

@adfoster-r7 adfoster-r7 self-assigned this Oct 2, 2023
@adfoster-r7 adfoster-r7 changed the title solves bug #18371 Fix error downloading a file from generic shell Oct 2, 2023
@sjanusz-r7
Copy link
Contributor

I've tested this with the suggested ssh_login module with a simple shell:

Before

Broken

download /home/kali/Desktop/win_met_x64_staged.exe /Users/sjanusz/Desktop/temp.exe
[-] Session manipulation failed: undefined method `ends_with?' for nil:NilClass ["/Users/sjanusz/Programming/metasploit-framework/lib/msf/base/sessions/command_shell.rb:800:in `_file_transfer'", "/Users/sjanusz/Programming/metasploit-framework/lib/msf/base/sessions/command_shell.rb:421:in `cmd_download'", "/Users/sjanusz/Programming/metasploit-framework/lib/msf/base/sessions/command_shell.rb:622:in `run_builtin_cmd'", "/Users/sjanusz/Programming/metasploit-framework/lib/msf/base/sessions/command_shell.rb:610:in `run_single'", "/Users/sjanusz/Programming/metasploit-framework/lib/msf/base/sessions/command_shell.rb:774:in `_interact_stream'", "/Users/sjanusz/Programming/metasploit-framework/lib/msf/base/sessions/command_shell.rb:750:in `block in _interact'", "/Users/sjanusz/Programming/metasploit-framework/lib/rex/ui/text/shell/history_manager.rb:31:in `with_context'", "/Users/sjanusz/Programming/metasploit-framework/lib/msf/base/sessions/command_shell.rb:749:in `_interact'", "/Users/sjanusz/Programming/metasploit-framework/lib/rex/ui/interactive.rb:53:in `interact'", "/Users/sjanusz/Programming/metasploit-framework/lib/msf/ui/console/command_dispatcher/core.rb:1680:in `cmd_sessions'", "/Users/sjanusz/Programming/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:581:in `run_command'", "/Users/sjanusz/Programming/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:530:in `block in run_single'", "/Users/sjanusz/Programming/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:524:in `each'", "/Users/sjanusz/Programming/metasploit-framework/lib/rex/ui/text/dispatcher_shell.rb:524:in `run_single'", "/Users/sjanusz/Programming/metasploit-framework/lib/rex/ui/text/shell.rb:168:in `block in run'", "/Users/sjanusz/Programming/metasploit-framework/lib/rex/ui/text/shell/history_manager.rb:31:in `with_context'", "/Users/sjanusz/Programming/metasploit-framework/lib/rex/ui/text/shell.rb:133:in `run'", "/Users/sjanusz/Programming/metasploit-framework/lib/metasploit/framework/command/console.rb:54:in `start'", "/Users/sjanusz/Programming/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'", "./msfconsole:23:in `<main>'"]

After

Working

download /home/kali/Desktop/win_met_x64_staged.exe /Users/sjanusz/Desktop/temp.exe

[*] Download /home/kali/Desktop/win_met_x64_staged.exe => /Users/sjanusz/Desktop/temp.exe
[+] Done

@sjanusz-r7 sjanusz-r7 merged commit faa3dd6 into rapid7:master Oct 5, 2023
@sjanusz-r7 sjanusz-r7 added the rn-fix release notes fix label Oct 5, 2023
@sjanusz-r7
Copy link
Contributor

Release Notes

Fixed an issue in the generic shell download command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-fix release notes fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants