1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00

Add a print_bad alias for print_error

Came up on Twitter, where Justin may have been trolling a little:

https://twitter.com/jstnkndy/status/798671298302017536

We have a `print_good` method, but not a `print_bad`, which seems a
little weird for Ruby -- opposite methods should be intuitive as Justin
is implying.

Anyway, I went with alias_method, thanks to the compelling argument at

https://github.com/bbatsov/ruby-style-guide#alias-method

...since Metasploit is all about the singleton, and didn't want to risk
some unexpected scoping thing.

Also dang, we define the `print_` methods like fifty billion times!
Really should fix that some day.
This commit is contained in:
Tod Beardsley 2016-11-15 19:20:42 -06:00
parent 7e4645afb3
commit 1deacad2be
No known key found for this signature in database
GPG Key ID: 08B5B91DC85943FE
19 changed files with 39 additions and 4 deletions

View File

@ -133,6 +133,8 @@ module Metasploit
@parent.print_error(message)
end
alias_method :print_bad, :print_error
end
end
end

View File

@ -667,6 +667,8 @@ module Auxiliary::AuthBrute
print_brute :level => :verror, :legacy_msg => msg
end
alias_method :vprint_bad, :vprint_error
# Legacy vprint
def vprint_good(msg='')
print_brute :level => :vgood, :legacy_msg => msg

View File

@ -326,5 +326,7 @@ class Auxiliary::Web::HTTP
@parent.print_error message
end
alias_method :print_bad, :print_error
end
end

View File

@ -8,6 +8,8 @@ module Msf::Module::UI::Message
super(print_prefix + msg)
end
alias_method :print_bad, :print_error
def print_good(msg='')
super(print_prefix + msg)
end

View File

@ -4,6 +4,8 @@ module Msf::Module::UI::Message::Verbose
print_error(msg) if datastore['VERBOSE'] || (!framework.nil? && framework.datastore['VERBOSE'])
end
alias_method :vprint_bad, :vprint_error
# Verbose version of #print_good
def vprint_good(msg='')
print_good(msg) if datastore['VERBOSE'] || (!framework.nil? && framework.datastore['VERBOSE'])

View File

@ -19,6 +19,8 @@ class Msf::Payload::Apk
$stderr.puts "[-] #{msg}"
end
alias_method :print_bad, :print_error
def usage
print_error "Usage: #{$0} -x [target.apk] [msfvenom options]\n"
print_error "e.g. #{$0} -x messenger.apk -p android/meterpreter/reverse_https LHOST=192.168.1.1 LPORT=8443\n"

View File

@ -112,6 +112,8 @@ class Plugin
output.print_error(msg) if (output)
end
alias_method :print_bad, :print_error
#
# Prints a 'good' message.
#

View File

@ -9,6 +9,7 @@ class Base
def print_status(msg); end
def print_good(msg); end
def print_error(msg); end
alias_method :print_bad, :print_error
def print_warning(msg); end
end

View File

@ -24,6 +24,8 @@ class Output
def print_error(msg='')
end
alias_method :print_bad, :print_error
#
# Prints a 'good' message.
#

View File

@ -46,6 +46,8 @@ module Subscriber
end
end
alias_method :print_bad, :print_error
#
# Wraps user_output.print_good
#

View File

@ -80,6 +80,8 @@ class BidirectionalPipe < Rex::Ui::Text::Input
print_line('[-] ' + msg)
end
alias_method :print_bad, :print_error
def print_line(msg='')
print(msg + "\n")
end

View File

@ -61,6 +61,8 @@ module DispatcherShell
shell.print_error(msg)
end
alias_method :print_bad, :print_error
#
# Wraps shell.print_status
#

View File

@ -51,6 +51,8 @@ class Output < Rex::Ui::Output
print_line("%bld%red[-]%clr #{msg}")
end
alias_method :print_bad, :print_error
def print_good(msg = '')
print_line("%bld%grn[+]%clr #{msg}")
end

View File

@ -276,6 +276,8 @@ module Shell
log_output(output.print_error(msg))
end
alias_method :print_bad, :print_error
#
# Prints a status message to the output handle.
#

View File

@ -7,7 +7,8 @@ RSpec.describe Msf::Post::Windows::MSSQL do
let(:subject) do
mod = double(Module.new)
mod.extend described_class
stubs = [ :vprint_status, :print_status, :vprint_good, :print_good, :print_error, :print_warning ]
stubs = [ :vprint_status, :print_status, :vprint_good, :print_good,
:print_error, :vprint_error, :print_bad, :vprint_bad, :print_warning ]
stubs.each { |meth| allow(mod).to receive(meth) }
allow(mod).to receive(:service_info).and_return({})
mod

View File

@ -36,7 +36,8 @@ RSpec.describe Msf::Post::Windows::Runas do
let(:subject) do
mod = double(Module.new)
mod.extend described_class
stubs = [ :vprint_status, :print_status, :vprint_good, :print_good, :print_error ]
stubs = [ :vprint_status, :print_status, :vprint_good, :print_good,
:print_error, :vprint_error, :print_bad, :vprint_bad ]
stubs.each { |meth| allow(mod).to receive(meth) }
allow(mod).to receive_message_chain("session.railgun.kernel32").and_return(kernel32)
allow(mod).to receive_message_chain("session.railgun.advapi32").and_return(advapi32)

View File

@ -17,6 +17,10 @@ RSpec.shared_context 'Msf::UIDriver' do
@error ||= []
@error.concat string.split("\n")
end
allow(driver).to receive(:print_bad).with(kind_of(String)) do |string|
@error ||= []
@error.concat string.split("\n")
end
}
end
end

View File

@ -2,8 +2,9 @@ RSpec.shared_examples_for 'Msf::Module::UI::Message' do
it_should_behave_like 'Msf::Module::UI::Message::Verbose'
it { is_expected.to respond_to :print_error }
it { is_expected.to respond_to :print_bad }
it { is_expected.to respond_to :print_good }
it { is_expected.to respond_to :print_prefix }
it { is_expected.to respond_to :print_status }
it { is_expected.to respond_to :print_warning }
end
end

View File

@ -1,6 +1,7 @@
RSpec.shared_examples_for 'Msf::Module::UI::Message::Verbose' do
it { is_expected.to respond_to :vprint_error }
it { is_expected.to respond_to :vprint_bad }
it { is_expected.to respond_to :vprint_good }
it { is_expected.to respond_to :vprint_status }
it { is_expected.to respond_to :vprint_warning }
end
end