freeze punk, it's rubocop!

rubocop autocrrecting a bunch of stuff *fingers crossed*
bug/bundler_fix
David Maloney 2016-12-06 17:17:56 -06:00
parent dc53057639
commit 606232828f
No known key found for this signature in database
GPG Key ID: DEDBA9DC3A913DB2
1 changed files with 71 additions and 80 deletions

View File

@ -1,3 +1,4 @@
# frozen_string_literal: true
# -*- coding: binary -*-
#
@ -6,17 +7,14 @@
require 'rex/ui/text/output/buffer/stdout'
module Msf
module Ui
module Console
module CommandDispatcher
#
# {CommandDispatcher} for commands related to background jobs in Metasploit Framework.
#
class Jobs
include Msf::Ui::Console::CommandDispatcher
@@handler_opts = Rex::Parser::Arguments.new(
@ -29,8 +27,6 @@ module Msf
"-n" => [ true, "The custom name to give the handler job"]
)
@@jobs_opts = Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner." ],
"-k" => [ true, "Terminate jobs by job ID and/or range." ],
@ -95,7 +91,7 @@ module Msf
# @param words [Array<String>] the previously completed words on the command line. words is always
# at least 1 when tab completion has reached this stage since the command itself has been completed
def cmd_rename_job_tabs(str, words)
def cmd_rename_job_tabs(_str, words)
return [] if words.length > 1
framework.jobs.keys
end
@ -114,7 +110,7 @@ module Msf
def cmd_jobs(*args)
# Make the default behavior listing all jobs if there were no options
# or the only option is the verbose flag
args.unshift("-l") if args.length == 0 || args == ["-v"]
args.unshift("-l") if args.empty? || args == ["-v"]
verbose = false
dump_list = false
@ -122,41 +118,41 @@ module Msf
job_id = nil
# Parse the command options
@@jobs_opts.parse(args) do |opt, idx, val|
@@jobs_opts.parse(args) do |opt, _idx, val|
case opt
when "-v"
verbose = true
when "-l"
dump_list = true
when "-v"
verbose = true
when "-l"
dump_list = true
# Terminate the supplied job ID(s)
when "-k"
job_list = build_range_array(val)
if job_list.blank?
print_error("Please specify valid job identifier(s)")
return false
end
print_status("Stopping the following job(s): #{job_list.join(', ')}")
job_list.map(&:to_s).each do |job|
if framework.jobs.has_key?(job)
print_status("Stopping job #{job}")
framework.jobs.stop_job(job)
else
print_error("Invalid job identifier: #{job}")
end
end
when "-K"
print_line("Stopping all jobs...")
framework.jobs.each_key do |i|
framework.jobs.stop_job(i)
end
when "-i"
# Defer printing anything until the end of option parsing
# so we can check for the verbose flag.
dump_info = true
job_id = val
when "-h"
cmd_jobs_help
when "-k"
job_list = build_range_array(val)
if job_list.blank?
print_error("Please specify valid job identifier(s)")
return false
end
print_status("Stopping the following job(s): #{job_list.join(', ')}")
job_list.map(&:to_s).each do |job|
if framework.jobs.key?(job)
print_status("Stopping job #{job}")
framework.jobs.stop_job(job)
else
print_error("Invalid job identifier: #{job}")
end
end
when "-K"
print_line("Stopping all jobs...")
framework.jobs.each_key do |i|
framework.jobs.stop_job(i)
end
when "-i"
# Defer printing anything until the end of option parsing
# so we can check for the verbose flag.
dump_info = true
job_id = val
when "-h"
cmd_jobs_help
return false
end
end
@ -177,7 +173,7 @@ module Msf
if verbose
mod_opt = Serializer::ReadableText.dump_advanced_options(mod, ' ')
if mod_opt && mod_opt.length > 0
if mod_opt && !mod_opt.empty?
print_line("\nModule advanced options:\n\n#{mod_opt}\n")
end
end
@ -194,10 +190,8 @@ module Msf
# @param words [Array<String>] the previously completed words on the command line. words is always
# at least 1 when tab completion has reached this stage since the command itself has been completed
def cmd_jobs_tabs(str, words)
if words.length == 1
return @@jobs_opts.fmt.keys
end
def cmd_jobs_tabs(_str, words)
return @@jobs_opts.fmt.keys if words.length == 1
if words.length == 2 && (@@jobs_opts.fmt[words[1]] || [false])[0]
return framework.jobs.keys
@ -210,7 +204,7 @@ module Msf
print_line "Usage: kill <job1> [job2 ...]"
print_line
print_line "Equivalent to 'jobs -k job1 -k job2 ...'"
print @@jobs_opts.usage()
print @@jobs_opts.usage
end
def cmd_kill(*args)
@ -224,7 +218,7 @@ module Msf
# @param words [Array<String>] the previously completed words on the command line. words is always
# at least 1 when tab completion has reached this stage since the command itself has been completed
def cmd_kill_tabs(str, words)
def cmd_kill_tabs(_str, words)
return [] if words.length > 1
framework.jobs.keys
end
@ -233,13 +227,13 @@ module Msf
print_line "Usage: handler [options]"
print_line
print_line "Spin up a Payload Handler as background job."
print @@handler_opts.usage()
print @@handler_opts.usage
end
# Allows the user to setup a payload handler as a background job from a single command.
def cmd_handler(*args)
#Display the help banner if no arguments were passed
if args.length == 0
# Display the help banner if no arguments were passed
if args.empty?
cmd_handler_help
return
end
@ -252,31 +246,31 @@ module Msf
stage_encoder = nil
# Parse the command options
@@handler_opts.parse(args) do |opt, idx, val|
@@handler_opts.parse(args) do |opt, _idx, val|
case opt
when "-x"
exit_on_session = true
when "-p"
payload_module = framework.payloads.create(val)
if payload_module.nil?
print_error "Invalid Payload Name Supplied!"
return
end
when "-P"
port = val
when "-H"
host = val
when "-n"
job_name = val
when "-e"
encoder_module = framework.encoders.create(val)
if encoder_module.nil?
print_error "Invalid Encoder Name Supplied"
end
stage_encoder = encoder_module.refname
when "-h"
cmd_handler_help
when "-x"
exit_on_session = true
when "-p"
payload_module = framework.payloads.create(val)
if payload_module.nil?
print_error "Invalid Payload Name Supplied!"
return
end
when "-P"
port = val
when "-H"
host = val
when "-n"
job_name = val
when "-e"
encoder_module = framework.encoders.create(val)
if encoder_module.nil?
print_error "Invalid Encoder Name Supplied"
end
stage_encoder = encoder_module.refname
when "-h"
cmd_handler_help
return
end
end
@ -294,9 +288,9 @@ module Msf
payload_datastore = payload_module.datastore
# Set The RHOST or LHOST for the payload
if payload_datastore.has_key? "LHOST"
if payload_datastore.key? "LHOST"
payload_datastore['LHOST'] = host
elsif payload_datastore.has_key? "RHOST"
elsif payload_datastore.key? "RHOST"
payload_datastore['RHOST'] = host
else
print_error "Could not determine how to set Host on this payload..."
@ -304,9 +298,9 @@ module Msf
end
# Set the RPORT or LPORT for the payload
if payload_datastore.has_key? "LPORT"
if payload_datastore.key? "LPORT"
payload_datastore['LPORT'] = port
elsif payload_datastore.has_key? "RPORT"
elsif payload_datastore.key? "RPORT"
payload_datastore['RPORT'] = port
else
print_error "Could not determine how to set Port on this payload..."
@ -335,15 +329,12 @@ module Msf
# Customise the job name if the user asked for it
if job_name.present?
framework.jobs["#{job_id}"].send(:name=, job_name)
framework.jobs[job_id.to_s].send(:name=, job_name)
end
print_status "Payload Handler Started as Job #{job_id}"
end
end
end
end
end