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 RequestError class undefined method issue #14887

Merged
merged 1 commit into from
Mar 15, 2021

Conversation

space-r7
Copy link
Contributor

@space-r7 space-r7 commented Mar 13, 2021

If Metasploit receives an error response from Mettle, Metasploit attempts to return which command failed. The search for the command id currently throws a NoMethodError because start_with? is called on a Symbol instead of a String. This change just makes sure the variable used is a string before start_with? is called on it.

Verification

  • Start msfconsole
  • Generate a Meterpreter payload
  • Get a Meterpreter session
  • Use a command that you expect to fail: rm blah.notrealext
  • Verify that the error tells you which extension / command was used

Scenarios

Before fix

msf6 > use multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload linux/x64/meterpreter/reverse_tcp
payload => linux/x64/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set lhost 192.168.37.1
lhost => 192.168.37.1
msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 192.168.37.1:4444 
[*] Sending stage (3008420 bytes) to 192.168.37.170
[*] Meterpreter session 1 opened (192.168.37.1:4444 -> 192.168.37.170:35530) at 2021-03-12 17:56:58 -0600

meterpreter > rm blah.c
[-] Error running command rm: NoMethodError undefined method `start_with?' for :TLV_TYPE_LOCAL_DATETIME:Symbol

After fix

msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 192.168.37.1:4444 
[*] Sending stage (3008420 bytes) to 192.168.37.170
[*] Meterpreter session 2 opened (192.168.37.1:4444 -> 192.168.37.170:35532) at 2021-03-12 17:59:07 -0600

meterpreter > rm blah.c
[-] stdapi_fs_delete_file: Operation failed: 1

@space-r7 space-r7 added the bug label Mar 13, 2021
@timwr
Copy link
Contributor

timwr commented Mar 13, 2021

For some reason I can't reproduce the original error (without the fix applied):

msf6 exploit(multi/handler) > ruby -v
[*] exec: ruby -v

ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
msf6 exploit(multi/handler) > version
Framework: 6.0.35-dev-a428c5721d
Console  : 6.0.35-dev-a428c5721d
msf6 exploit(multi/handler) >
[*] Sending stage (3008420 bytes) to 192.168.13.37
[*] Meterpreter session 2 opened (192.168.13.37:4444 -> 192.168.13.37:50732) at 2021-03-13 11:03:01 +0000

msf6 exploit(multi/handler) > sessions 2
[*] Starting interaction with 2...

meterpreter > rm blah.notrealfile
[-] stdapi_fs_delete_file: Operation failed: 1

@bcoles
Copy link
Contributor

bcoles commented Mar 13, 2021

For some reason I can't reproduce the original error (without the fix applied):

I presumed, perhaps in error, that spacey's examples were around the wrong way. ie, before fix should read after fix.

I am wrong.

@space-r7
Copy link
Contributor Author

For some reason I can't reproduce the original error (without the fix applied):

msf6 exploit(multi/handler) > ruby -v
[*] exec: ruby -v

ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
msf6 exploit(multi/handler) > version
Framework: 6.0.35-dev-a428c5721d
Console  : 6.0.35-dev-a428c5721d
msf6 exploit(multi/handler) >
[*] Sending stage (3008420 bytes) to 192.168.13.37
[*] Meterpreter session 2 opened (192.168.13.37:4444 -> 192.168.13.37:50732) at 2021-03-13 11:03:01 +0000

msf6 exploit(multi/handler) > sessions 2
[*] Starting interaction with 2...

meterpreter > rm blah.notrealfile
[-] stdapi_fs_delete_file: Operation failed: 1

Thanks for trying that out! Yea, I was using 2.6 at the time, and that was the issue. It looks like the start_with?() method was added to the Symbol class in v2.7:

https://ruby-doc.org/core-2.6/Symbol.html
https://ruby-doc.org/core-2.7.0/Symbol.html

@adfoster-r7
Copy link
Contributor

adfoster-r7 commented Mar 15, 2021

The fix seems good to me, we currently aim to have framework working with Ruby 2.5, 2.6, 2.7 - and soon in the future 3.0

ruby:
- 2.5
- 2.6
- 2.7

Although Ruby 2.5 will be EOL soon enough:

Ruby 2.5
status: security maintenance
release date: 2017-12-25
EOL date: 2021-03-31

Just verified the behavior of start_with in IRB with Ruby 2.7:

2.7.2 :001 > 'a'.start_with? 'a'
 => true
2.7.2 :002 > :a.start_with? 'a'
 => true 
2.7.2 :003 > RUBY_DESCRIPTION
 => "ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]" 

With Ruby 2.6:

2.6.5 :001 > 'a'.start_with? 'a'
 => true 
2.6.5 :002 > :a.start_with? 'a'
Traceback (most recent call last):
	21: from /Users/user/.rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `<main>'
	20: from /Users/user/.rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `eval'
	19: from /Users/user/.rvm/gems/ruby-2.6.5/bin/irb:23:in `<main>'
	18: from /Users/user/.rvm/gems/ruby-2.6.5/bin/irb:23:in `load'
	17: from /Users/user/.rvm/gems/ruby-2.6.5/gems/irb-1.3.2/exe/irb:11:in `<top (required)>'
(irb):2:in `<main>': undefined method `start_with?' for :a:Symbol (NoMethodError)
2.6.5 :003 > RUBY_DESCRIPTION
 => "ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]" 

@adfoster-r7 adfoster-r7 merged commit ce48d75 into rapid7:master Mar 15, 2021
@adfoster-r7 adfoster-r7 added the rn-fix release notes fix label Mar 15, 2021
@adfoster-r7
Copy link
Contributor

adfoster-r7 commented Mar 15, 2021

Release Notes

Fixed a previous feature which added the readability of Meterpreter error messages via replacing the command ID with the command name to now work with older versions of Ruby.

@space-r7 space-r7 deleted the pkt_dispatch_fix branch March 15, 2021 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug rn-fix release notes fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants