Skip to content

Commit 6062328

Browse files
David MaloneyDavid Maloney
authored andcommitted
freeze punk, it's rubocop!
rubocop autocrrecting a bunch of stuff *fingers crossed*
1 parent dc53057 commit 6062328

File tree

1 file changed

+71
-80
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+71
-80
lines changed

lib/msf/ui/console/command_dispatcher/jobs.rb

Lines changed: 71 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12
# -*- coding: binary -*-
23

34
#
@@ -6,17 +7,14 @@
67

78
require 'rex/ui/text/output/buffer/stdout'
89

9-
1010
module Msf
1111
module Ui
1212
module Console
1313
module CommandDispatcher
14-
1514
#
1615
# {CommandDispatcher} for commands related to background jobs in Metasploit Framework.
1716
#
1817
class Jobs
19-
2018
include Msf::Ui::Console::CommandDispatcher
2119

2220
@@handler_opts = Rex::Parser::Arguments.new(
@@ -29,8 +27,6 @@ class Jobs
2927
"-n" => [ true, "The custom name to give the handler job"]
3028
)
3129

32-
33-
3430
@@jobs_opts = Rex::Parser::Arguments.new(
3531
"-h" => [ false, "Help banner." ],
3632
"-k" => [ true, "Terminate jobs by job ID and/or range." ],
@@ -95,7 +91,7 @@ def cmd_rename_job(*args)
9591
# @param words [Array<String>] the previously completed words on the command line. words is always
9692
# at least 1 when tab completion has reached this stage since the command itself has been completed
9793

98-
def cmd_rename_job_tabs(str, words)
94+
def cmd_rename_job_tabs(_str, words)
9995
return [] if words.length > 1
10096
framework.jobs.keys
10197
end
@@ -114,49 +110,49 @@ def cmd_jobs_help
114110
def cmd_jobs(*args)
115111
# Make the default behavior listing all jobs if there were no options
116112
# or the only option is the verbose flag
117-
args.unshift("-l") if args.length == 0 || args == ["-v"]
113+
args.unshift("-l") if args.empty? || args == ["-v"]
118114

119115
verbose = false
120116
dump_list = false
121117
dump_info = false
122118
job_id = nil
123119

124120
# Parse the command options
125-
@@jobs_opts.parse(args) do |opt, idx, val|
121+
@@jobs_opts.parse(args) do |opt, _idx, val|
126122
case opt
127-
when "-v"
128-
verbose = true
129-
when "-l"
130-
dump_list = true
123+
when "-v"
124+
verbose = true
125+
when "-l"
126+
dump_list = true
131127
# Terminate the supplied job ID(s)
132-
when "-k"
133-
job_list = build_range_array(val)
134-
if job_list.blank?
135-
print_error("Please specify valid job identifier(s)")
136-
return false
137-
end
138-
print_status("Stopping the following job(s): #{job_list.join(', ')}")
139-
job_list.map(&:to_s).each do |job|
140-
if framework.jobs.has_key?(job)
141-
print_status("Stopping job #{job}")
142-
framework.jobs.stop_job(job)
143-
else
144-
print_error("Invalid job identifier: #{job}")
145-
end
146-
end
147-
when "-K"
148-
print_line("Stopping all jobs...")
149-
framework.jobs.each_key do |i|
150-
framework.jobs.stop_job(i)
151-
end
152-
when "-i"
153-
# Defer printing anything until the end of option parsing
154-
# so we can check for the verbose flag.
155-
dump_info = true
156-
job_id = val
157-
when "-h"
158-
cmd_jobs_help
128+
when "-k"
129+
job_list = build_range_array(val)
130+
if job_list.blank?
131+
print_error("Please specify valid job identifier(s)")
159132
return false
133+
end
134+
print_status("Stopping the following job(s): #{job_list.join(', ')}")
135+
job_list.map(&:to_s).each do |job|
136+
if framework.jobs.key?(job)
137+
print_status("Stopping job #{job}")
138+
framework.jobs.stop_job(job)
139+
else
140+
print_error("Invalid job identifier: #{job}")
141+
end
142+
end
143+
when "-K"
144+
print_line("Stopping all jobs...")
145+
framework.jobs.each_key do |i|
146+
framework.jobs.stop_job(i)
147+
end
148+
when "-i"
149+
# Defer printing anything until the end of option parsing
150+
# so we can check for the verbose flag.
151+
dump_info = true
152+
job_id = val
153+
when "-h"
154+
cmd_jobs_help
155+
return false
160156
end
161157
end
162158

@@ -177,7 +173,7 @@ def cmd_jobs(*args)
177173

178174
if verbose
179175
mod_opt = Serializer::ReadableText.dump_advanced_options(mod, ' ')
180-
if mod_opt && mod_opt.length > 0
176+
if mod_opt && !mod_opt.empty?
181177
print_line("\nModule advanced options:\n\n#{mod_opt}\n")
182178
end
183179
end
@@ -194,10 +190,8 @@ def cmd_jobs(*args)
194190
# @param words [Array<String>] the previously completed words on the command line. words is always
195191
# at least 1 when tab completion has reached this stage since the command itself has been completed
196192

197-
def cmd_jobs_tabs(str, words)
198-
if words.length == 1
199-
return @@jobs_opts.fmt.keys
200-
end
193+
def cmd_jobs_tabs(_str, words)
194+
return @@jobs_opts.fmt.keys if words.length == 1
201195

202196
if words.length == 2 && (@@jobs_opts.fmt[words[1]] || [false])[0]
203197
return framework.jobs.keys
@@ -210,7 +204,7 @@ def cmd_kill_help
210204
print_line "Usage: kill <job1> [job2 ...]"
211205
print_line
212206
print_line "Equivalent to 'jobs -k job1 -k job2 ...'"
213-
print @@jobs_opts.usage()
207+
print @@jobs_opts.usage
214208
end
215209

216210
def cmd_kill(*args)
@@ -224,7 +218,7 @@ def cmd_kill(*args)
224218
# @param words [Array<String>] the previously completed words on the command line. words is always
225219
# at least 1 when tab completion has reached this stage since the command itself has been completed
226220

227-
def cmd_kill_tabs(str, words)
221+
def cmd_kill_tabs(_str, words)
228222
return [] if words.length > 1
229223
framework.jobs.keys
230224
end
@@ -233,13 +227,13 @@ def cmd_handler_help
233227
print_line "Usage: handler [options]"
234228
print_line
235229
print_line "Spin up a Payload Handler as background job."
236-
print @@handler_opts.usage()
230+
print @@handler_opts.usage
237231
end
238232

239233
# Allows the user to setup a payload handler as a background job from a single command.
240234
def cmd_handler(*args)
241-
#Display the help banner if no arguments were passed
242-
if args.length == 0
235+
# Display the help banner if no arguments were passed
236+
if args.empty?
243237
cmd_handler_help
244238
return
245239
end
@@ -252,31 +246,31 @@ def cmd_handler(*args)
252246
stage_encoder = nil
253247

254248
# Parse the command options
255-
@@handler_opts.parse(args) do |opt, idx, val|
249+
@@handler_opts.parse(args) do |opt, _idx, val|
256250
case opt
257-
when "-x"
258-
exit_on_session = true
259-
when "-p"
260-
payload_module = framework.payloads.create(val)
261-
if payload_module.nil?
262-
print_error "Invalid Payload Name Supplied!"
263-
return
264-
end
265-
when "-P"
266-
port = val
267-
when "-H"
268-
host = val
269-
when "-n"
270-
job_name = val
271-
when "-e"
272-
encoder_module = framework.encoders.create(val)
273-
if encoder_module.nil?
274-
print_error "Invalid Encoder Name Supplied"
275-
end
276-
stage_encoder = encoder_module.refname
277-
when "-h"
278-
cmd_handler_help
251+
when "-x"
252+
exit_on_session = true
253+
when "-p"
254+
payload_module = framework.payloads.create(val)
255+
if payload_module.nil?
256+
print_error "Invalid Payload Name Supplied!"
279257
return
258+
end
259+
when "-P"
260+
port = val
261+
when "-H"
262+
host = val
263+
when "-n"
264+
job_name = val
265+
when "-e"
266+
encoder_module = framework.encoders.create(val)
267+
if encoder_module.nil?
268+
print_error "Invalid Encoder Name Supplied"
269+
end
270+
stage_encoder = encoder_module.refname
271+
when "-h"
272+
cmd_handler_help
273+
return
280274
end
281275
end
282276

@@ -294,19 +288,19 @@ def cmd_handler(*args)
294288
payload_datastore = payload_module.datastore
295289

296290
# Set The RHOST or LHOST for the payload
297-
if payload_datastore.has_key? "LHOST"
291+
if payload_datastore.key? "LHOST"
298292
payload_datastore['LHOST'] = host
299-
elsif payload_datastore.has_key? "RHOST"
293+
elsif payload_datastore.key? "RHOST"
300294
payload_datastore['RHOST'] = host
301295
else
302296
print_error "Could not determine how to set Host on this payload..."
303297
return
304298
end
305299

306300
# Set the RPORT or LPORT for the payload
307-
if payload_datastore.has_key? "LPORT"
301+
if payload_datastore.key? "LPORT"
308302
payload_datastore['LPORT'] = port
309-
elsif payload_datastore.has_key? "RPORT"
303+
elsif payload_datastore.key? "RPORT"
310304
payload_datastore['RPORT'] = port
311305
else
312306
print_error "Could not determine how to set Port on this payload..."
@@ -335,15 +329,12 @@ def cmd_handler(*args)
335329

336330
# Customise the job name if the user asked for it
337331
if job_name.present?
338-
framework.jobs["#{job_id}"].send(:name=, job_name)
332+
framework.jobs[job_id.to_s].send(:name=, job_name)
339333
end
340334

341335
print_status "Payload Handler Started as Job #{job_id}"
342336
end
343-
344-
345337
end
346-
347338
end
348339
end
349340
end

0 commit comments

Comments
 (0)