Land #16373, Add initial ruby 3.1 support

This commit is contained in:
dwelch-r7 2022-04-07 16:44:02 +01:00 committed by GitHub
commit a82c936613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 102 additions and 14 deletions

View File

@ -66,6 +66,7 @@ jobs:
- 2.6
- 2.7
- 3.0.3
- 3.1.1
test_cmd:
- bundle exec rake rspec-rerun:spec SPEC_OPTS="--tag content"
- bundle exec rake rspec-rerun:spec SPEC_OPTS="--tag ~content"

View File

@ -36,6 +36,7 @@ PATH
msgpack
nessus_rest
net-ldap
net-smtp
net-ssh
network_interface
nexpose
@ -160,6 +161,7 @@ GEM
crass (1.0.6)
daemons (1.4.1)
diff-lcs (1.5.0)
digest (3.0.0)
dnsruby (1.61.9)
simpleidn (~> 0.1)
docile (1.4.0)
@ -229,6 +231,7 @@ GEM
i18n (1.10.0)
concurrent-ruby (~> 1.0)
io-console (0.5.11)
io-wait (0.1.0)
irb (1.3.6)
reline (>= 0.2.5)
jmespath (1.6.1)
@ -285,6 +288,13 @@ GEM
ruby2_keywords (~> 0.0.1)
nessus_rest (0.1.6)
net-ldap (0.17.0)
net-protocol (0.1.0)
io-wait
timeout
net-smtp (0.2.1)
digest
net-protocol
timeout
net-ssh (6.1.0)
network_interface (0.0.2)
nexpose (7.3.0)
@ -469,6 +479,7 @@ GEM
thor (1.2.1)
tilt (2.0.10)
timecop (0.9.5)
timeout (0.1.1)
ttfunk (1.7.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)

View File

@ -118,7 +118,7 @@ module Auxiliary
unless mod.has_check?
# Bail out early if the module doesn't have check
raise ::NoMethodError.new(Msf::Exploit::CheckCode::Unsupported.message, 'check')
raise ::NotImplementedError.new(Msf::Exploit::CheckCode::Unsupported.message)
end
# Validate the option container state so that options will

View File

@ -193,7 +193,7 @@ module Exploit
unless mod.has_check?
# Bail out early if the module doesn't have check
raise ::NoMethodError.new(Msf::Exploit::CheckCode::Unsupported.message, 'check')
raise ::NotImplementedError.new(Msf::Exploit::CheckCode::Unsupported.message)
end
# Validate the option container state so that options will

View File

@ -190,8 +190,13 @@ class Msf::DBManager
self.error = "No database YAML file"
else
if configuration_pathname.readable?
# parse specified database YAML file
dbinfo = YAML.load_file(configuration_pathname) || {}
# parse specified database YAML file, using the same pattern as Rails https://github.com/rails/rails/pull/42249
dbinfo = begin
YAML.load_file(configuration_pathname, aliases: true) || {}
rescue ArgumentError
YAML.load_file(configuration_pathname) || {}
end
dbenv = opts['DatabaseEnv'] || Rails.env
db_opts = dbinfo[dbenv]
else

View File

@ -82,9 +82,9 @@ module Msf
# @see Rex::Proto::Kerberos::Model::KdcRequestBody
def build_as_request_body(opts = {})
options = opts[:options] || 0x50800000 # Forwardable, Proxiable, Renewable
from = opts[:from] || Time.utc('1970-01-01-01 00:00:00')
till = opts[:till] || Time.utc('1970-01-01-01 00:00:00')
rtime = opts[:rtime] || Time.utc('1970-01-01-01 00:00:00')
from = opts[:from] || Time.at(0)
till = opts[:till] || Time.at(0)
rtime = opts[:rtime] || Time.at(0)
nonce = opts[:nonce] || Rex::Text.rand_text_numeric(6).to_i
etype = opts[:etype] || [Rex::Proto::Kerberos::Crypto::RC4_HMAC]
cname = opts[:cname] || build_client_name(opts)

View File

@ -225,9 +225,9 @@ module Msf
# @see Rex::Proto::Kerberos::Model::KdcRequestBody
def build_tgs_request_body(opts = {})
options = opts[:options] || 0x50800000 # Forwardable, Proxiable, Renewable
from = opts[:from] || Time.utc('1970-01-01-01 00:00:00')
till = opts[:till] || Time.utc('1970-01-01-01 00:00:00')
rtime = opts[:rtime] || Time.utc('1970-01-01-01 00:00:00')
from = opts[:from] || Time.at(0)
till = opts[:till] || Time.at(0)
rtime = opts[:rtime] || Time.at(0)
nonce = opts[:nonce] || Rex::Text.rand_text_numeric(6).to_i
etype = opts[:etype] || [Rex::Proto::Kerberos::Crypto::RC4_HMAC]
cname = opts[:cname] || build_client_name(opts)

View File

@ -165,7 +165,7 @@ module Exploit::Remote::VIMSoap
if res.body.include? "NotAuthenticatedFault"
return :expired
elsif res.body.include? "<faultstring>"
@vim_soap_error = res.body.match(/<faultstring>([^\c ]+?)<\/faultstring>/)[1]
@vim_soap_error = res.body.match(/<faultstring>(.+?)<\/faultstring>/m)[1]
return :error
elsif res.code != 200
@vim_soap_error = "An unknown error was encountered"

View File

@ -18,4 +18,15 @@ unless defined?(Rails) && !Rails.application.nil?
end
require 'msf_autoload'
# Disable the enhanced error messages introduced as part of Ruby 3.1, as some error messages are directly shown to users,
# and the default ErrorHighlight formatter displays unneeded Ruby code to the user
# https://github.com/ruby/error_highlight/tree/f3626b9032bd1024d058984329accb757687cee4#custom-formatter
if defined?(::ErrorHighlight)
noop_error_formatter = Object.new
def noop_error_formatter.message_for(_spot)
''
end
::ErrorHighlight.formatter = noop_error_formatter
end
MsfAutoload.instance

View File

@ -142,6 +142,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'bcrypt_pbkdf'
spec.add_runtime_dependency 'ruby_smb', '~> 3.0'
spec.add_runtime_dependency 'net-ldap'
spec.add_runtime_dependency 'net-smtp'
spec.add_runtime_dependency 'winrm'
#

6
msfdb
View File

@ -270,7 +270,11 @@ end
def update_db_port
if File.file?(@db_conf)
config = YAML.load(File.read(@db_conf))
config = begin
YAML.load_file(@db_conf, aliases: true) || {}
rescue ArgumentError
YAML.load_file(@db_conf) || {}
end
if config["production"] && config["production"]["port"]
port = config["production"]["port"]
if port != @options[:db_port]

View File

@ -255,6 +255,26 @@ RSpec.describe "Metasploit's json-rpc" do
end
end
context 'when the module does not support a check method' do
let(:module_name) { 'scanner/http/title' }
it 'returns successful job results' do
create_job
expect(last_response).to_not be_ok
expected_error_response = {
error: {
code: -32000,
data: {
backtrace: include(a_kind_of(String))
},
message: 'Application server error: This module does not support check.'
},
id: 1
}
expect(last_json_response).to include(expected_error_response)
end
end
context 'when the check command raises a known msf error' do
before(:each) do
allow_any_instance_of(::Msf::Auxiliary::Scanner).to receive(:check) do |mod|

View File

@ -0,0 +1,35 @@
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
###
#
# A placeholder module for json_rpc_spec.rb
#
###
class MetasploitModule < Msf::Exploit::Remote
include Msf::Exploit::Remote::DCERPC
prepend Msf::Exploit::Remote::AutoCheck
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Placeholder scanner http title module',
'Description' => 'Placeholder scanner http title module',
'Author' => [],
'License' => MSF_LICENSE
)
)
end
# No check method
# def check
# # noop
# end
def run
# noop
end
end

View File

@ -222,7 +222,7 @@ RSpec.describe Msf::Ui::Console::CommandDispatcher::Exploit do
it 'notifies the user that this module does not support check' do
subject.cmd_check
expected_output = [
'Check failed: NoMethodError This module does not support check.'
'This module does not support check.'
]
expect(@combined_output).to match_array(expected_output)

View File

@ -23,6 +23,6 @@ RSpec.shared_context 'Msf::Simple::Framework' do
end
after(:example) do
dummy_pathname.rmtree
FileUtils.rm_rf(dummy_pathname)
end
end