File task_scheduler.rb
has 354 lines of code (exceeds 250 allowed). Consider refactoring. Open
module Msf
class Post
module Windows
#
# Post module mixin for dealing with Windows Task Scheduler
Method task_create
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def task_create(task_name, task_cmd, opts = {})
schtasks_cmd = ['/create']
task_type = opts[:task_type] || (datastore['ScheduleType'].present? ? datastore['ScheduleType'] : DEFAULT_SCHEDULE_TASK_TYPE)
schtasks_cmd += ['/tn', "\"#{task_name}\"", '/tr', "\"#{task_cmd}\"", '/sc', task_type]
if %w[MINUTE HOURLY DAILY WEEKLY MONTHLY ONIDLE].include?(task_type)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method initialize
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(info = {})
super
register_advanced_options(
[
Method run_one_off_task
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def run_one_off_task(cmd, check_success: false)
result = nil
task_name = Rex::Text.rand_text_alpha(rand(8..15))
log_and_print("[Task Scheduler] Creating the remote task #{task_name} to run '#{cmd}'")
# Obfuscation is not possible since #run_one_off_task will be called
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_reg_key_value
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def add_reg_key_value(reg_key, reg_value, reg_data, reg_type, opts = {})
log_and_print('[Task Scheduler] Restoring the Security Descriptor registry key value to unhide the task')
# Override by default. It has to be explicitly set to false if we don't want the key to be overridden.
unless opts[:override].nil? || opts[:override]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method delete_reg_key_value
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def delete_reg_key_value(reg_key, reg_value, opts = {})
log_and_print('[Task Scheduler] Removing the Security Descriptor registry key value to hide the task')
log_and_print('[Task Scheduler] Checking if the key value exists')
unless reg_key_value_exists?(reg_key, reg_value)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method run_one_off_task
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def run_one_off_task(cmd, check_success: false)
result = nil
task_name = Rex::Text.rand_text_alpha(rand(8..15))
log_and_print("[Task Scheduler] Creating the remote task #{task_name} to run '#{cmd}'")
# Obfuscation is not possible since #run_one_off_task will be called
Method task_create
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def task_create(task_name, task_cmd, opts = {})
schtasks_cmd = ['/create']
task_type = opts[:task_type] || (datastore['ScheduleType'].present? ? datastore['ScheduleType'] : DEFAULT_SCHEDULE_TASK_TYPE)
schtasks_cmd += ['/tn', "\"#{task_name}\"", '/tr', "\"#{task_cmd}\"", '/sc', task_type]
if %w[MINUTE HOURLY DAILY WEEKLY MONTHLY ONIDLE].include?(task_type)
Method get_schtasks_cmd_string
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def get_schtasks_cmd_string(schtasks_cmd, opts = {})
cmd = schtasks_cmd.dup
cmd.prepend('schtasks')
system = opts[:remote_system] || (datastore['ScheduleRemoteSystem'].present? ? datastore['ScheduleRemoteSystem'] : nil)
cmd += ['/s', system] if system
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method task_info_field
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def task_info_field(task_name, task_info, key)
task_name = task_name.delete_prefix('"').delete_suffix('"')
key = key.delete_prefix('"').delete_suffix('"')
task_info = task_info.lines
title_array = task_info.shift&.split(',')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_reg_key_value
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def add_reg_key_value(reg_key, reg_value, reg_data, reg_type, opts = {})
log_and_print('[Task Scheduler] Restoring the Security Descriptor registry key value to unhide the task')
# Override by default. It has to be explicitly set to false if we don't want the key to be overridden.
unless opts[:override].nil? || opts[:override]
Method log_and_print
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def log_and_print(msg, level: :debug)
case level
when :debug
vprint_status(msg) if respond_to?(:vprint_status)
dlog(msg)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method reg_key_value_exists?
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def reg_key_value_exists?(reg_key, reg_value, opts = {})
remote_host = opts[:remote_system].present? || datastore['ScheduleRemoteSystem'].present?
result = false
if remote_host
begin
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method add_reg_key_value
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def add_reg_key_value(reg_key, reg_value, reg_data, reg_type, opts = {})
Method get_system_privs
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def get_system_privs
return if is_system?
unless session.type == 'meterpreter'
error = "Incompatible session type (#{session.type}), cannot get SYSTEM "\
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method task_delete
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def task_delete(task_name, opts = {})
# We want to make sure `opts` has preference over the datastore option
obfuscation = opts.fetch(:obfuscation, datastore['ScheduleObfuscationTechnique'])
if obfuscation && obfuscation != 'NONE'
begin
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"