Skip to content

Commit

Permalink
Land #9276, cleanup of crufty code
Browse files Browse the repository at this point in the history
  • Loading branch information
wvu committed Dec 7, 2017
2 parents ce2db3c + c15f379 commit 0a0d24d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 159 deletions.
3 changes: 1 addition & 2 deletions lib/msf/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#
###

# Sanity check this version of ruby
require 'msf/sanity'
# Include backported features for older versions of Ruby
require 'backports'

# The framework-core depends on Rex
Expand Down
28 changes: 0 additions & 28 deletions lib/msf/sanity.rb

This file was deleted.

133 changes: 4 additions & 129 deletions lib/msf/ui/console/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,6 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
print_error("***")
end

begin
require 'openssl'
rescue ::LoadError
print_error("***")
print_error("* WARNING: No OpenSSL support. This is required by meterpreter payloads and many exploits")
print_error("* Please install the ruby-openssl package (apt-get install libopenssl-ruby on Debian/Ubuntu")
print_error("***")
end

# Register event handlers
register_event_handlers

Expand Down Expand Up @@ -191,24 +182,10 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
end
end

# framework.db.active will be true if after_establish_connection ran directly when connection_established? was
# already true or if framework.db.connect called after_establish_connection.
if !! framework.db.error
if framework.db.error.to_s =~ /RubyGem version.*pg.*0\.11/i
print_error("***")
print_error("*")
print_error("* Metasploit now requires version 0.11 or higher of the 'pg' gem for database support")
print_error("* There a three ways to accomplish this upgrade:")
print_error("* 1. If you run Metasploit with your system ruby, simply upgrade the gem:")
print_error("* $ rvmsudo gem install pg ")
print_error("* 2. Use the Community Edition web interface to apply a Software Update")
print_error("* 3. Uninstall, download the latest version, and reinstall Metasploit")
print_error("*")
print_error("***")
print_error("")
print_error("")
end

# framework.db.active will be true if after_establish_connection ran
# directly when connection_established? was already true or if
# framework.db.connect called after_establish_connection.
if !!framework.db.error
print_error("Failed to connect to the database: #{framework.db.error}")
end
end
Expand Down Expand Up @@ -250,108 +227,6 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
end
end

#
# Configure a default output path for jUnit XML output
#
def junit_setup(output_path)
output_path = ::File.expand_path(output_path)

::FileUtils.mkdir_p(output_path)
@junit_output_path = output_path
@junit_error_count = 0
print_status("Test Output: #{output_path}")

# We need at least one test success in order to pass
junit_pass("framework_loaded")
end

#
# Emit a new jUnit XML output file representing an error
#
def junit_error(tname, ftype, data = nil)

if not @junit_output_path
raise RuntimeError, "No output path, call junit_setup() first"
end

data ||= framework.inspect.to_s

e = REXML::Element.new("testsuite")

c = REXML::Element.new("testcase")
c.attributes["classname"] = "msfrc"
c.attributes["name"] = tname

f = REXML::Element.new("failure")
f.attributes["type"] = ftype

f.text = data
c << f
e << c

bname = ("msfrpc_#{tname}").gsub(/[^A-Za-z0-9\.\_]/, '')
bname << "_" + Digest::MD5.hexdigest(tname)

fname = ::File.join(@junit_output_path, "#{bname}.xml")
cnt = 0
while ::File.exist?( fname )
cnt += 1
fname = ::File.join(@junit_output_path, "#{bname}_#{cnt}.xml")
end

::File.open(fname, "w") do |fd|
fd.write(e.to_s)
end

print_error("Test Error: #{tname} - #{ftype} - #{data}")
end

#
# Emit a new jUnit XML output file representing a success
#
def junit_pass(tname)

if not @junit_output_path
raise RuntimeError, "No output path, call junit_setup() first"
end

# Generate the structure of a test case run
e = REXML::Element.new("testsuite")
c = REXML::Element.new("testcase")
c.attributes["classname"] = "msfrc"
c.attributes["name"] = tname
e << c

# Generate a unique name
bname = ("msfrpc_#{tname}").gsub(/[^A-Za-z0-9\.\_]/, '')
bname << "_" + Digest::MD5.hexdigest(tname)

# Generate the output path, allow multiple test with the same name
fname = ::File.join(@junit_output_path, "#{bname}.xml")
cnt = 0
while ::File.exist?( fname )
cnt += 1
fname = ::File.join(@junit_output_path, "#{bname}_#{cnt}.xml")
end

# Write to our test output location, as specified with junit_setup
::File.open(fname, "w") do |fd|
fd.write(e.to_s)
end

print_good("Test Pass: #{tname}")
end


#
# Emit a jUnit XML output file and throw a fatal exception
#
def junit_fatal_error(tname, ftype, data)
junit_error(tname, ftype, data)
print_error("Exiting")
run_single("exit -y")
end

#
# Loads configuration that needs to be analyzed before the framework
# instance is created.
Expand Down

0 comments on commit 0a0d24d

Please sign in to comment.